Mental model
Module 06: Retrieve semantically similar chunks- Build a small vector index, understand top-k retrieval, and learn why nearest-neighbour search needs filters and evaluation.
Build a small vector index, understand top-k retrieval, and learn why nearest-neighbour search needs filters and evaluation.
Engineering focus: Retrieve semantically similar chunks
Build a small vector index, understand top-k retrieval, and learn why nearest-neighbour search needs filters and evaluation.
You are not expected to know the engineering vocabulary before using the idea. Formal terminology comes after the mental model.
Carry one evidence-grounded knowledge assistant through all 18 modules. Preserve source IDs, retrieval evidence, evaluation cases, authority decisions and security assumptions so every improvement is measurable.
Vector search is a candidate finder. top-k controls how many neighbours you inspect before later filtering, reranking and context construction.
A vector index retrieves candidates; it does not decide authority or permission.
The retriever returns the k most similar items. Too small can miss evidence; too large can flood context with noise.
Approximate nearest-neighbour indexes improve scale by trading exactness for speed and memory efficiency.
Always retain the ability to print retrieved chunks, scores and metadata. Retrieval must be observable.
Metadata filtering changes the candidate set and can affect both correctness and performance.
Module 06: Retrieve semantically similar chunksk=1 -> [network-summary] # misses exact procedure
k=3 -> [network-summary, api-runbook, dns-note]
rerank -> [api-runbook, network-summary]
context -> [api-runbook]Relevant evidence exists but is absent from top-k.
Tune candidate generation with labelled retrieval cases.
Goal: Implement a tiny in-memory top-k vector search and inspect ranked results.
python3 - <<'PY2'
from math import sqrt
def cos(a,b): return sum(x*y for x,y in zip(a,b))/(sqrt(sum(x*x for x in a))*sqrt(sum(y*y for y in b)))
q=[1,0]; docs={'network':[.95,.05],'payroll':[.1,.9],'api':[.8,.2]}
print(sorted(((cos(q,v),k) for k,v in docs.items()),reverse=True)[:2])
PY2Record the intermediate source IDs, ranks, metadata or state produced by the baseline. Explain which pipeline layer this evidence belongs to.
Set k=1 so a relevant second-ranked candidate is excluded, then repeat with k=2. Record the recall/noise trade-off.
Tune candidate generation with labelled retrieval cases. State the failing layer, change only that layer, then repeat the verification checks.
Record: hypothesis → evidence → change → observed result → remaining limitation. Keep this note with the running Evidence Desk project.
Production RAG improves when every change can be traced to evidence at a specific pipeline layer. In production, retain the before/after evidence so the same failure can become a regression test.
Top-k justified by retrieval eval
Latency and recall measured
Raw text inspected in regression cases
How many nearest candidates are returned.
It can introduce irrelevant or conflicting context.
Approximate nearest-neighbour search that trades some exactness for scalable speed.
Query identity, returned source/chunk IDs, scores, filters and latency where appropriate.
Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.
Attempt the core lab and knowledge checks before marking the module complete.