After studying this material, you should be able to:
Imagine you have a library of millions of documents, each converted into a vector of numbers (an embedding). When a user asks a question, that question is also converted into a vector.
MIPS answers: "Which document vector aligns best with my question vector?"
Inner product = a mathematical measure of how well two vectors point in the same direction. Higher = better match.
User asks: "What causes thunder?"
↓
Convert to query vector: [0.2, 0.8, 0.1, ...]
↓
Compare against 2,000,000 document vectors
↓
Find the document with the HIGHEST inner product score
↓
Prefix that document to the query → send to LLM
| Database Size | Vector Dimensions | Comparisons Needed |
|---|---|---|
| 1,000 docs | 100 dims | Manageable |
| 2,600,000 docs | 1,000 dims | Extremely costly |
Checking every single document = exhaustive search = slow and expensive at scale.
Instead of comparing the query to all n documents, traditional systems:
Without clustering: compare to n = 2,600,000 documents
With k=128 clusters: compare to 128 centroids + ~20,000 documents
→ roughly 128× speedup
Here is the problem visualized conceptually:
Cluster A centroid: ● (average position)
Actual documents: ○ ○ ○ ○ ○ ★ ← outlier, far from centroid
but VERY close to query ✦
Query ✦ is near ★, but centroid ● looks far from ✦
→ System skips Cluster A entirely → WRONG answer
The centroid cannot tell you how good the BEST key inside a cluster is. It only tells you where the average is.
In RAG specifically:
These live in different regions of embedding space. Methods designed assuming queries look like documents will perform poorly.
This is the key theoretical breakthrough in the paper.
The function that takes a query vector and returns the highest possible inner product score with any key in the database is called the support function of that set of keys.
Formally:
h(query) = max over all keys { inner_product(query, key) }
This function has two powerful properties:
| Property | What It Means | Why It Helps |
|---|---|---|
| Convexity | The function curves upward in a predictable way | Can be approximated by special neural networks (ICNNs) |
| Gradient = Best Key | The derivative of h at any query points to the best-matching key | One network can solve two problems |
Traditional approach: search through all keys to find the best one
(expensive at runtime)
New approach: train a neural network ONCE to learn h(query)
then at runtime: just run the small NN
(cheap at runtime)
This is called amortization — pay a one-time training cost upfront, save repeatedly at inference time.
Both networks are trained using regression — a supervised learning approach:
Step 1: Sample many query vectors from the real query distribution
Step 2: For each query, run exhaustive search → find ground truth answer
Step 3: Store (query, answer) pairs as training data
Step 4: Train neural network to predict answer given query
Step 5: Deploy the small NN — no more exhaustive search needed
What it learns: The support function value for each cluster
What it replaces: Centroid comparison during routing
How it works:
Old routing:
query → compare to centroid of each cluster → pick closest centroid
New routing with SupportNet:
query → SupportNet outputs k scores → pick cluster with HIGHEST score
The score now answers: "What is the BEST possible match
inside this cluster for this query?"
Why it's better than centroids:
Centroid asks: "Is the average of this cluster close to my query?"
SupportNet asks: "Is there ANY key in this cluster that matches my query well?"
↑ This is the right question to ask!
Architecture detail: Uses Input Convex Neural Networks (ICNNs) — a special NN architecture that guarantees the output is a convex function of the input, matching the mathematical structure of support functions.
Performance on Natural Questions (2.6M passages, 128 clusters):
| Model Size | Recall @ 5% DB scanned | Latency to 95% recall |
|---|---|---|
| Centroid baseline | 87.5% | 3.36 ms |
| SupportNet XS (1%) | ~90% | — |
| SupportNet M (10%) | 92.6% | — |
| SupportNet L (20%) | 97% | 1.74 ms |
Key result: Large SupportNet hits 97% recall at the same latency (1.74 ms) that centroid routing needs just to reach 95% recall.
What it learns: To predict the best-matching key vector directly
What it replaces: The original query vector
How it works:
Old search pipeline:
raw question → IVF index → retrieved documents
New search pipeline with KeyNet:
raw question → KeyNet → predicted key vector → IVF index → retrieved documents
KeyNet transforms: "What is Matchbox Twenty?"
into: a vector that looks like the answer document
The intuition:
Problem: Query "What is Matchbox Twenty?" lives in "question space"
Answer document lives in "answer space"
These spaces don't perfectly overlap
Solution: KeyNet bridges the gap by predicting WHERE in embedding space
the answer document likely lives
Architecture detail: Uses a consistency loss derived from Euler's theorem for homogeneous functions — this keeps predictions geometrically grounded even without enforcing convexity explicitly.
Performance on Natural Questions:
| Model Size | Recall @ 0.001% DB scanned | Latency to 99% recall |
|---|---|---|
| Raw query baseline | 86% | 1.8 ms |
| KeyNet XS (1%) | 89% | — |
| KeyNet L (20%) | 96.7% | 0.23 ms |
Key result: KeyNet L achieves 99% recall ~8× faster than raw query search, and scans ~11× fewer keys to reach the same recall level.
Think of it as a decision tree:
Do you need a calibrated SCORE (for re-ranking or thresholding)?
├── YES → Use SupportNet
│ (outputs meaningful scores, not just a key vector)
│
└── NO → Is inference speed your primary concern?
├── YES → Use KeyNet
│ (fastest path to the right document)
│
└── BOTH matter at massive scale?
→ Use BOTH
SupportNet routes across clusters
KeyNet refines search within each cluster
| Feature | SupportNet | KeyNet |
|---|---|---|
| What it outputs | Score per cluster | Predicted key vector |
| Role in pipeline | Replaces centroid routing | Rewrites the query |
| Architecture | ICNN (convex) | Standard NN + consistency loss |
| Best for | Routing quality, re-ranking | Maximum speed, plug-in to existing IVF |
| Works with existing index? | Replaces routing layer | Yes, drop-in before any IVF index |
| Traditional MIPS | Amortized MIPS |
|---|---|
| Optimizes for any possible query | Optimizes for your actual queries |
| Generic, query-agnostic | Query-distribution-aware |
| Fast to deploy, no training needed | One-time training cost, faster inference |
| Centroid geometry as proxy | Learned neural approximation |
Cost without amortization:
Every query → expensive exhaustive search
1,000,000 queries × high cost = very expensive
Cost with amortization:
One-time training cost (paid once)
+ Every query → cheap NN forward pass
1,000,000 queries × low cost = much cheaper overall
This is the same principle behind many ML systems: invest once in learning, profit repeatedly at inference.
Why does centroid routing fail for outlier documents?
Because the centroid represents the cluster average, not the best possible match. A document far from the centroid but close to the query gets skipped.
What two mathematical properties make support functions learnable?
Convexity (allows ICNN approximation) and the gradient property (gradient = best matching key).
What does "amortization" mean in this context?
Paying a one-time training cost upfront so that each individual query at inference time is much cheaper to answer.
When would you use KeyNet over SupportNet?
When you need maximum inference speed and don't need a calibrated score — KeyNet rewrites the query to look like the answer, then hands off to a standard fast index.
Why is the query-key mismatch a special problem in RAG?
Because queries are short informal questions while keys are long curated documents — they occupy different regions of embedding space, so methods assuming they look similar will perform poorly.