← All open source projects

Faiss

facebookresearch/faiss

Faiss is Meta’s library for fast similarity search and clustering of dense vectors.

Forks 4,438
Language C++
License MIT
Synced 2026-06-27

What It Is

Faiss is a library for similarity search and clustering of dense vectors. It is developed primarily by Meta’s Fundamental AI Research group, written in C++, and exposed through complete Python and NumPy wrappers.

The project is useful wherever an object is represented as a numeric vector: text, image, audio, user profile, or product. Search becomes the problem of finding vectors nearest to a query vector.

Faiss supports several search methods, including options for datasets that do not fit entirely in RAM. Some of the most useful algorithms also have GPU implementations.

What Is Inside

The base model is simple: each vector has an integer id, and similarity is measured with L2 distance or dot product. Cosine similarity is supported through normalized vectors.

The library includes exact indexes, approximate indexes, quantization, compressed representations, evaluation tools, and parameter tuning. It is a set of engineering tradeoffs around speed, memory, and accuracy.

The Python layer makes experimentation convenient, while the C++ core matters for performance. That is why Faiss appears in both research prototypes and production search systems.

How People Use It

A typical setup starts with embeddings: a model turns documents or objects into vectors, Faiss builds an index, and a new query returns the nearest items.

Small projects can use an exact index for clear behavior. Larger collections often use approximate search to reduce memory usage and response time.

The limitation is that Faiss is not a full search product. Teams still need good vectors, original document storage, index updates, and quality checks on real queries.

Minimal Search

The example shows the basic mechanics: create an index by dimensionality, add vectors, and search for nearest items.

Strengths And Limits

Faiss’s strength is its mature set of indexes and high speed. It gives engineers control over accuracy, memory, and latency.

The challenge is configuration. A poor index choice can be too slow or too inaccurate, so measurements on real data are necessary.

Faiss fits semantic search, recommendations, duplicate detection, clustering, and multimedia collections. For small datasets, a direct scan or database-native feature may be enough.

Example

Nearest-Vector Search

The example uses an exact L2 index. It is simple for validating the idea, although larger datasets often use other indexes.

Language: Python
import faiss
import numpy as np

vectors = np.random.random((1000, 128)).astype("float32")
queries = np.random.random((3, 128)).astype("float32")

index = faiss.IndexFlatL2(128)
index.add(vectors)

distances, ids = index.search(queries, 5)
print(ids)