← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · ✎ updated 7d
← Back to glossary

Retrieval-Augmented Generation (RAG)

AI / ML Advanced
debt(d9/e7/b7/t7)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). detection_hints.automated is no — there's no linter that flags 'you should use RAG here' or 'your chunks are too large.' Quality issues surface only when users get wrong answers.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). quick_fix describes building an embedding pipeline, vector DB, retrieval layer, and prompt restructuring — this is not a one-line patch but adding a whole subsystem (embeddings + vector store + retrieval + prompt assembly).

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). applies_to spans web/cli/queue-worker; once RAG is the AI feature's foundation, chunking strategy, embedding model, and vector store choice shape every future AI feature change. Tagged vector-database — a load-bearing infrastructure choice.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception is explicit: developers believe RAG eliminates hallucination, but the LLM can still fabricate or ignore the retrieved context. This contradicts the intuitive promise of 'grounded generation' and is a documented, costly misunderstanding.

About DEBT scoring →

Also Known As

RAG grounded generation retrieval augmentation

TL;DR

A pattern that combines document retrieval with LLM generation — relevant documents are fetched and injected into the prompt context, grounding responses in current, specific data.

Explanation

RAG solves two LLM limitations: knowledge cutoff dates and hallucination on specific domain data. The pipeline: (1) documents are chunked and embedded as vectors, (2) stored in a vector database, (3) a user query is embedded, (4) similar vectors are retrieved, (5) the retrieved chunks are injected into the LLM prompt as context, (6) the LLM answers based on the provided context. This enables LLMs to answer questions about private or recent data without fine-tuning.

Common Misconception

✗ RAG eliminates hallucination — RAG reduces hallucination by grounding responses in retrieved context, but the LLM can still generate incorrect statements or misinterpret the documents.

Why It Matters

RAG is the primary pattern for building AI features over private or frequently updated data — documentation assistants, support bots, and code search all use RAG.

Common Mistakes

  • Chunk size too large — chunks that are too big include irrelevant text, diluting signal; too small loses context.
  • Not filtering retrieved chunks by relevance score — low-similarity chunks mislead the model.
  • Not citing sources in the response — users cannot verify which document the answer came from.
  • Using the LLM's training knowledge instead of retrieved context when context is provided — prompt must instruct the model to use only the provided context.

Code Examples

✗ Vulnerable
// RAG without relevance filtering — poor chunks mislead LLM:
$allDocs = vectorDB()->search($query, topK: 20); // Too many, low relevance
$context = implode('\n', array_column($allDocs, 'text'));
$response = $llm->complete('Answer based on context: ' . $context . '\n\nQuestion: ' . $query);
✓ Fixed
// RAG with relevance threshold:
$docs = vectorDB()->search($query, topK: 5, minSimilarity: 0.75);
if (empty($docs)) {
    return 'No relevant documentation found for that question.';
}
$context = implode('\n---\n', array_column($docs, 'text'));
$prompt = "Answer the question using ONLY the context below. If the answer is not in the context, say so.\n\nContext:\n$context\n\nQuestion: $query";
return $llm->complete($prompt);

Added 15 Mar 2026
Edited 22 Mar 2026
Views 167
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 2 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Scrapy 14 Ahrefs 11 Google 11 Amazonbot 10 SEMrush 10 Perplexity 9 PetalBot 9 Unknown AI 4 Bing 4 Twitter/X 4 ChatGPT 3 Applebot 2 Meta AI 1 Sogou 1
crawler 86 crawler_json 6 pre-tracking 1
⚡ DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Embed your documents, store in a vector DB (pgvector, Pinecone), retrieve the top-k most similar on each query, and inject them as context before the user question
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
LLM answering questions about your private data without RAG; entire document stuffed into context window instead of retrieved chunks
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant