Reference · How-to · ~20 min
How to build a 5-document RAG app
Minimal RAG: five markdown/text files → embeddings → question → cited answer.
Minimal RAG: five markdown/text files → embeddings → question → cited answer.
Steps
1. **Prepare 5 docs** — FAQ, policy, README, etc. Plain text or markdown
2. **Chunk** each doc (~500 tokens, 50 overlap)
3. **Embed** chunks with an embedding API or local model
4. **Store** vectors + text + metadata (filename, chunk id)
5. **On question:** embed query → cosine similarity → top 3 chunks
6. **Prompt LLM:** "Answer using only these notes: … Question: …"
7. **Show sources** in the UI
Minimal loop (pseudo)
chunks = chunk_all(docs)
index = [(embed(c.text), c) for c in chunks]
def answer(q):
q_vec = embed(q)
top = nearest(q_vec, index, k=3)
context = "\n\n".join(c.text for _, c in top)
return llm(f"Context:\n{context}\n\nQ: {q}\nA:")