Maudhui makuu ya ukurasa huu ni kwa Kiingereza.Tafsiri ukurasa huu
AI na mada zinazovuma
RAG: Retrieval-Augmented Generation roadmap
RAG is the most common AI feature in business: an assistant that answers questions from company documents, with sources. Learn how it works and build one step by step, from a simple prototype to a measured, production-ready system.
- Muda
- ⏱ 3–4 weeks
- Level
- Intermediate
- Steps
- 6 steps
- Progress
- 0/6 done
The roadmap
Click a step to open the full guide.
Best architecture: a production RAG system
Separate ingestion and query paths, sharing one index with permissions.
Two paths, one index
Ingestion (offline)
- Sources (docs, wiki, PDFs)
- Parse & clean
- Chunk + metadata + permissions
- Embed
- Vector + keyword index
Query (online)
- Question (+ rewrite)
- Hybrid search + permission filter
- Re-rank
- LLM with citations
- Answer + feedback + evals
Why it's built this way
- Ingestion runs separately and only re-processes changed documents.
- Permissions are stored with chunks and filtered at query time.
- Hybrid search + re-ranking gives the best retrieval quality.
- Evals and feedback close the loop.
RAG: Retrieval-Augmented Generation cheat sheet
The essentials on one screen. Bookmark it for revision.
Pipeline
| Load | Text + source + page |
|---|---|
| Chunk | By headings; ~500–800 words; 10–15% overlap |
| Embed | Same model for docs and questions |
| Store | Vector + text + metadata (pgvector or vector DB) |
| Retrieve | Hybrid search → re-rank → top 4–8 |
| Tengeneza | Answer only from context; cite; say 'I don't know' |
Fixes for common problems
| Right info not found | Better chunking, metadata, hybrid search |
|---|---|
| Exact codes/names missed | Add keyword (BM25) search |
| Too much irrelevant context | Re-rank; reduce top-k |
| Made-up answers | Stricter prompt; require citations |
| Follow-ups fail | Rewrite the query with chat history |
| Outdated answers | Re-index changed docs; filter by date |
Improve performance
- Use an ANN index (e.g. HNSW) once you have more than a few thousand chunks.
- Filter by metadata before or during vector search to shrink the search space.
- Re-rank only the top 20–50 candidates, not everything.
- Cache embeddings for repeated questions and answers for frequent questions.
- Send fewer, better chunks to the model: shorter prompts are faster and cheaper.
- Embed documents in batches and only re-embed documents that changed.
Security checklist
- Enforce permissions in retrieval: filter chunks by the user's access before they reach the model.
- Treat document content as untrusted: it may contain prompt-injection text.
- Remove or mask personal data (PII) before indexing when it isn't needed.
- Log which documents were used for each answer for auditing.
- Delete chunks when source documents are deleted (right to be forgotten).
- Keep the vector database private; never expose it directly to the internet.
Most important interview questions
Click a question to see a strong answer. Each step also has its own questions.
1RAG ni nini?
Retrieval-augmented generation: retrieve relevant passages from your data and give them to an LLM so it answers from them, with citations, without retraining the model.
2Describe a production RAG architecture.
Ingestion (parse, clean, chunk, embed, store with metadata and permissions) → query (rewrite, hybrid search, filter, re-rank) → generation (grounded prompt, citations) → evaluation and monitoring, with caching and re-indexing of changed documents.
3How do you choose an embedding model?
Test a few on your own retrieval eval set; consider language support (e.g. Indian languages), vector size (storage cost), speed, price and whether it can run privately.
4the 'lost in the middle' problem ni nini?
Models can pay less attention to information buried in the middle of long contexts. Send fewer, well-ranked chunks and put the most relevant ones first.
5How do you reduce hallucinations in RAG?
Improve retrieval quality, instruct the model to use only the context and say when the answer is missing, require citations, and evaluate faithfulness automatically.
6How do you handle multilingual documents?
Use a multilingual embedding model, store the language in metadata, and either search across languages or translate the query; answer in the user's language.
7RAG vs long context windows: is RAG still needed?
Yes for large or changing data: retrieval is cheaper, faster, respects permissions and gives citations. Long contexts help when a few documents fit entirely.
8How would you evaluate a RAG system?
Golden question set → measure retrieval (recall@k, MRR) and generation (correctness, faithfulness, completeness) separately → automate and track over time → add real user questions.
Ramani Related
AI Engineer
6 steps · 4–6 months · Intermediate
Build products on top of large language models.
View roadmap →PostgreSQL & SQL
6 steps · 4–5 weeks · Beginner
The database most new apps choose.
View roadmap →AI Agents
6 steps · 3–4 weeks · Intermediate
Build AI that plans, uses tools and gets work done.
View roadmap →MCP: Model Context Protocol
5 steps · 2–3 weeks · Intermediate
Connect AI apps to tools and data with one open standard.
View roadmap →