Vector Similarity Search: Metrics & Approximate Methods › Similarity Search Libraries
Language AI HandbookAll chapters Vector Similarity Search: Metrics & Approximate Methods › Similarity Search LibrariesOne section · Sections in this chapter8 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
FAISS is the most established library, but the vector search ecosystem has grown rapidly. Here is a brief overview of the major options, grouped by their positioning in the stack.
Core Algorithm Libraries
These libraries provide the algorithmic primitives without a database layer:
FAISS (Meta) is the gold standard for research and production. It supports CPU and GPU, with extensive index types (Flat, IVF, HNSW, PQ, and combinations). Written in C++ with Python bindings, FAISS is the right choice when you need fine-grained control over index construction, when you need GPU acceleration, or when you are building a custom retrieval pipeline.
HNSWlib is a standalone C++ implementation of the HNSW algorithm with Python bindings. Lighter weight than FAISS, focused exclusively on HNSW. This is a good choice when you only need the HNSW index type and want minimal dependencies. It is especially popular for embedding-based retrieval in NLP research because of its simplicity and good performance.
Annoy (Spotify) uses random projection trees. Its key advantage is memory mapping: you can build an index, save it to disk, and then load it into multiple processes simultaneously without duplicating the memory footprint. This makes it attractive for applications that share a single index across many parallel workers. The main limitation is that Annoy does not support adding vectors after index construction, requiring a full rebuild when the collection changes.
ScaNN (Google) is optimized for inner product search with a technique called anisotropic vector quantization, which learns quantization codebooks that minimize the directional error relevant to retrieval rather than the absolute reconstruction error. ScaNN achieves state-of-the-art speed-recall trade-offs on several standard benchmarks. It is the right choice for production systems that have benchmarked multiple options and need the absolute best performance.
Vector Databases
Vector databases add persistence, filtering, distributed search, and managed infrastructure on top of the core ANN algorithms:
Qdrant is an open-source vector database written in Rust, known for its support of rich payload filtering (combining vector search with structured metadata constraints), on-disk indexing for large collections that exceed RAM, and support for multiple vector types per document (dense, sparse, and named vectors).
Milvus is an open-source distributed vector database designed for billion-scale collections. It separates storage, compute, and coordination into distinct layers, letting horizontal scaling of each component independently. Milvus supports a wider range of index types than most alternatives, including GPU acceleration.
Weaviate emphasizes semantic search with built-in module support for generating embeddings from text or images, which makes it easy to set up a pipeline without managing embedding models separately. It also supports hybrid search that combines vector and keyword search natively.
Pinecone is a managed vector database service that eliminates operational overhead at the cost of vendor lock-in. It manages the infrastructure and scaling, including service updates. Pinecone is a reasonable choice for teams that want to move quickly without managing distributed systems.
The choice between a library and a database depends on your requirements. For a RAG system where the document collection fits in memory and you control the embedding pipeline, FAISS or HNSWlib provides maximum flexibility and performance. For a production system requiring persistence, real-time updates, metadata filtering, and operational monitoring, a vector database handles concerns that libraries leave to you.
Choosing a Library or Database
A pragmatic framework for choosing:
- Start with FAISS if you are prototyping or building a custom pipeline and your collection fits in memory. It gives you the most control and is well-documented.
- Switch to HNSWlib if you only need HNSW and want simpler code.
- Consider Qdrant or Weaviate if you need metadata filtering ("find documents similar to this query and tagged with topic=finance") or operational features like monitoring and backup.
- Use Pinecone or a cloud-native solution if minimizing operational burden is more important than cost or performance optimization.