ScaNN (Scalable Nearest Neighbors) is a quantization-based approximate nearest neighbor (ANN) algorithm that introduces anisotropic vector quantization to prioritize the preservation of inner product scores critical for Maximum Inner Product Search (MIPS). Unlike isotropic quantizers that minimize Euclidean reconstruction error uniformly, ScaNN's loss function is specifically designed to weight quantization error by how much it impacts the dot product, yielding superior recall for recommendation and attention models.
Glossary
ScaNN

What is ScaNN?
ScaNN is a vector similarity search library developed by Google Research that optimizes the trade-off between search accuracy and speed for Maximum Inner Product Search (MIPS).
The algorithm compresses database vectors by learning a codebook where the quantization granularity is higher along dimensions with greater variance, directly optimizing the recall@k versus throughput tradeoff. ScaNN achieves state-of-the-art performance by combining this anisotropic quantization with a fast, SIMD-optimized scoring kernel, making it a leading choice for production systems requiring low-latency, high-recall retrieval over billion-scale embedding datasets.
Key Features of ScaNN
ScaNN (Scalable Nearest Neighbors) is Google's vector similarity search library that optimizes the recall-speed tradeoff through anisotropic vector quantization, specifically designed to preserve inner product scores critical for Maximum Inner Product Search (MIPS).
Anisotropic Vector Quantization
Unlike traditional Product Quantization (PQ) which minimizes reconstruction error uniformly, ScaNN's anisotropic quantization explicitly optimizes for the preservation of inner product scores. It learns a quantization codebook that allocates more precision to vector components with higher variance, recognizing that not all dimensions contribute equally to the dot product. This is critical for MIPS workloads where the magnitude of the query-database interaction matters. The technique reduces quantization error along dimensions that most impact the inner product, yielding higher recall at equivalent compression ratios compared to isotropic methods.
Score-Aware Quantization Loss
ScaNN introduces a novel score-aware quantization loss function that directly penalizes errors in the approximated inner product rather than Euclidean distance. The loss is formulated as:
- Minimizing the difference between the true dot product and the quantized dot product
- Weighting the loss by the query distribution to focus on high-probability query regions
- Jointly optimizing the coarse and fine quantization codebooks end-to-end This design ensures that the compressed vectors maintain the correct ranking order when scored against typical queries, directly optimizing for the Recall@K metric used in production retrieval systems.
Two-Level Tree-Quantization Index
ScaNN combines an Inverted File Index (IVF) for coarse partitioning with anisotropic quantization for fine-grained compression in a two-level structure:
- Level 1 (Coarse Quantizer): Partitions the vector space into Voronoi cells using K-means clustering, assigning each database vector to its nearest centroid
- Level 2 (Fine Quantizer): Applies anisotropic quantization to the residual vectors (the difference between the original vector and its assigned coarse centroid)
- Asymmetric Distance Computation (ADC): Queries remain in full precision while only database vectors are compressed, yielding higher accuracy than symmetric approaches This architecture enables sub-linear search complexity while maintaining high fidelity for inner product ranking.
MIPS-Optimized Search Pruning
Standard ANN algorithms optimized for Euclidean distance or cosine similarity perform poorly on Maximum Inner Product Search (MIPS) because inner product is not a metric—it violates the triangle inequality. ScaNN addresses this with:
- Query-dependent pruning: Dynamically adjusts search radii based on the query vector's magnitude, since high-magnitude queries require exploring more partitions
- Inner product upper bound estimation: Computes tight theoretical upper bounds on the maximum possible inner product within each Voronoi cell to safely prune unpromising partitions
- Adaptive candidate selection: Varies the number of coarse partitions searched based on the query's norm, balancing speed and recall per-query This makes ScaNN particularly effective for attention mechanisms and matrix factorization models where MIPS is the core operation.
SIMD-Accelerated Distance Computations
ScaNN leverages SIMD (Single Instruction, Multiple Data) instructions extensively to parallelize the inner product computations that dominate search latency:
- Uses AVX2 and AVX-512 instruction sets on x86 processors for 8-way or 16-way parallel floating-point operations
- Implements cache-friendly memory layouts that store quantized codes contiguously to maximize cache line utilization
- Batches distance computations across multiple query vectors simultaneously for amortized throughput gains
- Achieves sub-millisecond latency per query on billion-scale datasets when deployed on optimized hardware These low-level optimizations are critical for production deployments requiring high queries-per-second throughput.
Dynamic Re-Ranking Pipeline Integration
ScaNN is designed to serve as the fast candidate generation stage in a two-stage retrieval pipeline:
- Stage 1: ScaNN retrieves a candidate set (e.g., top-1000) using quantized vectors with high recall
- Stage 2: A more expensive re-ranking step computes exact inner products on the full-precision vectors for the candidate set only
- The anisotropic quantization ensures that the true top-K results are included in the candidate set with high probability, minimizing recall loss
- Configurable tradeoff: Adjust the number of coarse partitions searched and the candidate set size to balance latency against Recall@K targets This architecture is the standard pattern for production semantic search systems requiring both speed and accuracy.
Frequently Asked Questions
Technical answers to common questions about Google's ScaNN algorithm, its anisotropic quantization mechanism, and its performance characteristics in production vector search systems.
ScaNN (Scalable Nearest Neighbors) is a quantization-based approximate nearest neighbor search algorithm developed by Google Research that optimizes the recall-speed tradeoff through anisotropic vector quantization. Unlike traditional product quantization which minimizes reconstruction error uniformly, ScaNN prioritizes the preservation of inner product scores critical for Maximum Inner Product Search (MIPS). It works by learning a quantization codebook that allocates more precision to vector components with higher variance—those dimensions that disproportionately influence the dot product. The algorithm introduces a novel anisotropic quantization loss function that weights the quantization error by the query distribution's covariance structure, ensuring that the compressed vectors maintain accurate inner product rankings even at aggressive compression ratios. This makes ScaNN particularly effective for recommendation systems and attention mechanisms where the magnitude of the dot product directly determines relevance scores.
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
Core concepts and related algorithms that define the context for Google's ScaNN library, focusing on the quantization and search techniques that optimize the recall-speed tradeoff.
Anisotropic Vector Quantization
The core innovation of ScaNN. Unlike standard quantization that minimizes reconstruction error, anisotropic quantization explicitly optimizes the quantization process to preserve the inner product between the query and database vectors. It learns a quantization distortion that penalizes errors parallel to the original vector direction more heavily than orthogonal errors, ensuring the dot product score—critical for Maximum Inner Product Search (MIPS)—remains highly accurate even after aggressive compression.
Product Quantization (PQ)
The baseline compression technique that ScaNN improves upon. PQ decomposes a high-dimensional vector into smaller subvectors and quantizes each independently using a distinct codebook. While PQ minimizes reconstruction error (how close the compressed vector is to the original), it is agnostic to the final search metric. ScaNN modifies this by scoring quantization centroids based on their impact on the dot product rather than Euclidean distance, achieving higher recall for MIPS at the same compression ratio.
Score-Aware Quantization Loss
The custom loss function that differentiates ScaNN from traditional vector compression. Standard quantization minimizes ||x - ilde{x}||^2. ScaNN's loss function is ||x - ilde{x}||^2 + \lambda \cdot f(\langle q, x angle, \langle q, ilde{x} angle), where the second term explicitly penalizes discrepancies in the inner product score. This score-aware optimization ensures that the relative ordering of database vectors by relevance to a query is preserved, even when the absolute vector reconstruction is imperfect.
Two-Level Indexing with IVF
ScaNN combines its anisotropic quantization with an Inverted File Index (IVF) for coarse partitioning. The vector space is first partitioned into Voronoi cells using a coarse quantizer. During search, only the most promising partitions are visited. Within each partition, the residual vectors are compressed using ScaNN's anisotropic PQ. This two-level approach dramatically reduces the number of distance computations, while the anisotropic compression ensures high recall within the probed partitions.
Asymmetric Distance Computation (ADC)
The efficient distance approximation scheme used at query time. The query vector remains in full precision, while only the database vectors are compressed via anisotropic quantization. The inner product is approximated by computing the dot product between the uncompressed query and the quantized database vectors using pre-computed lookup tables. This asymmetry yields significantly higher accuracy than symmetric computation (where both are compressed) and is a key factor in ScaNN's state-of-the-art recall-speed Pareto frontier.

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