Metadata Design
Metadata is the control plane of RAG. It tells the system what a chunk is, where it came from, who can see it, which version it belongs to, when it expires, and whether it is authoritative enough to answer from.
How to read this chapter
- Read it as product control: metadata is not decoration; it decides retrieval filters, citations, access control, freshness, and evaluation slices.
- Design before indexing: retrofitting metadata after a corpus is already embedded is painful and expensive.
- Think schema and governance: every field needs a purpose, owner, allowed values, default behavior, and failure rule.
- Keep production in view: wrong metadata can hide the right answer or expose the wrong source.
Why Metadata Matters
- Metadata controls filtering, ranking, citations, permissions, freshness, and debugging.
- Without metadata, retrieval becomes similarity-only, which is not enough for production decisions.
- Metadata schema design should happen before chunking and indexing.
Imagine a user asks, "Can a contractor access customer logs during a Sev1 incident in Germany?" The answer depends on role, region, incident severity, document authority, policy version, approval owner, and access boundary. Those are metadata questions before they are language questions.
If metadata is weak, the system may retrieve a similar but wrong document. If metadata is strong, the system can filter, rank, cite, and refuse with much better control.
If a field does not improve retrieval, safety, freshness, citations, evaluation, or operations, it may be noise. If a field controls user trust, it must be required and validated.
Region, role, product, policy status, source authority, customer tier, document type, language, or time period.
Source URI, section, page, row, table, heading path, version, timestamp, and owner.
Tenant, access level, sensitivity, role, entitlement, allowed audience, and redaction status.
Freshness, parser version, index version, schema version, approval status, retired status, and metadata completeness.
Real-Life Analogy: A Passport for Every Chunk
A passport does not contain your whole life story. It contains structured facts that let systems make decisions: name, country, date of birth, document number, issue date, expiry date, and authority.
Metadata is the passport for a chunk. It tells the retrieval system: where this chunk came from, what it belongs to, who can use it, whether it is expired, and how to cite it.
- Text carries meaning.
- Metadata carries control.
- Production RAG needs both.
Technical Explanation: Metadata Schema
A metadata schema defines the fields every source or chunk must carry. The schema should be boring, explicit, and tested. Boring is good here. Boring means the system behaves predictably.
Example chunk metadata contract
{
"source_id": "customer_data_access_policy",
"chunk_id": "customer_data_access_policy:p4:s2:c3",
"source_uri": "policies/customer-data-access.md",
"document_type": "policy",
"section": "Emergency access",
"heading_path": ["Security", "Customer data", "Emergency access"],
"authority": "approved",
"owner": "Security Governance",
"access_level": "restricted",
"allowed_roles": ["security", "incident_commander"],
"region": "EU",
"policy_id": "SEC-CUST-042",
"version": "2026.1",
"effective_from": "2026-01-15",
"expires_at": "2027-01-15",
"parser_version": "pdf-parser-3.2",
"schema_version": "rag-metadata-v1"
}Identity fields
Source id, chunk id, parent id, source URI, section, page, row, and heading path let the system trace evidence.
Control fields
Access level, allowed roles, tenant, region, authority, status, sensitivity, and redaction state protect users and data.
Lifecycle fields
Version, effective date, expiry date, parser version, index version, owner, and refresh rule keep answers current.
Metadata Field Families
Do not design fields randomly. Group them by the job they perform.
Authority and status
Access and sensitivity
Version and time
Business context
Pipeline lineage
Access and Safety Metadata
Access metadata is not optional. It decides whether content is allowed to enter retrieval results for a specific user.
Security access question
User: support contractor in Germany. Question: "Can I view customer logs during Sev1?"
- Needed filters: role=contractor, region=EU, incident_severity=sev1, source_authority=approved.
- Needed permissions: only retrieve policies visible to support contractors.
- Needed refusal: if restricted security policy is required but not visible, explain that escalation is needed instead of leaking details.
The lesson: access control must happen before generation, not after the answer is written.
Permissions can change the correct answer
The right answer for a security engineer may not be the right answer for a contractor because source visibility and allowed actions differ.
Roles need stable vocabulary
If one source says "contractor" and another says "vendor," filters may miss unless the schema normalizes roles.
Do not retrieve what the user cannot see
UI hiding is not enough. Permission filters must apply at retrieval time.
Record why a source was blocked
Blocked source ids and reasons help teams debug refusals without exposing restricted content.
Versioning, Freshness, and Time-Aware Retrieval
Many production questions are time-sensitive. "What is the policy?" often really means "What is the approved policy for this user, region, product, and date?"
Freshness decision flow
Question has time constraint?
-> apply effective_from / expires_at filters
-> prefer approved current version
-> include historical source only if user asks for history
-> refuse or escalate when current source is missingProduction failure mode
A policy changed last month, but old chunks still outrank new chunks because both are semantically similar and the old version has more links.
Engineering checklist
- Store version and effective dates.
- Mark retired content clearly.
- Keep index version and ingestion run id.
- Test historical and current questions separately.
Metrics to watch
stale-source rate, current-version recall, retired-source retrieval rate, metadata completeness, and freshness SLA violations.
Architecture View
Metadata in the RAG pipeline
Parsed document
-> metadata extraction
-> schema validation
-> enrichment and normalization
-> permission classification
-> index with metadata
-> filter retrieval by user and question
-> cite with source metadataProduction Controls
- Metadata dictionary: define each field, type, allowed values, owner, default, and whether it is required.
- Schema validation: block indexing when required fields are missing or malformed.
- Controlled vocabularies: normalize roles, regions, document types, authority, and access levels.
- Permission filters: enforce tenant, role, region, and sensitivity before context assembly.
- Freshness rules: expire, review, or downgrade stale sources.
- Evaluation slices: measure answer quality by region, role, source type, policy version, and metadata completeness.
Metadata completeness before indexing
Do not let chunks enter the index without required identity, access, authority, and lifecycle fields.
Track filter effectiveness
Watch how often filters remove sources, hide all results, or route users to refusal. These are product signals, not just logs.
Test metadata-specific questions
Create golden questions that differ only by role, region, date, or product version. These catch filter mistakes quickly.
Metadata fields need owners
If no team owns a field, its values will drift. Metadata quality is an operating responsibility.
Common Mistakes
Metadata mistakes are dangerous because the system may still retrieve fluent, plausible evidence while ignoring real-world constraints.
Treating metadata as optional labels
Using free-text values for controlled fields
Forgetting source authority
Ignoring access metadata
Not versioning metadata schemas
Dropping section and page information
Using timestamps without semantics
Overloading one field with many meanings
Not measuring metadata quality
Letting metadata drift after launch
Mini Assignment
Design metadata for one assistant domain: HR policy, security runbook, customer support, developer docs, or finance policy. Include identity fields, access fields, lifecycle fields, business-context fields, required/optional status, allowed values, and one validation rule for each required field.
Points To Remember
- Metadata is the control plane for RAG retrieval.
- Similarity is not enough; filters need structured fields.
- Access, authority, version, region, and source position should be designed before indexing.
- Metadata schemas need validation, controlled values, owners, and versioning.
- Good metadata improves retrieval, citations, safety, evaluation, and operations.
Next, test metadata judgment in the quiz, then build a metadata schema validator in exercises and the project.