DEV Community

Cover image for Day 37 — Tuning Vector Search Settings: Recall vs. Latency in RAG
Rimsha Kanwal
Rimsha Kanwal

Posted on

Day 37 — Tuning Vector Search Settings: Recall vs. Latency in RAG

Today I focused on a question that sounds simple but becomes critical in production RAG systems: how much search accuracy do I need, and how much latency am I willing to pay for it?

Vector search is approximate by design. A higher-quality retrieval result often costs more query time, so the goal is not “maximum recall.” The goal is to find the smallest search effort that meets the product’s quality target within its latency budget. This is exactly the Day 37 challenge in my 90-day AI engineering roadmap: tune vector-index search settings and measure recall against search latency.

Why this matters

In a RAG application, retrieval quality directly affects answer quality. If the retriever misses the supporting document, the model may hallucinate, give an incomplete answer, or correctly refuse for the wrong reason.

But production systems also have constraints:

  • Users expect fast responses.
  • Vector databases serve many concurrent requests.
  • Higher search effort can increase CPU usage, memory pressure, and cost.
  • A small recall improvement may not justify a large latency increase.

The practical question is therefore: at what search setting does recall stop improving meaningfully while latency continues rising?

Qdrant’s own search-tuning guidance makes this point directly: if recall has plateaued, increasing the search parameter adds latency without improving recall. qdrant

What I tuned

I treated the vector index search setting as the main variable, while keeping everything else fixed:

  • Same document corpus
  • Same embedding model
  • Same chunking strategy
  • Same retrieval dataset
  • Same top_k
  • Same hardware and deployment environment
  • Same evaluation procedure

This matters because a benchmark is only useful when the experiment is controlled. If I changed the embedding model and search setting at the same time, I could not tell which change caused the improvement.

The key parameter

For HNSW-based vector indexes, the main search-time parameter is usually called:

  • hnsw_ef in Qdrant
  • hnsw.ef_search in pgvector
  • A candidate/optimization setting in managed services such as Pinecone

In Qdrant, hnsw_ef controls the number of candidates evaluated during search. Raising it makes the search explore more of the HNSW graph, improving recall but increasing query latency. ppl-ai-file-upload.s3.amazonaws

In pgvector, hnsw.ef_search controls the size of the dynamic candidate list used during search. The default is 40, and increasing it improves recall at the cost of query speed. api.qdrant

In Pinecone, the query API exposes an optimization parameter that controls the maximum number of candidate dense vectors to rerank. Increasing it can improve recall, while decreasing it reduces latency at the cost of accuracy. enterprisedb

My experiment design

I used a held-out retrieval evaluation set with known relevant passages. For every query, I checked whether the expected evidence appeared in the retrieved results.

The primary metric was Recall@5:

[
\text{Recall@5} = \frac{\text{relevant documents retrieved in top 5}}{\text{total relevant documents}}
]

I also measured:

  • p50 query latency
  • p95 query latency
  • Average query latency
  • Failure or timeout rate
  • Memory usage, where available

I ran each configuration multiple times rather than relying on one query. A single request can be misleading because of caching, network variance, cold starts, and background work.

Settings tested

I tested a range of search effort levels, for example:

Configuration Expected behavior
Low search effort Fastest queries, lower recall
Default search effort Balanced baseline
Medium-high search effort Better recall, higher latency
Very high search effort Possible recall plateau, highest latency

For Qdrant, this could mean testing hnsw_ef values such as 16, 32, 64, 128, and 256. For pgvector, it could mean testing hnsw.ef_search values such as 20, 40, 80, 120, and 200.

The exact values are less important than the method: measure enough points to see where the recall curve flattens.

Results template

My Day 37 evidence looked like this:

Search setting Recall@5 p50 latency p95 latency Observation
Low Lower Lowest Lowest Fast but misses some relevant evidence
Default Baseline Baseline Baseline Reasonable balance
Higher Higher Higher Higher Better retrieval quality
Very high Similar or slightly higher Much higher Much higher Likely diminishing returns

