Track 02 · RetrievalLesson 03 of 11
Vector stores and HNSW tuning
Size, tune and price the index against the real corpus and its recall target.
- Lesson library · reference
- 40 min read
- 60 min hands-on
- Pro
What you'll be able to do
01- Explain how HNSW finds neighbours, and what
M,ef_constructionand search-timeefeach trade between recall, latency, memory and build time. - Distinguish ANN recall (index versus exact search) from retrieval relevance (results versus user intent), and measure each.
- Size a vector store from first principles for a real corpus, including quantisation, graph overhead, payload, replicas and headroom, and turn it into a monthly cost.
- Design filtered search that stays correct and fast under permission and region filters, avoiding post-filtering recall collapse.
- Choose between Qdrant, Weaviate, Elasticsearch, pgvector and managed options with reasons an architecture review will accept.
Before you start
- Picking embeddings on your corpus, not a leaderboard: dimensions, precision, metrics and recall@k.
- Parsing and chunking documents that fight back: the payload fields (ACL groups, region, doc type, dates) you will filter on.
- Comfort with big-O reasoning and basic capacity planning (RAM, disk, replicas).
The short version
A vector database stores embeddings with their payloads and answers "which stored vectors are nearest to this one, subject to these filters?" fast enough for an interactive product. Exact search compares against every vector and is fine for small sets. At enterprise scale you use an approximate index, almost always HNSW, which trades a small, measurable loss of recall for large speed-ups. Your job on an engagement is to size memory and cost from the real corpus, tune the index against a recall target measured against exact search, make filters (especially permissions) work without destroying recall, and pick a store the customer can operate.
- HNSW has three knobs:
M(graph degree),ef_construction(build effort) andef(search effort). Tuneeffirst; it needs no rebuild. - Memory is roughly vectors × dimensions × bytes per dimension, plus graph links, payload, replicas and headroom. Quantisation with rescoring is the biggest lever.
- Post-filtering after ANN search silently returns too few results for selective filters. Use filter-aware search.
- Measure ANN recall against exact search in CI. It is a different number from retrieval quality.
- The store is derived data, but rebuilding it costs re-embedding time and money. Snapshot it.
Pro lesson
The rest of this lesson is in Pro.
The mental model, worked example, field note, failure table, exercise and self-check, with the voice tutor.
- Every stage and specialisation, in full
- Every lab and every role project
- Halden weeks 2–10, on your record
- Every drill, live in the playground
- All solutions, plus the server judge
- Lab Assistant and every Teach with AI