Lesson
Chunking, Metadata, and Retrieval Quality in RAG
Learning Objectives
- Explain why RAG retrieval quality determines whether generated answers are grounded or misleading.
- Compare common chunking strategies and choose practical chunk boundaries for different business documents.
- Design metadata fields that support filtering, permissions, freshness, source ownership, and debugging.
- Identify retrieval-quality levers such as hybrid search, metadata filters, reranking, top-k tuning, and query rewriting.
- Build a retrieval evaluation set that tests retrieval separately from answer generation.
Prerequisites
Helpful background includes a basic understanding of embeddings, vector databases, semantic search, and retrieval-augmented generation. You do not need advanced machine learning knowledge. The most useful prerequisite is understanding that a RAG system answers well only when it retrieves useful evidence before the model generates a response.
RAG retrieval quality is where many AI answers are won or lost
RAG retrieval quality is the difference between a system that answers from useful evidence and a system that confidently summarizes the wrong material.
Many teams focus on the language model first. They tune the prompt. They swap models. They ask for shorter answers, better citations, or more confident explanations. Those things can matter, but they do not fix the most common failure in retrieval-augmented generation: the model never received the right context in the first place.
A RAG system usually fails earlier than people think.
If the document was split badly, the answer may miss an exception. If metadata is missing, the system may retrieve a policy from the wrong region. If permissions are weak, the model may see content the user should not access. If stale content remains indexed, the generated answer may cite an outdated policy. If top-k retrieval is tuned poorly, irrelevant chunks may crowd out the useful passage. If retrieval quality is never evaluated, the team may not know any of this is happening.
That is why reliable RAG should be treated as a retrieval system first and a generation system second.
Generation is the visible part. Retrieval is the evidence layer underneath it. A strong model with the wrong evidence can still produce a polished wrong answer. A smaller model with precise, current, authorized evidence may produce a more useful result.
This lesson focuses on the retrieval-quality layer: chunking, metadata, filtering, ranking, permissions, freshness, and evaluation. These are not implementation details to handle after the demo. They are the foundation of production RAG.
Why retrieval quality determines RAG quality
Retrieval-augmented generation has a simple promise: retrieve relevant information, place it in context, and ask a model to generate an answer from that evidence.
That promise depends on retrieval.
The model can only use the evidence it receives. If the retriever returns the wrong passage, the model may answer from the wrong passage. If the retriever returns a broad passage with only one relevant sentence, the model may miss the relevant part. If the retriever returns five similar but contradictory chunks, the model may merge them into an answer that no source actually supports.
RAG retrieval quality determines whether the context is:
- relevant to the user’s question;
- current;
- complete enough to answer;
- specific to the right product, region, version, customer tier, or policy;
- authorized for the user;
- traceable to a source;
- compact enough to avoid wasting tokens;
- structured enough to support citations and review.
This matters because generated answers inherit retrieval errors.
A support copilot that retrieves the wrong troubleshooting article may draft the wrong customer response. A policy assistant that retrieves a policy but misses the contractor exception may give employees incomplete guidance. A contract assistant that retrieves a similar prior customer clause instead of approved fallback language may create legal risk.
Better prompts do not solve those problems. Better retrieval does.
What chunking means in RAG
Chunking is the process of splitting larger documents into smaller pieces that can be indexed, retrieved, and passed to a model.
The word sounds simple, but the design choice is important. A chunk is usually the unit of retrieval. If your system retrieves document chunks, then the chunk boundary determines what the model sees.
For example, consider a remote-work equipment policy:
“Employees may expense one external monitor for remote work.”
The next paragraph says:
“Contractors are excluded unless approved by the department head.”
If those two paragraphs are split into separate chunks, a user who asks “Can contractors expense a monitor?” may retrieve only the first paragraph. The model may then answer incorrectly because the exception is missing.
The chunking problem is not just about size. It is about meaning.
A good chunk should usually preserve enough context to answer the type of question users ask. It should include the rule and the exception. It should keep headings with the body text they describe. It should keep a FAQ question with its answer. It should keep a table with enough surrounding explanation to interpret it. It should keep a code snippet with the function or section that explains it.
Chunking is not merely splitting text every N tokens. It is deciding the retrieval unit for the workflow.
Why chunking is not just token splitting
Fixed-size token splitting is common because it is easy. Take a document, split it every 500 or 1,000 tokens, add overlap, embed each chunk, and query the vector database.
That can work for a prototype. It can also fail badly in production.
Fixed-size splitting does not know where meaning begins or ends. It can split a policy rule from its exception, a heading from its section, a table from its caption, a troubleshooting step from its condition, or a code block from its explanation.
RAG retrieval quality improves when chunking respects document structure.
A support article might be chunked by heading and subheading. A policy document might be chunked by section and exception. A contract might be chunked by clause. A transcript might be chunked by topic or speaker turn. A CRM note might be chunked by issue summary rather than full conversation history. A technical document might keep code examples with the surrounding explanation.
The right chunking strategy depends on the document type, user questions, retrieval method, and downstream answer requirements.
There is no universal best chunk size.
A short FAQ answer may work as a single chunk. A legal clause may need surrounding definitions. A troubleshooting guide may need the symptom, cause, and fix together. A technical page may need headings, code, and version metadata. A long policy may need parent-child retrieval: retrieve a small precise child chunk, then provide a larger parent section as context.
The practical goal is not to make chunks small or large. The goal is to make chunks useful.
Common chunking strategies and tradeoffs
Different chunking strategies solve different problems.
| Chunking strategy | Best for | Risk |
|---|---|---|
| Fixed-size chunks | Simple prototypes and uniform text | Can split meaning or include irrelevant text |
| Paragraph chunks | Articles and prose | May lose heading context |
| Heading-aware chunks | Docs, policies, help centers | Requires clean document structure |
| Semantic chunks | Topic-based passages | More complex and harder to debug |
| Parent-child chunks | Precise retrieval with broader context | More moving parts |
| Sliding overlap | Reducing boundary loss | Can create duplicates and token waste |
| Table-aware chunks | Tables, specs, pricing, policies | Requires parsing quality |
| Code-aware chunks | Technical docs and repositories | Needs language-aware parsing |
| Ticket-summary chunks | Support and CRM records | Requires summarization or normalization |
Fixed-size chunks are fast to implement, but they ignore structure.
Paragraph chunks are better for clean prose, but a paragraph alone may not include the heading or document context needed to interpret it.
Heading-aware chunks are often strong for policies, help centers, and documentation because headings carry meaning. The heading “Refund Exceptions” changes how the following text should be interpreted.
Semantic chunking tries to split by topic. It can improve coherence, but it is harder to inspect and debug because the boundaries may be generated or inferred.
Parent-child retrieval can be useful when small chunks retrieve precisely but larger sections are needed for generation. The system retrieves a small child passage, then supplies the larger parent section to the model. This can improve context completeness but adds complexity.
Sliding overlap reduces the chance that important context is split at a boundary. It can also create duplicate chunks, inflate token usage, and crowd retrieval results with near-duplicates.
Table-aware chunking matters because tables often lose meaning when flattened poorly. A row, heading, footnote, and caption may need to stay together.
The question is not “Which chunker is best?” The question is “Which chunking strategy preserves the evidence this workflow needs?”
How chunk size affects business outcomes
Chunk size affects precision, recall, cost, latency, citation quality, and answer faithfulness.
Small chunks can improve precision because they contain less irrelevant text. They are easier to cite. They can make it clearer which passage supports an answer.
But small chunks can also lose context. A short chunk may mention “approval required” without saying who approves, when approval is required, or which policy section applies.
Large chunks preserve more context. They can include the rule, exception, examples, and definitions. But they also add more irrelevant tokens and may make retrieval less precise. Large chunks can also make citations less useful because the cited passage may contain many unrelated details.
Overlap can help when important information crosses boundaries. But overlap also creates duplicates. If several overlapping chunks appear in the top results, they may crowd out different but important evidence.
Chunking is a tradeoff:
- Precision: Does the retrieved chunk focus on the answer?
- Recall: Does the system retrieve the needed evidence at all?
- Completeness: Does the chunk include enough surrounding context?
- Cost: How many tokens are sent to the model?
- Latency: How much retrieval and generation time does the system add?
- Citation quality: Can the system point to a specific supporting passage?
- Faithfulness: Can the model answer without filling gaps?
The only reliable way to tune these tradeoffs is to test against real queries.
How to handle different business document types
RAG retrieval quality depends heavily on document type.
A help-center article is not a contract. A transcript is not a policy. A product catalog is not a runbook. Each source type needs a retrieval design that matches how users ask questions and how answers should be supported.
Policies
Policies need rules, exceptions, eligibility, dates, regions, and approval requirements. Chunking should keep exceptions with the rules they modify. Metadata should include region, effective date, owner, approval status, and policy type.
Help-center articles
Help articles often work well with heading-aware chunks. Keep troubleshooting steps together with symptoms and product metadata. Public versus internal status matters.
Contracts
Contracts may need clause-level chunks plus metadata such as contract type, jurisdiction, customer segment, version, and whether language is approved fallback or customer-specific negotiated text. Similarity does not mean legal equivalence.
Technical documentation
Technical docs need version metadata. Code snippets should stay with explanatory text. Exact terms, function names, error codes, and product versions may require hybrid search.
PDFs
PDFs can be difficult because extraction quality varies. Headers, footers, columns, tables, and page breaks may create noisy chunks. Do not assume a PDF parser produced clean retrieval units without inspection.
Transcripts
Transcripts often need topic-aware chunking. Speaker turns alone may be too small. Full transcripts may be too large. Summaries or topic segments can work better if they preserve evidence and timestamps.
Tickets and CRM notes
Tickets and CRM notes often include noise. A full conversation may not be the best chunk. A normalized issue summary, resolution, product, customer segment, and tags may improve retrieval.
Tables
Tables need structure. A row without column names is often meaningless. A table chunk should preserve headers, units, footnotes, and surrounding explanation.
The operational point is simple: the document shape should influence the chunking strategy.
Metadata is the control layer for retrieval
If chunking defines the retrieval unit, metadata defines retrieval control.
Metadata is structured information attached to each document or chunk. It tells the system what the chunk is, where it came from, who can see it, when it was updated, what product it applies to, and how it should be filtered or prioritized.
Without metadata, retrieval is mostly similarity. Similarity is not enough for business workflows.
A chunk can be semantically similar but wrong because it is:
- for the wrong product;
- for the wrong region;
- for the wrong language;
- for the wrong customer tier;
- outdated;
- unapproved;
- internal-only;
- from a low-trust source;
- superseded by a newer policy;
- tied to a specific customer rather than general guidance.
Metadata helps the retrieval layer filter and interpret results before the model sees them.
| Metadata field | Why it matters | Example |
|---|---|---|
| source_system | Debugging and ownership | help_center |
| document_id | Traceability and deletion | doc_123 |
| section_heading | Context interpretation | Refund exceptions |
| url_or_record_pointer | Source review and citation | /help/billing/refunds |
| document_type | Filtering by source type | policy |
| product | Product filtering | billing |
| region | Regional policy control | EU |
| language | Language-specific retrieval | en |
| version | Version-specific answers | v3.2 |
| updated_at | Freshness filtering | 2026-04-30 |
| effective_date | Policy validity | 2026-05-01 |
| owner | Source accountability | support_ops |
| approval_status | Source trust | approved |
| permission_group | Access control | support_internal |
| confidentiality_level | Data governance | internal |
| customer_segment | Segment-specific rules | enterprise |
This metadata should be designed before indexing, not bolted on later.
Filtering, permissions, freshness, and source priority
Metadata becomes useful when the retrieval layer uses it.
Filtering
Filters narrow retrieval to eligible content.
If the user asks about the EU refund policy, the system should filter or prioritize EU content. If the question is about Product A, Product B content should not appear just because it is semantically similar. If the assistant is customer-facing, internal-only content should be excluded.
Filtering prevents wrong-but-related documents from entering the context.
Permissions
Permissions should be enforced before retrieved text reaches the model.
If unauthorized text enters the prompt, the model can leak it in the answer. This is especially important for HR, legal, customer records, internal support notes, executive docs, and tenant-specific data.
Permission metadata should be attached to each retrievable unit. The retriever should filter by user role, group, tenant, account, or access policy before context assembly.
Freshness
Freshness matters because old and new documents are often semantically similar.
A refund policy from last year may retrieve just as well as the current policy. Without updated_at, effective_date, approval_status, and version metadata, the system cannot reliably prefer current sources.
Source priority
Some sources are more authoritative than others.
An approved policy should outrank an old Slack message. A public help article may be safer for a customer-facing answer than an internal troubleshooting note. A legal playbook may be more authoritative than prior negotiated language from a specific customer deal.
Source priority should be explicit. Do not expect vector similarity to infer authority.
Retrieval quality levers: keyword, vector, hybrid, reranking, and top-k
RAG retrieval quality is not controlled by chunking and metadata alone. The search method matters too.
Keyword search
Keyword search is strong for exact terms, IDs, product names, legal phrases, error codes, acronyms, and version numbers.
If a user asks about “SAML 403 after Okta login,” exact terms matter. A pure vector search may retrieve general login articles because they are semantically related but miss the specific issue.
Vector search
Vector search is strong for semantic similarity. It can match “change who gets invoices” with “update billing contact email.”
This is useful when users do not know the exact terminology.
Hybrid search
Hybrid search combines exact-term relevance and semantic similarity. It is often better for business RAG because business questions usually contain both fuzzy meaning and exact constraints.
For example, “EU enterprise refund policy” contains semantic intent, a region, a customer segment, and a policy type. A hybrid retrieval system can preserve exact terms while still finding related passages.
Reranking
Reranking takes initial candidates and reorders them with a stronger relevance signal. It can improve final context quality, especially when many candidates are plausible.
Reranking adds latency and sometimes cost, so it should be justified by evaluation.
Query rewriting and multi-query retrieval
Some systems rewrite user questions or generate multiple search queries to improve retrieval. This can help when user wording is vague. It can also introduce complexity and retrieval drift if poorly controlled.
Top-k tuning
Top-k is the number of results returned.
More is not always better.
Returning more chunks can improve recall, but it can also add irrelevant context, increase token cost, slow generation, and confuse the model. Returning fewer chunks can improve focus, but it may miss the answer.
Top-k should be tuned against retrieval evaluation, not guessed.
How retrieval failures become bad generated answers
Retrieval failures often look like model failures because the user only sees the final answer.
But the root cause may be earlier.
A policy assistant says contractors can expense monitors. The model looks wrong. The real issue is that the retrieved chunk contained the employee rule but not the contractor exception.
A support copilot recommends the wrong fix. The model looks careless. The real issue is that product metadata was missing, so the retriever found a similar article for another product.
A documentation assistant gives outdated API instructions. The model looks stale. The real issue is that version metadata was missing, so old docs competed with current docs.
A customer-facing assistant exposes internal troubleshooting notes. The model looks unsafe. The real issue is permission filtering failed before generation.
A contract assistant cites prior negotiated language as if it were approved fallback. The model looks overconfident. The real issue is that source type and approval metadata were not distinguished.
This is why retrieval and generation must be evaluated separately.
Do not ask only, “Was the answer good?”
Ask:
- Did retrieval find the right source?
- Did it retrieve the right passage?
- Was the passage current?
- Was it authorized?
- Was it complete?
- Did irrelevant context crowd out useful context?
- Did the answer actually follow the retrieved evidence?
How to evaluate retrieval separately from generation
A RAG system needs retrieval evaluation before answer evaluation.
Retrieval evaluation asks whether the system found the right evidence.
Generation evaluation asks whether the model used that evidence correctly.
Both matter, but retrieval comes first.
A useful retrieval evaluation set includes:
- user query;
- expected source document;
- expected passage or section;
- required metadata filters;
- allowed source types;
- retrieved top-k results;
- relevance judgment;
- failure category;
- suggested fix.
Example:
| Query | Expected source | Retrieved top-k | Relevance judgment | Failure category | Fix |
|---|---|---|---|---|---|
| Can contractors expense monitors? | Remote-work equipment policy exception | Remote-work overview | Partial | Chunk boundary missed exception | Merge rule and exception |
| EU refund policy for enterprise customers | EU enterprise refund policy | US refund policy | Bad | Missing region filter | Add region metadata |
| SAML 403 after Okta login | SSO troubleshooting guide | General login article | Partial | Exact term missed | Add hybrid search |
| Is this fallback clause approved? | Legal fallback playbook | Prior customer contract | Bad | Source priority failure | Add approval_status and source_type |
| How do I update invoice recipients? | Billing contact settings | Billing contact settings | Good | None | Keep |
Common retrieval metrics include:
- top-k hit rate;
- recall@k;
- precision@k;
- mean reciprocal rank;
- nDCG where appropriate;
- human relevance score;
- stale-result rate;
- permission-filter success;
- duplicate-result rate;
- answer support rate;
- citation support rate;
- retrieval latency.
Do not overcomplicate the first version. A spreadsheet with 50 realistic queries and human-reviewed expected sources can expose more retrieval problems than weeks of prompt tuning.
Minimal Python example: retrieval top-k hit rate
The following example is illustrative. It does not call an AI provider and is not presented as executed output. It shows how to score whether expected source IDs appear in retrieved top-k results.
from dataclasses import dataclass
from typing import Dict, List
@dataclass
class RetrievalTestCase:
query_id: str
query: str
expected_source_ids: List[str]
@dataclass
class RetrievedResult:
query_id: str
source_id: str
rank: int
failure_category: str | None = None
test_cases = [
RetrievalTestCase(
query_id="Q001",
query="Can contractors expense monitors?",
expected_source_ids=["policy_remote_equipment_exception"],
),
RetrievalTestCase(
query_id="Q002",
query="EU refund policy for enterprise customers",
expected_source_ids=["policy_eu_enterprise_refunds"],
),
RetrievalTestCase(
query_id="Q003",
query="SAML 403 after Okta login",
expected_source_ids=["doc_sso_okta_403"],
),
]
retrieved_results = [
RetrievedResult(
"Q001",
"policy_remote_equipment_overview",
1,
"chunk_boundary",
),
RetrievedResult(
"Q001",
"policy_remote_equipment_exception",
2,
None,
),
RetrievedResult(
"Q002",
"policy_us_refunds",
1,
"missing_region_filter",
),
RetrievedResult(
"Q002",
"billing_faq_refunds",
2,
"weak_metadata",
),
RetrievedResult(
"Q003",
"doc_general_login",
1,
"exact_term_missed",
),
RetrievedResult(
"Q003",
"doc_sso_okta_403",
2,
None,
),
]
def top_k_hit_rate(
tests: List[RetrievalTestCase],
results: List[RetrievedResult],
k: int,
) -> Dict[str, float]:
results_by_query: Dict[str, List[RetrievedResult]] = {}
for result in results:
results_by_query.setdefault(result.query_id, []).append(result)
hits = 0
for test in tests:
ranked = sorted(
results_by_query.get(test.query_id, []),
key=lambda item: item.rank,
)
top_k_source_ids = {
result.source_id
for result in ranked
if result.rank <= k
}
if any(
expected_id in top_k_source_ids
for expected_id in test.expected_source_ids
):
hits += 1
return {
"k": k,
"total_queries": len(tests),
"hits": hits,
"hit_rate": hits / len(tests) if tests else 0,
}
print(top_k_hit_rate(test_cases, retrieved_results, k=1))
print(top_k_hit_rate(test_cases, retrieved_results, k=3))This example measures only whether the expected source appears in the top-k results. A real evaluation should also review passage quality, source freshness, permissions, duplicates, ranking position, and whether the generated answer is actually supported.
The point is the habit: retrieval quality should be measured with explicit test cases.
How to debug retrieval failures
When RAG gives a bad answer, debug in order.
First, inspect the retrieved sources. Did the expected source appear in the top results? If not, the problem is retrieval, not generation.
Second, inspect the chunk. Did it contain the answer? Did it include the exception, definition, table header, or version note? If not, the problem may be chunking.
Third, inspect metadata. Did filters apply correctly? Was product, region, language, version, approval status, or permission group missing?
Fourth, inspect ranking. Did the correct source appear too low? Did duplicate chunks crowd out better results? Did exact terms get ignored?
Fifth, inspect context assembly. Was the retrieved evidence actually passed to the model? Was it placed clearly with source IDs and headings?
Sixth, inspect generation. Did the model ignore evidence, overgeneralize, or cite a source that did not support the claim?
This order matters. If you jump straight to prompt tuning, you may hide the real problem.
Common fixes include:
- adjust chunk boundaries;
- merge rules with exceptions;
- add heading context;
- improve PDF extraction;
- add metadata fields;
- enforce permission filters;
- add freshness filters;
- deduplicate chunks;
- use hybrid search;
- add reranking;
- tune top-k;
- create source priority rules;
- improve context assembly;
- add refusal rules when evidence is insufficient.
A good retrieval system is debuggable. You should be able to explain why a result appeared and what fix is needed when it should not have.
How chunking and metadata connect to cost control
Retrieval quality is also cost control.
Poor retrieval wastes tokens. Oversized chunks send irrelevant text into the prompt. Missing metadata causes the system to retrieve broad candidate sets. Duplicate chunks crowd context. Weak filtering increases reranking cost. Too many top-k results increase input tokens and latency.
Better retrieval means fewer wasted tokens and better answers.
This is why “just use a larger context window” is not a retrieval strategy. Larger context windows can be useful, but they also make it easier to hide poor retrieval. Sending more text may increase cost and still fail if the right evidence is missing or buried.
The goal is not less context at all costs. The goal is better context per token.
A compact, current, authorized, highly relevant passage is usually more valuable than ten broad chunks that might contain the answer somewhere.
When not to over-engineer retrieval
Not every workflow needs an elaborate retrieval system.
If the dataset is small, a simple keyword search may be enough. If the question requires exact lookup, use a database query. If the content is structured, filters may matter more than embeddings. If the use case is low risk and internal, a simple first version may be appropriate.
Over-engineering can create its own problems: more latency, more moving parts, harder debugging, more infrastructure, and higher maintenance cost.
Start with the simplest retrieval design that can meet the quality bar.
Use more complex chunking, hybrid search, reranking, parent-child retrieval, query rewriting, and feedback loops when evaluation shows they are needed.
The right standard is not architectural sophistication. The right standard is measured retrieval performance for the business task.
Practical retrieval-quality checklist
Use this checklist before trusting a RAG system in production:
- Source inventory: Which documents are indexed?
- Source ownership: Who maintains each source?
- Source trust: Which sources are approved?
- Document cleaning: What noise, duplicates, and stale content are removed?
- Chunking strategy: What is the retrieval unit?
- Chunk inspection: Do chunks preserve rules, exceptions, headings, and evidence?
- Metadata schema: Which fields support filtering and governance?
- Permission model: How is access enforced at retrieval time?
- Freshness model: How are updated and effective dates handled?
- Deletion process: How are removed documents deleted from the index?
- Versioning: How are old and new versions distinguished?
- Hybrid search decision: Are exact terms important?
- Reranking decision: Is second-stage ranking needed?
- Top-k tuning: How many results are useful without adding noise?
- Deduplication: Are near-duplicate chunks suppressed?
- Source priority: Which sources outrank others?
- Evaluation set: Which queries test the retriever?
- Retrieval logs: Are query, filters, sources, ranks, and scores logged?
- Answer support checks: Are generated answers supported by retrieved evidence?
- Human review loop: Who reviews failures?
- Monitoring: How are drift, stale results, and permission failures detected?
This checklist is not bureaucracy. It is how teams move from a RAG demo to a trustworthy retrieval system.
Conclusion: better RAG starts before generation
RAG systems do not fail only because models hallucinate. They often fail because the model receives bad context.
Bad chunks, missing metadata, weak filters, stale documents, duplicate content, wrong permissions, poor ranking, and unmeasured retrieval quality all create failures before generation starts.
That is why RAG retrieval quality deserves serious design attention.
A reliable RAG system starts with clean sources, meaningful chunks, useful metadata, permission-aware filtering, source freshness, hybrid retrieval where needed, reranking where justified, and evaluation that measures retrieval separately from generation.
The model still matters. Prompting still matters. Evaluation of final answers still matters.
But better RAG starts before the model writes a word.
Key Takeaways
- RAG retrieval quality determines whether the model receives useful evidence or misleading context.
- Chunking is not just splitting text by token count. It is choosing the unit of retrieval.
- There is no universal best chunk size. The right chunk depends on document type, query type, and answer requirements.
- Metadata is the control layer for filtering, permissions, freshness, source priority, debugging, and governance.
- Vector similarity alone is not enough for reliable business RAG.
- Hybrid search is often useful when exact terms, IDs, product names, legal phrases, or acronyms matter.
- Top-k is not “more is better.” Too many chunks can add noise, cost, and latency.
- Retrieval should be evaluated separately from generation.
- Many bad RAG answers are retrieval failures wearing a generation mask.
Practical Exercise
Objective:
Design and evaluate the retrieval layer for one RAG workflow.
Task:
Choose one business use case:
- internal policy assistant;
- support knowledge assistant;
- technical documentation Q&A;
- contract review support;
- customer-facing help assistant;
- product feedback clustering;
- sales enablement assistant;
- operations runbook assistant.
Create a retrieval-quality plan with the following sections.
- Source inventory
List the content that will be indexed.
Examples:
- help-center articles;
- internal policies;
- technical documentation;
- contracts;
- runbooks;
- CRM notes;
- support tickets;
- approved sales playbooks.
- Chunking strategy
Choose a chunking strategy and explain why.
Options:
- fixed-size chunks;
- paragraph chunks;
- heading-aware chunks;
- semantic chunks;
- parent-child chunks;
- sliding overlap;
- table-aware chunks;
- code-aware chunks.
- Metadata schema
Define required metadata fields.
Suggested fields:
- source_system;
- document_id;
- title;
- section_heading;
- document_type;
- product;
- region;
- language;
- version;
- updated_at;
- effective_date;
- owner;
- approval_status;
- permission_group;
- confidentiality_level.
- Retrieval method
Choose the retrieval method:
- keyword search;
- vector search;
- hybrid search;
- metadata-filtered search;
- reranked retrieval.
Explain why.
- Evaluation set
Create 20 realistic user queries. For each query, define:
- expected source;
- expected passage;
- required metadata filters;
- unacceptable source;
- failure category if retrieval fails.
- Failure debugging
For each failed query, classify the failure:
- bad chunk boundary;
- missing metadata;
- stale source;
- permission failure;
- exact term missed;
- semantically similar but wrong;
- duplicate chunks;
- source priority problem;
- top-k too low;
- top-k too noisy.
What success looks like:
A successful result is a retrieval plan that clearly defines the source inventory, chunking strategy, metadata schema, retrieval method, evaluation set, and debugging process. The plan should make it possible to test whether the system retrieves the right evidence before measuring generated answers.
Stretch goal:
Build a small spreadsheet with 20 test queries and manually score top-3 retrieval results for each query. Track hit rate, failure category, and recommended fix. Then revise either chunking, metadata, or retrieval method and run the same test again.
FAQ
What is RAG retrieval quality?
RAG retrieval quality measures whether a retrieval-augmented generation system finds relevant, current, authorized, and useful evidence before the model generates an answer.
Why does chunking matter in RAG?
Chunking determines what pieces of source content can be retrieved. Bad chunking can separate rules from exceptions, headings from sections, tables from explanations, or code from context.
Is there a best chunk size for RAG?
No. There is no universal best chunk size. The right size depends on document type, user questions, retrieval method, context requirements, cost, latency, and evaluation results.
Does chunk overlap always improve retrieval?
No. Overlap can reduce boundary loss, but it can also create duplicate chunks, increase token usage, and crowd out better results.
What metadata matters most for RAG?
Commonly useful metadata includes source system, document ID, title, section heading, product, region, language, version, updated date, approval status, permission group, owner, and confidentiality level.
Why is metadata important for retrieval quality?
Metadata lets the system filter by product, region, version, permissions, approval status, freshness, and source type. Similarity alone cannot enforce those business constraints.
Is vector search enough for reliable RAG?
Not always. Vector search is useful for semantic similarity, but business workflows often need keyword search, metadata filters, hybrid search, reranking, permissions, and freshness controls.
What is top-k in retrieval?
Top-k is the number of retrieved results returned for a query. More results can improve recall, but too many can add noise, cost, latency, and confusion.
How do you evaluate retrieval separately from generation?
Create test queries with expected sources or passages, run retrieval, inspect top-k results, score relevance, classify failures, and only then evaluate whether generated answers are faithful to retrieved evidence.
What is the biggest mistake teams make with RAG retrieval?
The biggest mistake is assuming that if a RAG system returns plausible context, it returned the right context. Retrieval needs explicit evaluation, not vibes.
Sources
- OpenAI File Search Guide: https://developers.openai.com/api/docs/guides/tools-file-search
- OpenAI Assistants File Search Documentation: https://developers.openai.com/api/docs/assistants/tools/file-search
- LangChain Retrieval Documentation: https://docs.langchain.com/oss/python/langchain/retrieval
- LangChain Text Splitter Documentation: https://docs.langchain.com/oss/python/integrations/splitters
- LlamaIndex Metadata Extraction Documentation: https://developers.llamaindex.ai/python/framework/module_guides/indexing/metadata_extraction/
- LlamaIndex Basic Strategies for Chunk Sizes: https://developers.llamaindex.ai/python/framework/optimizing/basic_strategies/basic_strategies/
- Pinecone Metadata Filtering Documentation: https://docs.pinecone.io/guides/search/filter-by-metadata
- Pinecone Semantic Search Documentation: https://docs.pinecone.io/guides/search/semantic-search
- Qdrant Filtering Documentation: https://qdrant.tech/documentation/search/filtering/
- Ragas Metrics Documentation: https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/
- Arize Phoenix RAG Evaluation Documentation: https://arize.com/docs/phoenix/cookbook/evaluation/evaluate-rag
- Evaluation of Retrieval-Augmented Generation: A Survey: https://arxiv.org/html/2405.07437v2
- Lost in the Middle: How Language Models Use Long Contexts: https://aclanthology.org/2024.tacl-1.9/
- NIST AI Risk Management Framework: https://www.nist.gov/itl/ai-risk-management-framework
Related articles from Kyle Beyke
- AI Workflow Anatomy: Essential Guide for Business: https://beykeworkflows.com/ai-workflow-anatomy-business-guide/
- How LLMs Work: Essential Guide for Builders: https://beykeworkflows.com/how-llms-work-builders-guide/
- Production Prompting: Essential Business AI Guide: https://beykeworkflows.com/production-prompting-business-ai-guide/
- LLM Integration: 7 Best Python Patterns: https://beykeworkflows.com/llm-integration-python-hugging-face-inference/
- 7 Ways Context Windows Still Break Modern LLMs: https://beykeworkflows.com/llm-context-window-hallucination-memory-limitations/
