Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Day 37/90 — Your RAG System Is Only as Good as Its Vector Search

Why tuning HNSW can improve retrieval without changing your embedding model or LLM. Many AI engineers improve RAG systems by switching embedding models, adding rerankers, or upgrading LLMs. But sometimes the real bottleneck is inside the vector index. Even when the correct document exists in your vector database, approximate nearest-neighbor search can fail to return it. Today, let’s look at how…

Day 37/90 — HNSW Configuration Determines RAG Retrieval Performance

Exact nearest-neighbor search compares a query vector against every stored vector, providing true nearest neighbors but becoming slow with large data sets. Approximate Nearest Neighbor (ANN) search, like HNSW, offers faster retrieval at the cost of some recall. HNSW, a graph-based approach, builds a multi-layer index for efficient candidate exploration.

HNSW has three key parameters:

1. m: Graph connectivity, affecting memory use and build time, potentially improving recall.

2. ef_construction: Candidate exploration during index building, longer build times for higher-quality graph.

3. ef_search: Candidate exploration during queries, offering higher recall but increased latency.

Start with pgvector's default settings: m=16, ef_construction=64, ef_search=40. Then, measure retrieval quality and latency on your data. Common tuning progression:

- Start with ef_search=40 for a fast baseline

- Increase to ef_search=80 for better recall and moderate latency

- Try ef_search=100 as a strong production starting point

- Higher ef_search values may improve recall but increase latency and cost

Evaluation involves comparing approximate search with exact search using the same queries, embeddings, and settings. Metrics include ANN Recall@10 (exact top-10 retrieval), Relevant Recall@10 (human-labeled relevant documents), P50 and P95 latency, and query throughput. Remember, higher recall does not guarantee relevance, so always evaluate answer quality using RAG metrics.

In production, begin by creating a representative evaluation set from real user queries, labeling relevant documents or chunks. Measure exact search ground truth, then ANN Recall@10 and relevance Recall@10. Tuning ef_search first (no index rebuild needed) followed by adjusting m or ef_construction if needed. Set recall and latency targets, such as maintaining 95% ANN Recall@10 with P95 latency below 50 ms.

Avoid common pitfalls like optimizing only average latency, treating recall as relevance proof, changing m/ef_construction before testing ef_search, or neglecting metadata filters. A strong RAG system depends on both powerful embeddings and a well-tuned vector search pipeline.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Report a problem with this story

Get the day's news by email. Daily, weekly or monthly. Sign up

More in Tech

More from Wednesday, 2 December 2026 →