FAISS
Faiss is a library for efficient similarity search and clustering of dense vectors, developed by Meta's Fundamental AI Research. It provides algorithms that scale to billions of vectors, with support for GPU acceleration. It is intended for developers and researchers who need to perform nearest neighbor search or clustering on large datasets.
🎬 FAISS Vector Library with LangChain and OpenAI (Semantic Search) · Ryan & Matt Data Science
✨ Key features
- Efficient similarity search and clustering of dense vectors
- Supports L2 distance and dot product comparisons
- GPU implementation for fast exact and approximate search
- Handles vectors that do not fit in RAM
- Includes evaluation and parameter tuning code
- Python/numpy wrappers for C++ library
🎯 Use cases
- Building recommendation systems with similarity search
- Clustering large-scale image or text embeddings
- Implementing semantic search over document embeddings
- Performing nearest neighbor queries in high-dimensional spaces
📦 Installation
🧰 Requirements: Requires a BLAS implementation; optional GPU support via CUDA or ROCm; Python interface optional.
Faiss comes with precompiled libraries for Anaconda in Python. Install via conda:
conda install -c pytorch faiss-cpu
For GPU support:
conda install -c pytorch faiss-gpu
Alternatively, compile from source with cmake. See INSTALL.md for details.
🚀 Usage
import faiss
import numpy as np
d = 64 # dimension
nb = 100000 # database size
nq = 1000 # number of queries
np.random.seed(1234)
xb = np.random.random((nb, d)).astype('float32')
xb[:, 0] += np.arange(nb) / 1000.
xq = np.random.random((nq, d)).astype('float32')
xq[:, 0] += np.arange(nq) / 1000.
index = faiss.IndexFlatL2(d) # build the index
print(index.is_trained)
index.add(xb) # add vectors to the index
print(index.ntotal)
k = 4 # we want to see 4 nearest neighbors
D, I = index.search(xq, k) # actual search
print(I[:5]) # neighbors of the 5 first queries
print(D[-5:]) # distances of the 5 last queries
⚠️ Good to know
Faiss is primarily for dense vectors and may require significant memory for exact search on very large datasets; approximate methods trade off precision for speed.
❓ FAQ
What distance metrics does Faiss support?
Faiss supports L2 (Euclidean) distances and dot products, and cosine similarity via dot product on normalized vectors.
Can Faiss handle datasets larger than RAM?
Yes, Faiss contains algorithms that can search in sets of vectors that do not fit in RAM, using compressed representations.
Does Faiss support GPU acceleration?
Yes, some algorithms are implemented on GPU, and GPU indexes can be used as drop-in replacements for CPU indexes.
How do I install Faiss?
Precompiled libraries are available via Anaconda for Python, with faiss-cpu and faiss-gpu packages. Alternatively, you can compile from source with cmake.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.