ScaNN (Scalable Nearest Neighbors) is an open-source library for approximate nearest neighbor (ANN) search that uses anisotropic vector quantization to optimize the accuracy-latency trade-off, particularly for maximum inner product search (MIPS). It partitions the vector space in a way that better preserves the geometric relationships crucial for inner product similarity, unlike isotropic methods designed for Euclidean distance. This makes it exceptionally effective for retrieving items with high dot-product similarity to a query, a core operation in systems using dense embeddings from models like BERT or Sentence Transformers.
Glossary
ScaNN (Scalable Nearest Neighbors)

What is ScaNN (Scalable Nearest Neighbors)?
ScaNN is a high-performance vector similarity search library developed by Google Research, designed to efficiently solve the Maximum Inner Product Search (MIPS) problem common in recommendation and retrieval systems.
The library's performance stems from its tree-AH (asymmetric hashing) and score-AH quantization techniques, which allow for faster distance computations with minimal loss in recall. By focusing on the anisotropic nature of real-world embedding distributions, ScaNN achieves higher accuracy at comparable speeds to libraries like Faiss for MIPS tasks. It is a key tool in retrieval-augmented generation (RAG) pipelines and recommendation engines where low-latency, high-recall retrieval from billion-scale vector databases is required.
Key Features of ScaNN
ScaNN (Scalable Nearest Neighbors) is a library from Google Research designed for efficient high-dimensional vector similarity search. Its core innovations focus on optimizing the accuracy-latency trade-off, particularly for Maximum Inner Product Search (MIPS).
Anisotropic Vector Quantization
ScaNN's defining technique is Anisotropic Vector Quantization (AVQ), a novel loss function for training quantization codebooks. Unlike standard quantization that minimizes mean squared error, AVQ directly optimizes for the inner product between the query and the quantized vector. This is critical because MIPS aims to maximize the inner product, not minimize Euclidean distance. By aligning the quantization error with the search objective, ScaNN achieves higher accuracy for a given compression rate and search speed.
- Standard Quantization: Minimizes
||x - q(x)||²(reconstruction error). - Anisotropic Quantization (ScaNN): Minimizes
1 - (x · q(x)) / (||x|| * ||q(x)||)(inner product loss).
Maximum Inner Product Search (MIPS) Optimization
ScaNN is specifically engineered for the Maximum Inner Product Search (MIPS) problem, which is prevalent in recommendation systems and retrieval with certain dense embedding models (where similarity is measured by dot product). It provides a more accurate and efficient solution than converting MIPS to nearest neighbor search via Euclidean distance, which requires vector normalization and can distort the space.
- Native MIPS Handling: Operates directly on inner product space without costly pre-processing transformations.
- Partitioning Strategy: Employs a tree-AVQ partitioning scheme that recursively splits the dataset using anisotropic quantizers, creating an index structure optimized for inner product traversal.
Optimal Space Partitioning (Tree-AVQ)
For dataset partitioning, ScaNN uses a tree-AVQ structure. This involves building a tree where each node uses an anisotropic quantizer to split its data points. The quantization cells (partitions) are not isotropic spheres but are shaped to maximize the expected maximum inner product of points within them. This leads to more intelligent pruning during search.
- Recursive Anisotropic Splitting: Each partition is created using AVQ, keeping the search objective in mind.
- Efficient Traversal: The tree structure allows the search algorithm to quickly prune entire branches that are unlikely to contain high inner-product results, reducing the number of distance computations.
Highly-Tunable Accuracy-Speed Trade-off
ScaNN provides granular control over the recall-latency trade-off through key parameters, allowing engineers to dial in performance for specific production requirements.
- Leaves to Search (
leaves_to_search): Analogous tonprobein IVF methods. Controls how many partitions (tree leaves) are examined per query. Increasing this improves recall at the cost of latency. - AVQ Re-ranks: The number of candidates re-scored with a more accurate distance computation after the initial fast quantization-based search.
- Pre-Trained Configuration: Ships with pre-optimized configurations for common scenarios (e.g., high recall, low latency) on standard benchmarks like Glove and Deep1B.
Performance & Scalability
ScaNN is designed for billion-scale datasets. Its combination of AVQ and tree partitioning achieves state-of-the-art performance on public benchmarks, often outperforming other libraries like Faiss (IVFPQ) and HNSW on MIPS tasks, especially at high recall rates.
- Benchmark Results: On the Glove-1.2M benchmark, ScaNN achieves ~10x faster search than Faiss-IVFPQ for the same recall.
- Memory Efficiency: Product Quantization is used in conjunction with AVQ, providing high compression rates (e.g., 32-byte codes for 128-dimensional vectors).
- GPU Compatibility: While primarily CPU-optimized, it supports execution on GPU hardware for accelerated batch inference.
ScaNN vs. Other ANN Libraries
A technical comparison of ScaNN against other prominent approximate nearest neighbor (ANN) libraries, focusing on core algorithms, optimization targets, and deployment characteristics relevant to retrieval latency optimization in RAG systems.
| Feature / Metric | ScaNN (Google) | Faiss (Meta) | HNSW-based (e.g., hnswlib) |
|---|---|---|---|
Primary Algorithm | Anisotropic Vector Quantization (AVQ) | Inverted File Index (IVF), Product Quantization (PQ) | Hierarchical Navigable Small World (HNSW) Graph |
Optimization Target | Maximum Inner Product Search (MIPS) | L2 Distance / Cosine Similarity | L2 Distance / Cosine Similarity |
Quantization Approach | Learned anisotropic partitioning | Structured (PQ) or scalar quantization | Typically none (full-precision vectors) |
Memory Efficiency (for 1M 768-dim vectors) | High (compressed via AVQ) | Very High (compressed via PQ) | Low (stores full-precision vectors) |
Index Build Time | Moderate to High (requires training) | Low to Moderate (IVF) / High (PQ training) | High (graph construction is computationally intensive) |
Query Latency (P50) at 95% Recall | < 1 ms (on CPU, optimized for MIPS) | 1-5 ms (CPU, depends on nprobe/PQ parameters) | 0.5-2 ms (CPU, depends on efSearch) |
GPU Acceleration | Limited (experimental) | Extensive (native GPU kernels for IVF, PQ) | None (primarily CPU-based) |
Dynamic Updates (Incremental Add) | No (requires partial retrain) | Yes (IVFADD, but degrades performance) | Yes (supports adding vectors to graph) |
Native Filtering Support | No | Yes (via IDSelector and range search) | No (requires pre/post-filtering wrapper) |
Primary Use Case in RAG | Recommendation-style retrieval, dense retrieval with dot-product similarity | Generic semantic search, high-scale clustering | Low-latency, high-recall search for moderate-scale datasets |
Frequently Asked Questions
ScaNN (Scalable Nearest Neighbors) is a library from Google Research for efficient high-dimensional vector similarity search, crucial for low-latency retrieval in recommendation systems and RAG architectures.
ScaNN (Scalable Nearest Neighbors) is an open-source library from Google Research for efficient Approximate Nearest Neighbor (ANN) search, specifically optimized for Maximum Inner Product Search (MIPS). It works by employing anisotropic vector quantization, a technique that quantizes vectors (compresses them into discrete codes) in a way that is directionally sensitive to the query distribution. Unlike isotropic methods that treat all vector directions equally, ScaNN's quantization learns to preserve more accuracy in the directions most relevant for the inner product, leading to a superior accuracy-latency trade-off. The library provides a simple API to build an index from a dataset of embeddings and then query it to find the most similar items with high recall and low millisecond latency.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
ScaNN operates within a broader ecosystem of algorithms, libraries, and techniques designed to make high-dimensional vector search fast, accurate, and scalable. Understanding these related concepts is crucial for designing efficient retrieval systems.
Approximate Nearest Neighbor Search (ANN)
Approximate Nearest Neighbor Search (ANN) is the overarching problem that ScaNN solves: efficiently finding vectors in a high-dimensional dataset that are most similar to a query vector. Unlike exact search, ANN algorithms accept a small reduction in accuracy (recall) for orders-of-magnitude improvements in search latency and computational cost. Key trade-offs are managed through algorithm parameters.
- Core Trade-off: Balancing recall (accuracy) against query latency and memory usage.
- Primary Use: Enabling real-time semantic search and recommendations on massive vector datasets where brute-force search is infeasible.
Maximum Inner Product Search (MIPS)
Maximum Inner Product Search (MIPS) is the specific mathematical objective optimized by ScaNN: finding the dataset vectors that yield the highest dot product (inner product) with a query vector. This is distinct from, but related to, nearest neighbor search under Euclidean distance.
- Key Difference: For normalized vectors, MIPS is equivalent to cosine similarity search. For unnormalized vectors (common in learned embeddings), it is a different problem.
- ScaNN's Innovation: ScaNN's anisotropic vector quantization is particularly effective for the MIPS problem, providing better accuracy-latency trade-offs than methods designed purely for Euclidean distance.
Product Quantization (PQ)
Product Quantization (PQ) is a core vector compression technique used in many ANN libraries, including ScaNN. It dramatically reduces memory footprint and accelerates distance calculations.
- Mechanism: Splits a high-dimensional vector into subvectors, quantizes each subspace into a small set of centroids, and represents the original vector as a concatenation of centroid IDs (a short code).
- Advantage: Enables billion-scale vector indices to fit in RAM by compressing vectors from 100s of bytes to just 10s of bytes.
- ScaNN's Use: ScaNN employs optimized variants of PQ as part of its indexing strategy to enable fast, memory-efficient search.
Hierarchical Navigable Small World (HNSW)
Hierarchical Navigable Small World (HNSW) is a leading graph-based ANN algorithm, often compared to ScaNN. It constructs a multi-layered graph where long-range connections enable fast, greedy traversal.
- Performance Profile: Excels at high recall rates with very low latency, especially for moderate-sized datasets that fit in memory.
- Key Parameter:
efSearchcontrols the size of the dynamic candidate list during search, trading accuracy for speed. - Contrast with ScaNN: While HNSW is often favored for pure Euclidean/cosine distance, ScaNN is specifically optimized for the MIPS problem and can outperform it in recommendation-style tasks.
Recall-Latency Trade-off
The recall-latency trade-off is the fundamental engineering compromise at the heart of all ANN systems, including ScaNN. It describes the inverse relationship between search accuracy and speed.
- Definition: Increasing search accuracy (measured as recall) typically requires examining more candidate vectors, leading to higher computational cost and query latency.
- Management: Controlled via algorithm-specific parameters (e.g., ScaNN's and Faiss's
nprobe, HNSW'sefSearch). - System Design: The optimal operating point is determined by application Service-Level Agreements (SLAs)—whether the priority is millisecond responses (e.g., real-time search) or maximal accuracy (e.g., offline batch analysis).

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us