Skip to content

Chunking and metadata design

How to split documents so retrieved passages remain useful, and which metadata to keep.

6 MIN READUPDATED 2026-11-18RAG & knowledge
ORIGINAL DIAGRAM · 4 STEPS1Parse structure first: …2Split on semantic bound…3Attach title, path, ver…4Store a stable chunk

Original flow diagram from note steps — not a copied image

§ 01Key concepts
ChunkA passage of text stored and retrieved as one unit.
OverlapRepeated text between chunks to avoid cutting a thought in half.
Metadata filterA constraint such as product, language or date applied at query time.
§ 02When to use
  • Documents have headings, tables or mixed formats.
  • Users filter by date, product, region or permission.
  • Citations must point back to an exact location.
§ 03How it works
  1. 01Parse structure first: headings, tables, lists.
  2. 02Split on semantic boundaries rather than fixed character counts.
  3. 03Attach title, path, version, date and access scope to every chunk.
  4. 04Store a stable chunk ID and test retrieval on real queries.
§ 04Use cases & scenarios

Product manual with tables and versions

Context
A billing manual contains tables, headings and several revisions.
Problem
Plain-text splitting turns tables into gibberish and loses the section context.
Approach
Parse structure first, keep tables intact and store title, path and version with each chunk.
Outcome
Retrieved passages remain readable and cite the exact section and version.

Multi-tenant knowledge base

Context
Several customer tenants share one document index.
Problem
A search for one tenant can surface another tenant's policies.
Approach
Attach tenant and access scope to every chunk and filter at query time.
Outcome
No cross-tenant leakage and simpler permission audits.
§ 05Examples

Chunk a product manual

json
{
  "id": "manual-v4-billing-02",
  "title": "Lease billing guide",
  "section_path": "Billing > Refunds",
  "version": "v4",
  "effective_from": "2026-10-01",
  "access_scope": ["support", "billing"],
  "text": "Billing > Refunds: A security deposit is returned within 14 days..."
}

Put the section heading inside the chunk text and give each chunk a stable, versioned ID for citations.

Filter at query time

sql
SELECT id, content FROM chunks
WHERE tenant_id = :tenant
  AND product = :product
  AND access_scope && :caller_scopes
ORDER BY embedding <=> :query_vector LIMIT 8;

Never mix access levels in one chunk; permissions must be enforceable with a filter at retrieval time.

§ 06Trade-offs

Fixed-size chunks

Up: Simple and predictable

Down: Breaks sentences and tables

Semantic chunks

Up: Better coherence

Down: Needs more parsing logic

Heavy metadata

Up: Precise filtering

Down: More storage and index complexity

§ 07Implementation checklist
  • Keep tables intact where possible.
  • Include the section heading in each chunk's text.
  • Never mix access levels in one chunk.
  • Version chunk IDs when source content changes.
§ 08Configuration reference
KeyTypical valueNote
chunk_overlap10–15%Enough to preserve context.
min_chunk_size100 tokensAvoid tiny, useless passages.
metadata_fieldsexplicit schemaValidate on ingest.
§ 09Troubleshooting
SymptomCauseFix
Tables retrieved as gibberishPlain-text parsingUse a structure-aware parser.
Cross-tenant resultsMissing access metadataApply permission filters at query time.
§ 10Frequently asked questions

What chunk size is best?

It depends on document structure. Start around 300–800 tokens and measure retrieval recall on real queries.

Should chunks overlap?

A small overlap helps, but excessive overlap duplicates content and skews ranking.

More in RAG & knowledge