Skip to content

< all problems08 · Level 03, RAG

Build Your First RAG Pipeline

medium · agent loop · RAG

Implement answer(question, documents, model, k=3):

  1. Chunk every document with chunk_document(text, 40, 10) (provided).
  2. Embed the chunks and the question with embed(texts) (provided, deterministic).
  3. Retrieve the k chunks most similar to the question, best first.
  4. Build the context: join those chunks with a blank line between them.
  5. Ask the model with a prompt containing both the context and the question, and return model.ask(prompt).

The model is scripted, so the tests check the pipeline: the right chunks retrieved, and both context and question in the prompt.