Build Your First RAG Pipeline
Implement answer(question, documents, model, k=3):
- Chunk every document with
chunk_document(text, 40, 10)(provided). - Embed the chunks and the question with
embed(texts)(provided, deterministic). - Retrieve the
kchunks most similar to the question, best first. - Build the context: join those chunks with a blank line between them.
- 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.