Naive fixed-token chunking breaks code blocks, tables, and section hierarchies—causing retrieval systems to return incomplete syntax or orphaned table rows.
Structure-Aware Chunking
Split Markdown and technical documents along semantic boundaries first:
- Heading Hierarchy Preservation: Prepend parent heading breadcrumbs (
# Guide > ## Authentication > ### Token Refresh) to every chunk so context survives isolation. - Atomic Code & Table Blocks: Never split inside fenced code blocks (
`` `) or Markdown tables. - Metadata Attachment: Store
source_path,section_anchor, andlast_modifiedalongside embeddings for exact citation links.
Hybrid Retrieval Scoring
Technical queries often contain exact identifiers (error codes, function names, CLI flags) where pure vector similarity underperforms lexical search. Combine both using Reciprocal Rank Fusion (RRF):
\[\text{RRF}(d) = \sum_{r \in R} \frac{1}{k + \text{rank}_r(d)}\]Where $k = 60$ dampens outlier rankings from either the BM25 keyword index or the dense embedding index.
#rag
#search
#ai-engineering