AI Agent Vector Search: 7 Methods to Cut Latency
Slow vector search is rarely the database's fault - it is index parameters, vector dimensions and retrieval strategy. Seven methods with the exact change, the metric to verify, and the combined result.
📜 Table of Contents
- Method 0: baseline first
- Method 1: tune HNSW - the biggest free win
- Method 2: quantization to cut memory bandwidth
- Method 3: fewer dimensions with Matryoshka embeddings
- Method 4: filter inside the search, not after
- Method 5: batch and parallelize
- Method 6: hybrid retrieval plus rerank
- Method 7: cache hot queries
- Combined effect
- FAQ
📖 Keep reading
AI Agent Vector Search: 7 Ways to Cut Retrieval Latency (2026)
A RAG request takes three seconds and 500ms of it is vector search. Users do not know which stage is slow; they just feel that the assistant is sluggish.
Order matters: measure a baseline, then tune the index, then touch the vectors. Get the order wrong and you conclude "vector search is just slow".
Method 0: baseline first
Record P50/P95 latency, recall@10 on 50 labelled questions, index size (count, dimensions, filters) and peak QPS. Without a recall baseline, every speedup is unverifiable - setting top-k to 1 also makes it faster.
Method 1: tune HNSW - the biggest free win
| Parameter | When | Effect | Start at |
|---|---|---|---|
M |
Build | Links per node; higher recall, more memory | 16, try 32 |
ef_construction |
Build | Candidate set at build time | 100-200 |
ef_search |
Query | Candidate set at query time; accuracy vs speed | 64, tune |
ef_search is a query-time parameter, so you can sweep it without rebuilding. Plot latency against recall and pick the knee.
client.search(collection_name="docs", query_vector=vec, limit=10,
search_params={"hnsw_ef": 96, "exact": False})
Method 2: quantization to cut memory bandwidth
client.create_collection(
"docs",
vectors_config=models.VectorParams(size=768, distance=models.Distance.COSINE),
quantization_config=models.ScalarQuantization(
scalar=models.ScalarQuantizationConfig(type=models.ScalarType.INT8, quantile=0.99, always_ram=True)),
)
float32 to int8 cuts memory and bandwidth to a quarter, and HNSW at scale is often bandwidth-bound. Re-measure recall on the same 50 questions; if it drops more than about 2 points, enable rescoring with the original vectors on the top candidates.
Method 3: fewer dimensions with Matryoshka embeddings
Models trained with Matryoshka can be truncated: the first N dimensions are a usable lower-dimensional representation. OpenAI's text-embedding-3 accepts a dimensions parameter; several open models support truncation plus renormalization. 768 to 256 cuts storage and distance work to roughly a third. This requires recomputing and rebuilding everything.
Method 4: filter inside the search, not after
Retrieve top-100 then filter by tenant can leave you three results. Filter inside the vector query and index the filter field:
client.search("docs", query_vector=vec, limit=10,
query_filter=models.Filter(must=[models.FieldCondition(
key="tenant_id", match=models.MatchValue(value="acme"))]))
For multi-tenant systems, per-tenant collections or shards make filtering nearly free.
Method 5: batch and parallelize
An agent often issues a dozen sub-queries per turn. Ten serial 30ms lookups is 300ms. Use batch search, run independent queries concurrently within the connection pool, and encode embeddings in batches.
client.search_batch("docs", requests=[models.SearchRequest(vector=v, limit=10) for v in vecs])
Method 6: hybrid retrieval plus rerank
Raising top-k to fix recall costs latency linearly. Cheaper: take top-50 from vectors, add BM25, merge, rerank with a light model, keep 10. Vector search is weak on product codes, error strings and proper nouns; keyword search covers exactly that.
Method 7: cache hot queries
Cache keys must include every filter, or you leak data across tenants, and the cache must invalidate on index updates - a collection version prefix handles both. Semantic caching is a riskier second layer for high-repetition support traffic.
Combined effect
| Change | Latency | Recall | Cost to adopt |
|---|---|---|---|
| HNSW tuning | Sharp drop | Neutral if tuned | None |
| int8 quantization | Sharp drop | Small drop, rescore fixes | Rebuild |
| Fewer dimensions | Sharp drop | Small drop | Rebuild + re-embed |
| Filter inside search | Drop | Improves (no empty results) | Payload index |
| Batching | Total time drops | None | Code change |
| Hybrid + rerank | Slightly up per query | Improves | Extra retrieval path |
| Cache | Near zero on hits | None | Cache layer |
Most projects do 1+4+5 first (no rebuild), then 2 or 3, then 6. Hundreds of milliseconds to tens is a common outcome - measure on your own data.
FAQ
Always HNSW? Under a few million vectors, yes. At billions, look at IVF-style or disk-based indexes.
Recall dropped after quantization? Rescore the top ~100 candidates with original vectors.
Would a faster database fix it? Only partly. Untuned parameters, unindexed filters and per-item queries are slow on any engine.
How to trade recall against latency? Plot recall@10 against P95 and pick the point your use case tolerates. Support chat and contract search do not share the same standard.
Parameter names and defaults differ per engine - check official docs; verify all speedups on your own data.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.