Scalable Nearest Neighbors (ScaNN) is an open-source library from Google Research that implements anisotropic vector quantization to optimize for Maximum Inner Product Search (MIPS), a common objective in recommendation and neural network inference. Unlike methods that assume normalized vectors for cosine similarity, ScaNN's core innovation is its quantization technique, which learns to partition the vector space in a direction-aware manner to better preserve inner product rankings at scale.
Glossary
Scalable Nearest Neighbors (ScaNN)

What is Scalable Nearest Neighbors (ScaNN)?
ScaNN is a specialized library for efficient high-dimensional vector similarity search, developed by Google Research.
The library provides a high-performance, sublinear-time search solution by combining its anisotropic quantization with a standard Inverted File (IVF) index structure. This design enables ScaNN to achieve superior recall@k performance for MIPS problems compared to isotropic methods like Product Quantization (PQ), making it particularly effective for searching unnormalized embedding spaces common in modern machine learning pipelines.
Key Features and Technical Characteristics
ScaNN is a library from Google Research for efficient vector similarity search, distinguished by its use of anisotropic vector quantization to optimize for Maximum Inner Product Search (MIPS).
Anisotropic Vector Quantization
ScaNN's core innovation is Anisotropic Vector Quantization (AVQ), a technique that optimizes quantization codebooks to maximize the inner product between the query and the quantized database vectors. Unlike standard Product Quantization (PQ) which minimizes mean squared error (good for Euclidean distance), AVQ directly optimizes for the Maximum Inner Product Search (MIPS) objective. This results in a more accurate ranking of high inner-product results, which is critical for recommendation systems and unnormalized embeddings.
- Key Mechanism: Learns codebook vectors that are not necessarily orthogonal, allowing them to better capture the directional variance important for inner product.
- Impact: Provides higher accuracy (recall) for MIPS problems at the same compression rate compared to isotropic methods.
Maximum Inner Product Search (MIPS) Optimization
ScaNN is explicitly designed to solve the Maximum Inner Product Search (MIPS) problem, which is distinct from minimizing Euclidean distance. This is crucial because many modern embeddings (e.g., from transformer models used in recommendation or retrieval) are not L2-normalized. Their magnitude carries semantic weight.
- Problem Formulation: Given a query vector
qand a datasetX, findargmax_{x ∈ X} (q · x). - ScaNN's Approach: By combining AVQ with a tree-based partitioning structure, it directly optimizes the index for this objective, avoiding the suboptimal workaround of transforming MIPS into cosine or Euclidean search via normalization.
Tree-AH Index Structure
ScaNN employs a hierarchical indexing structure called Tree-AH (Tree Asymmetric Hashing). This is a two-level index that combines efficient partitioning with anisotropic quantization.
- First Level - Partitioning Tree: Uses a balanced tree to partition the dataset, enabling sublinear time complexity by restricting search to a few leaf partitions.
- Second Level - Anisotropic Quantization: Within each leaf partition, vectors are compressed using the anisotropic codebooks. Search uses Asymmetric Distance Computation (ADC), where the raw query is compared to compressed database vectors for accuracy.
- Advantage: This structure provides a favorable trade-off between index build time, search latency, and recall, especially on large datasets.
Performance & Scalability
ScaNN is engineered for high throughput and low latency at billion-scale. Its performance characteristics are a direct result of its algorithmic choices.
- Sublinear Query Time: The Tree-AH structure ensures queries do not scan the entire dataset.
- Memory Efficiency: Anisotropic quantization provides high compression, reducing the index memory footprint. A billion vectors can be indexed in tens of GBs of RAM.
- Benchmarked Speed: In published benchmarks, ScaNN often achieves higher queries per second (QPS) at a given Recall@10 level compared to other leading ANN libraries for MIPS tasks.
- Hardware Optimization: Includes optimized kernels for modern CPU architectures (AVX2, AVX-512).
Integration with TensorFlow & ML Ecosystem
ScaNN is developed by Google Research and is deeply integrated with the TensorFlow ecosystem, though it can be used independently. This integration simplifies deployment in ML pipelines.
- TensorFlow Integration: Can be used as a layer in a TensorFlow model or serving pipeline. Embeddings generated by a TensorFlow model can be seamlessly indexed and searched.
- Python API: Provides a clean Python API for index building, searching, and serialization, making it accessible to ML engineers and researchers.
- Compatibility: Works with standard embedding formats (NumPy arrays) and is often compared with and used alongside libraries like Faiss and Annoy.
Trade-offs and Typical Use Cases
ScaNN excels in specific scenarios defined by the MIPS objective and scale requirements.
- Ideal Use Cases:
- Recommendation Systems: Finding items with high predicted user affinity (inner product).
- Neural Network Inference: Retrieving context for large language models or cross-encoders where logits are inner products.
- Dense Retrieval: Semantic search where query and document embeddings are not normalized.
- Trade-offs:
- Build Time: The anisotropic training and tree construction can have a higher index build time than simpler methods like HNSW.
- Static Indices: Traditionally optimized for static or batch-updated datasets, though research extends to streaming ANN scenarios.
- Objective-Specific: For pure cosine similarity on L2-normalized vectors, other algorithms may be simpler.
How ScaNN Works: Anisotropic Quantization and MIPS Optimization
ScaNN (Scalable Nearest Neighbors) is a library from Google Research that rethinks vector quantization to achieve state-of-the-art efficiency for Maximum Inner Product Search (MIPS), a common objective in recommendation systems and neural network inference where vectors are not normalized.
ScaNN's core innovation is anisotropic vector quantization, which departs from traditional methods that minimize mean squared error. Instead, it directly optimizes quantization to maximize inner products, aligning the compression error with the MIPS objective. This is achieved by learning a rotation transformation of the vector space that makes the dimensions more independent and unequal in variance, allowing quantization to better preserve the directions that most impact inner product scores.
The library implements this via a loss-aware training process and integrates it into a multi-level index. It typically uses an Inverted File (IVF) structure for coarse partitioning, followed by anisotropic product quantization for residual compression. During search, ScaNN employs asymmetric distance computation (ADC) and an optimized scoring scheme to efficiently traverse the index, achieving superior speed-recall trade-offs for inner product search compared to algorithms optimized for Euclidean distance or cosine similarity.
Primary Use Cases and Applications
ScaNN is engineered for high-performance Maximum Inner Product Search (MIPS), making it particularly effective for scenarios where vector similarity is defined by inner product rather than Euclidean distance. Its core applications span real-time recommendation, semantic search, and large-scale retrieval.
Recommendation Systems
ScaNN is optimized for the Maximum Inner Product Search (MIPS) objective, which is the mathematical foundation of many modern recommendation engines. In these systems, user and item embeddings are learned such that their inner product predicts engagement likelihood (e.g., click-through rate).
- Key Advantage: ScaNN's anisotropic vector quantization better preserves the direction of high inner product vectors, leading to higher recall for top recommendations compared to isotropic methods.
- Example: Retrieving the top-100 most relevant products from a catalog of 100 million items in milliseconds for a real-time personalized feed.
Semantic Search & Retrieval-Augmented Generation (RAG)
For Retrieval-Augmented Generation (RAG) architectures and semantic search engines, ScaNN efficiently finds the most contextually relevant text chunks or documents from a massive vector store.
- Process: Query and document embeddings are generated by a model like a sentence transformer. ScaNN performs a fast, approximate search over these embeddings.
- Why ScaNN: When embeddings are not L2-normalized, similarity is often measured by inner product. ScaNN's MIPS optimization provides more accurate retrieval than algorithms assuming normalized cosine similarity, improving the quality of context fed to the LLM.
Large-Scale Image & Multimodal Retrieval
ScaNN enables fast visual search across billions of image or multimodal embeddings, common in content moderation, e-commerce visual search, and media libraries.
- Application: Finding duplicate or similar user-generated content, or implementing 'search by image' functionality.
- Technical Fit: Deep learning models for vision (e.g., CLIP) often produce embeddings where inner product is a effective similarity measure. ScaNN's ability to handle dense, high-dimensional vectors from these models at scale is critical for low-latency user experiences.
Anisotropic vs. Isotropic Quantization
This is the core technical innovation behind ScaNN's performance. Most vector quantization methods (like Product Quantization) are isotropic—they assume the data distribution is roughly spherical, minimizing average distance error.
- ScaNN's Approach: It uses anisotropic quantization, which recognizes that for MIPS, error is not symmetric. It optimizes the quantization boundaries to preferentially reduce error in directions that matter most for high inner product values.
- Result: This leads to a better recall@k for the same computational budget, meaning the true top matches are more likely to be found in the approximate results.
Integration with Machine Learning Pipelines
ScaNN is designed as a library, not a full database, making it a building block within larger ML infrastructure.
- Common Pattern: Embeddings are generated offline by a model pipeline (e.g., TensorFlow, PyTorch). The embedding dataset is indexed by ScaNN, and the index is served via a lightweight service (e.g., using gRPC).
- Ecosystem: It integrates with TensorFlow ecosystems and can be used alongside other FAIR libraries. For persistent, managed service, its algorithms are often embedded within commercial vector databases.
Trade-offs and Algorithm Selection
Choosing ScaNN involves understanding its performance profile relative to other ANN algorithms like HNSW or IVF-PQ.
- Strengths: Superior recall-speed trade-off for MIPS on inner product spaces, especially with its anisotropic optimization.
- Considerations: Index build time can be higher due to its more complex training process. For purely cosine similarity searches on L2-normalized vectors (where cosine equals inner product), other highly optimized algorithms may be comparable.
- Decision Factor: Use ScaNN when your similarity metric is explicitly inner product and retrieval quality (recall) is paramount.
ScaNN vs. Other ANN Libraries
A technical comparison of Google's ScaNN against other prominent open-source libraries for approximate nearest neighbor search, focusing on algorithmic approach, core optimization, and operational characteristics.
| Feature / Metric | ScaNN | Faiss (Meta) | ANNOY |
|---|---|---|---|
Primary Algorithmic Foundation | Anisotropic Vector Quantization | IVF, PQ, HNSW | Random Projection Forests |
Core Optimization Objective | Maximum Inner Product Search (MIPS) | L2 / Cosine Similarity | Cosine / Euclidean Distance |
Index Update Support (Streaming) | |||
GPU Acceleration Support | |||
Memory Efficiency (for 1M 768-d vectors) | ~600 MB (with PQ) | ~300 MB - 2 GB (varies by index) | ~3 GB |
Typical Search Latency (P95, 1M dataset) | < 2 ms | < 1 ms | 5-10 ms |
Index Build Time (for 1M 768-d vectors) | High | Medium to High | Low |
Primary Use Case | Recommendation & MIPS-heavy workloads | General-purpose high-performance ANN | Static datasets, memory-constrained environments |
Frequently Asked Questions
Scalable Nearest Neighbors (ScaNN) is a library from Google Research for efficient vector similarity search. It is particularly optimized for the Maximum Inner Product Search (MIPS) problem, which is common in recommendation systems and neural network inference. This FAQ addresses its core mechanisms, advantages, and practical applications.
Scalable Nearest Neighbors (ScaNN) is an open-source library developed by Google Research for performing fast, approximate nearest neighbor (ANN) search on high-dimensional vectors. It works by employing a technique called anisotropic vector quantization. Unlike standard quantization methods that treat all directions in the vector space equally, ScaNN's quantization is directionally aware, optimizing the partitioning of space to better preserve the inner product between vectors. This is crucial for MIPS, where the goal is to find vectors with the highest dot product to a query, not necessarily the smallest Euclidean distance. The library typically combines this with an Inverted File (IVF) structure for coarse partitioning, restricting the search to the most promising clusters of vectors.
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 is a specialized library for efficient vector similarity search. Understanding its core components and related algorithms provides context for its performance and use cases.
Maximum Inner Product Search (MIPS)
Maximum Inner Product Search (MIPS) is the core problem ScaNN is optimized to solve. Unlike similarity search based on Euclidean distance or cosine similarity, MIPS finds the vectors that yield the highest dot product with a query vector. This is critical for recommendation systems and neural network inference where vectors (e.g., user and item embeddings) are not normalized. ScaNN's anisotropic vector quantization directly optimizes the index for the MIPS objective, leading to higher accuracy than algorithms adapted from Euclidean distance search.
Anisotropic Vector Quantization
Anisotropic Vector Quantization is ScaNN's key innovation over traditional methods like Product Quantization (PQ). Standard quantization assumes all vector dimensions contribute equally to the distance measure. ScaNN's anisotropic approach learns that some dimensions are more important for the inner product and optimizes the quantization boundaries accordingly. This allows it to:
- Better preserve the true ranking of vectors for the MIPS objective.
- Achieve higher recall@k at the same computational budget.
- Outperform isotropic quantization, especially on complex, high-dimensional datasets.
Product Quantization (PQ)
Product Quantization (PQ) is a foundational compression technique that ScaNN builds upon. It works by:
- Splitting a high-dimensional vector into multiple independent subvectors.
- Quantizing each subvector separately using a small codebook of centroids.
- Representing the original vector by a short code of centroid indices. This achieves extreme memory efficiency, enabling billion-scale indices to fit in RAM. ScaNN integrates PQ but modifies the training and search to be anisotropic, optimizing it for MIPS rather than symmetric Euclidean distance.
Asymmetric Distance Computation (ADC)
Asymmetric Distance Computation (ADC) is the standard method for calculating distances when database vectors are compressed (e.g., with PQ) but the query vector is raw/uncompressed. It computes the distance between the raw query and the quantized database point. ScaNN employs ADC, which is more accurate than symmetric computation between two quantized vectors. The anisotropic codebooks in ScaNN are specifically trained to minimize the error of this asymmetric distance calculation for the inner product, which is why its ADC step is more effective for MIPS.
Inverted File Index (IVF)
An Inverted File Index (IVF) is a two-stage indexing structure often used in conjunction with ScaNN's quantization. It works by:
- Coarse Quantization: Using k-means to partition all vectors into clusters (Voronoi cells).
- Inverted Lists: Storing an inverted list for each cluster containing the IDs of vectors belonging to it. During search, the system finds the nearest clusters to the query and only searches the vectors within those promising cells. This pruning step drastically reduces the number of vectors to score, making search sub-linear. ScaNN can use IVF as a first-level partitioner before applying its anisotropic quantization for scoring.
Recall-Precision Trade-off
The recall-precision trade-off is a fundamental concept governing all ANN systems, including ScaNN. Recall measures how many of the true nearest neighbors are found. Precision (in system performance terms) relates to query speed and resource use. Key levers in ScaNN to manage this trade-off include:
- Number of probes (nprobe) in IVF: Searching more clusters increases recall but slows the query.
- Quantization complexity: Using more centroids per PQ segment improves accuracy at a higher memory and compute cost.
- Anisotropic optimization: ScaNN's core advantage is providing higher recall for a given computational budget (improving the trade-off curve) specifically for MIPS problems.

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