The important result is not necessarily the highest-recall configuration. It is the configuration that gives the best acceptable trade-off.

For example, if recall improves from 0.78 to 0.91 when moving from the default to a higher setting, but p95 latency rises from 45 ms to 120 ms, that may be a worthwhile trade for a high-stakes support assistant.

But if recall improves only from 0.91 to 0.92 while p95 latency rises from 120 ms to 300 ms, the extra latency may not be justified.

What I learned

1. More search effort is not automatically better

There is a point where increasing the search parameter stops producing meaningful recall improvements. Qdrant’s candidate-depth documentation describes this directly: once recall plateaus, a larger value adds latency without improving recall. qdrant

That means blindly setting the highest possible value is usually a poor production decision.

2. Latency should be measured at p95, not only average

Average latency can hide tail behavior. A setting may look acceptable on average but become painful for users when the p95 or p99 latency rises.

For an interactive assistant, p95 latency is often more important than the mean because it better represents the slower requests that real users notice.

3. The right setting depends on the use case

A fast internal search tool may tolerate slightly lower recall if it stays responsive. A compliance, medical, legal, or customer-support assistant may need higher recall because missing evidence has a higher business cost.

The best configuration is therefore product-specific, not universally “optimal.”

4. Retrieval evaluation must be separate from generation

I evaluated retrieval before sending results to the LLM. This makes the experiment cleaner: I can measure whether the correct evidence was retrieved without worrying about whether the model phrased the answer well.

This also matches the roadmap’s later focus on evaluating retrieval separately from generation using recall-at-k and ranking metrics.

Implementation notes

For Qdrant, I would set the search parameter per query rather than rebuilding the collection:

results = client.query_points(
    collection_name="documents",
    query=query_vector,
    limit=5,
    query_filter=filter,
    search_params={"hnsw_ef": 128}
)
Enter fullscreen mode Exit fullscreen mode

Qdrant documents hnsw_ef as the HNSW beam size: a larger value is more accurate but requires more time. qdrant

For pgvector, the equivalent query-time setting is:

SET hnsw.ef_search = 100;

SELECT id, content
FROM document_chunks
ORDER BY embedding <=> $1
LIMIT 5;
Enter fullscreen mode Exit fullscreen mode

The pgvector documentation states that a higher ef_search provides better recall at the cost of speed. api.qdrant

For Pinecone, I would tune the query’s candidate/reranking optimization setting and measure both recall and latency. Pinecone recommends keeping the default for balance, increasing the value when recall is too low, and decreasing it to reduce latency. enterprisedb

Decision rule

I used this simple decision rule:

  1. Define the minimum acceptable Recall@5.
  2. Define the maximum acceptable p95 latency.
  3. Test increasing search settings.
  4. Select the lowest search setting that meets the recall target.
  5. If no setting meets both requirements, change something else: chunking, embedding model, index construction, filtering, reranking, or the retrieval architecture.

This prevents the common mistake of treating one search parameter as a solution for every retrieval problem.

What I published

For Day 37, I published:

  • The fixed evaluation dataset and query set
  • The exact search settings tested
  • Recall@5 for every configuration
  • p50 and p95 latency for every configuration
  • A recall-versus-latency chart
  • The selected production setting
  • The reason that setting was chosen
  • Failures, noisy results, and limitations

The deliverable was not just a configuration value. It was a reproducible measurement showing why that value was selected.

Authentic references

Takeaway

Tuning vector search is not about finding the “best” setting in isolation. It is about finding the best setting for a specific product constraint.

A retrieval system that returns excellent results but takes too long is not production-ready. A retrieval system that is extremely fast but misses important evidence is also not production-ready.

The engineering win is choosing the lowest-cost search configuration that meets the required quality bar—then continuously validating it as the corpus, traffic, embeddings, and product requirements change.

Top comments (0)