Two paths and a version counter
A toy keyword index so that three languages print the same text. The structure is the point: ingest() writes, query() only reads, and the version moves on every write.
A RAG service is two programs that share data: an ingestion path that turns documents into an index when they change, and a query path that answers a question in a few seconds. Knowing which parts are online, which are batch and where state lives is the first production decision.
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.
Write upsert(index, doc_id, chunks) for an index that is a dict from (doc_id, n) to text. It must remove all old entries of doc_id first, then add the new chunks, and return the number of entries removed. Call it twice with the same chunks and show the index size does not change.
Write a function deleted(index, doc_id) that removes every entry of a document and returns how many it removed. Show a query that finds the document before and does not after.
Explain it without notes
Why split a RAG service into an ingestion path and a query path?
What is the source of truth in a RAG system, and why does it matter that the index is derived?
What does it mean for ingestion to be idempotent, and how do you achieve it?
Name three things that must never happen on the online query path.
Expected output
ingest D3: 19 distinct words, index version 1
ingest D8: 15 distinct words, index version 2
ingest D2: 16 distinct words, index version 3
ask: What does the monthly pass cost? -> The monthly pass costs 25 dollars and includes unlimited rides of up to 45 minutes. [D8]
ask: Do you rent scooters? -> I can't find that in the handbook.
ingest D8: 15 distinct words, index version 4
ask: What does the monthly pass cost? -> The monthly pass costs 30 dollars and includes unlimited rides of up to 45 minutes. [D8]
store: 3 documents, index: 3 entries, version 4