| RAG | Retrieving relevant content and putting it into the prompt so the model answers with evidence. |
| Ingestion | Converting source documents into chunks, vectors and metadata. |
| Retrieval | Finding candidate passages for a query. |
| Generation | Producing an answer grounded in the retrieved passages. |
- Answers must cite sources or use private knowledge.
- Knowledge changes faster than model training cycles.
- You need traceability from claim back to document.
- 01Ingest: parse documents, preserve structure and metadata.
- 02Chunk: split into passages that stand alone.
- 03Embed and index with stable IDs and filters.
- 04Retrieve candidates using keyword + vector search.
- 05Rerank to a small set and pack into the context.
- 06Generate with an instruction to cite sources and abstain when unsupported.
Support assistant on current policies
- Context
- Customers ask about return windows and shipping rules.
- Problem
- Answers are plausible but quote outdated policy text.
- Approach
- Ingest versioned documents, retrieve with hybrid search, rerank and cite only supported claims.
- Outcome
- Answers match current policy or explicitly abstain when evidence is missing.
Onboarding over private documents
- Context
- New employees ask questions about internal handbooks.
- Problem
- General models have no access to private procedures.
- Approach
- Index handbook passages with access metadata and keep citations in the answer.
- Outcome
- Employees get traceable answers without exposing documents to other tenants.
Grounded generation prompt (shape)
System: Answer using ONLY the provided sources. Cite source IDs like [chunk:...].
If the sources do not support the answer, say: "I don't have enough evidence."
Sources:
[chunk:policy-returns-3] Returns accepted within 30 days with receipt...
[chunk:policy-shipping-2] International orders ship in 5-10 business days...
Question: Can I return an international order after 2 weeks?Keep evidence delimited and labeled so it is not confused with instructions.
Minimal retrieval config
retrieval:
mode: hybrid # keyword + vector
top_k: 20
rerank_top_n: 20
final_passages: 5
filters:
tenant_id: required
language: auto
generation:
cite_sources: true
abstain_on_low_evidence: trueLarge chunks
Up: More context per hit
Down: Diluted relevance, higher cost
Many retrieved chunks
Up: Higher recall
Down: More noise and slower generation
Strict citations
Up: Verifiable answers
Down: More abstentions on ambiguous queries
| Option | Upside | Cost |
|---|---|---|
| Large chunks | More context per hit | Diluted relevance, higher cost |
| Many retrieved chunks | Higher recall | More noise and slower generation |
| Strict citations | Verifiable answers | More abstentions on ambiguous queries |
- Preserve document titles and section paths in each chunk.
- Keep a unique chunk ID for traceability.
- Evaluate retrieval separately from generation.
- Handle the no-evidence case explicitly.
| Key | Typical value | Note |
|---|---|---|
| chunk_size | 300–800 tokens | Tune on your documents. |
| top_k | 10–20 before rerank | Then keep 3–6. |
| no_answer_threshold | task-specific | Triggers abstention. |
| Symptom | Cause | Fix |
|---|---|---|
| Answers cite the wrong source | Weak chunk IDs or metadata | Carry source IDs through to generation. |
| Retrieval misses obvious documents | Parsing failed or chunks too large | Inspect parsed output and reduce chunk size. |
Why does RAG still hallucinate?
Retrieval can return irrelevant content and models can ignore it. Measure both stages separately.
Should I store vectors in the prompt?
No. Store them in an index; put only the retrieved text in the prompt.
More in RAG & knowledge
Chunking and metadata design
How to split documents so retrieved passages remain useful, and which metadata to keep.
Hybrid search and reranking
Combine lexical and semantic retrieval, then use a reranker to improve precision before generation.
RAG evaluation: retrieval and answer quality
Separate the two halves of RAG quality so you know whether to fix retrieval or generation.