The Wayback Machine - http://web.archive.org/web/20201022093208/https://github.com/ankane/faiss
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Faiss

Faiss - efficient similarity search and clustering - for Ruby

Learn more about Faiss

Build Status

Installation

First, install BLAS, LAPACK, and OpenMP:

# Mac
brew install openblas lapack libomp

# Ubuntu
sudo apt install libblas-dev liblapack-dev

Add this line to your application’s Gemfile:

gem 'faiss'

Faiss is not available for Windows

Getting Started

Prep your data

objects = [
  [1, 1, 2, 1],
  [5, 4, 6, 5],
  [1, 2, 1, 2]
]

Build an index

index = Faiss::IndexFlatL2.new(4)
index.add(objects)

Search

distances, ids = index.search(objects, 3)

Save an index

index.save("index.bin")

Load an index

index = Faiss::Index.load("index.bin")

Use Faiss::IndexBinary to load binary indexes

Basic Indexes

Exact search for L2

Faiss::IndexFlatL2.new(d)

Exact search for inner product

Faiss::IndexFlatIP.new(d)

Hierarchical navigable small world graph exploration

Faiss::IndexHNSWFlat.new(d, m)

Inverted file with exact post-verification

Faiss::IndexIVFFlat.new(quantizer, d, nlists)

Locality-sensitive hashing

Faiss::IndexLSH.new(d, nbits)

Product quantizer (PQ) in flat mode

Faiss::IndexPQ.new(d, m, nbits)

IVFADC (coarse quantizer+PQ on residuals)

Faiss::IndexIVFPQ.new(quantizer, d, nlists, m, nbits)

IVFADC+R (same as IVFADC with re-ranking based on codes)

Faiss::IndexIVFPQR.new(quantizer, d, nlists, m, nbits, m_refine, nbits_refine)

Binary Indexes

Index binary vectors

Faiss::IndexBinaryFlat.new(d)

Speed up search with an inverse vector file

Faiss::IndexBinaryIVF.new(quantizer, d, nlists)

K-means Clustering

Train

kmeans = Faiss::Kmeans.new(4, 2)
kmeans.train(objects)

Get the centroids

kmeans.centroids

PCA

Train

mat = Faiss::PCAMatrix.new(40, 10)
mat.train(objects)

Apply

mat.apply(mt)

Product Quantizer

Train

pq = Faiss::ProductQuantizer.new(32, 4, 8)
pq.train(objects)

Encode

pq.compute_codes(objects)

Decode

pq.decode(codes)

Save a quantizer

pq.save("pq.bin")

Load a quantizer

pq = Faiss::ProductQuantizer.load("pq.bin")

Data

Data can be an array of arrays

[[1, 2, 3], [4, 5, 6]]

Or a Numo NArray

Numo::SFloat.new(3, 2).seq

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone --recursive https://github.com/ankane/faiss.git
cd faiss
bundle install
bundle exec rake compile
bundle exec rake test

About

Efficient similarity search and clustering for Ruby

Resources

License

Packages

No packages published
You can’t perform that action at this time.