Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.9 — Playbook: A Keyword Baseline
RAG and Vector Search · Example 1 of 1

Recipes: one analyser and an index you can update

Production-shaped but small: incremental postings, one analyser object, ties broken by id. A real engine adds persistence, segments and concurrency.

Recipes to copy into any project: one analyser for both sides, an index that handles add, update and remove, per-term score explanations, an exact-id lookup, a harness, and the checklist to pass before you add vectors.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write missing_terms(index_terms, text), a tiny check that returns the list of terms in text (lower-cased runs of letters and digits) that are missing from the set index_terms. Print it for the index terms {"monthly", "pass"} and the text "The monthly pass".

02

Write rebuild_equals(postings_a, postings_b) comparing two dicts of term -> {doc: tf} and returning "same" or "different". Print the result for two small dicts that are equal and two that differ in one count.

Explain it without notes

01

Why must an update remove the old postings before adding the new ones?

02

What is the single most important rule about the analyser, and how do the recipes enforce it?

03

Why check an identifier with an exact match before ranking?

Recipes: one analyser and an index you can update
Sign in to run this example in your browser.

Expected output

documents: 3, terms: 27
'charges for late bikes': D6=1.394, D9=0.512
'what does a pass cost':  D8=1.885
after updating D8:        D8=2.215
documents: 3, terms: 23
after removing D8:        (none)
documents: 2, terms: 18