TrolyPage

An autonomous Marketing & Sales operating system for businesses that want AI-powered omni-channel growth.

Contact Info

Follow Us

12 min read

What Are Chunking & Embeddings in RAG? How Splitting Documents Determines Chatbot Answer Accuracy

TrolyPage

Dec 02, 2026
10 views
Isometric 3D editorial illustration of translucent sapphire and violet glass document cards arranged along glowing amber coordinate grid lines on a pale alabaster and ice-blue background.

Chunking and embeddings in RAG are the two preprocessing mechanics that decide whether an AI chatbot retrieves exact answers or guesses. Chunking splits long price lists and policies into focused passages, while embeddings convert those passages into numerical vectors so retrieval engines can match customer phrasing by meaning before generating a reply.

Editorial disclosure: Published by TrolyPage, one of the platforms referenced in the "Putting It Into Practice" section below. Over 90% of this explainer covers vendor-neutral retrieval engineering grounded in official documentation from Anthropic, OpenAI, Google Cloud, LangChain, and peer-reviewed research.

Why Identical Chatbots Give Wildly Different Answers From the Same PDF

Consider a direct-to-consumer kitchenware retailer launching an AI support assistant across web chat and Messenger. The operations manager uploads a crisp 40-page catalog PDF containing 180 SKUs, tiered wholesale discounts, and warranty rules. On launch morning, a customer types: "My ceramic kettle cracked out of the box—what is the replacement window for SKU-409B?" The assistant replies confidently with the wrong warranty period for a coffee grinder, or quotes a discounted tier price without mentioning the 10-unit minimum.

When teams hit that bug, they usually blame the underlying language model and swap to a more expensive model tier. Yet in Retrieval-Augmented Generation (RAG), the model is only as accurate as the text slices handed to it at runtime. As Google Cloud's RAG Engine documentation outlines, every RAG system runs a multi-stage pipeline before the chat model ever writes a word: data ingestion, transformation into chunks, numerical embedding, corpus indexing, runtime retrieval, and finally grounded generation.

If the ingestion stage slices a pricing table horizontally across two chunks, or strips the section heading "Warranty Exceptions > Ceramic Kettles" off a paragraph, the retrieval engine pulls orphaned fragments into the prompt. No matter how capable the language model is, it cannot reason reliably over half a table row.

Founders and non-engineering leads often treat chunking, embeddings, and vector search as a single mysterious black box. In reality, each component performs a distinct job, and mixing them up leads teams to tune the wrong dial when answers go stale or miss exact product codes.

Three-column 5-Minute Decoder diagram showing Structure-Aware Chunking (300 to 600 tokens with header injection and intact rows), Dense Embedding Model (1,536-float semantic coordinate cluster), and Hybrid Vector plus BM25 Index fusing semantic similarity and exact SKU-409B matches.
Figure 1: Structure-aware chunking preserves headers and table rows, dense embeddings map paraphrased meaning into semantic coordinates, and hybrid vector plus BM25 indexing fuses conceptual similarity with exact SKU matching.
RAG Component Plain-English Definition When It Runs Primary Input & Output Common Failure When Misconfigured
Chunking Splitting source documents into self-contained passages sized for focused retrieval. Offline during document ingestion or URL re-crawls. Raw PDF, spreadsheet, or webpage text → discrete text chunks (typically 300–600 tokens). Severs table rows from column headers or divorces policy exceptions from parent rules.
Embeddings A neural model that translates text into a fixed list of floating-point numbers encoding semantic meaning. Offline for every chunk, and live at runtime for each incoming customer question. Text string → dense vector (for example, 1,536 or 3,072 numbers). Blurring multiple unrelated topics into a single vector when chunks are too long, or losing exact SKU precision.
Vector Index A specialized database structure that stores chunk vectors and ranks nearest matches by mathematical distance. Populated at ingestion; queried in milliseconds on every customer turn. Query vector + metadata filters → Top-K ranked candidate chunks. Returns conceptually similar neighbors (such as SKU-409A instead of SKU-409B) unless paired with keyword search.

What Embeddings Actually Measure (and Where They Hit a Wall)

According to OpenAI's Vector Embeddings guide, an embedding is a vector of floating-point numbers where the distance between two vectors—commonly measured via cosine similarity—captures semantic relatedness. OpenAI's third-generation text-embedding-3-small outputs 1,536 dimensions by default (supporting up to 8,192 input tokens and roughly 62,500 pages per dollar at ~800 tokens per page), while text-embedding-3-large outputs 3,072 dimensions for higher benchmark discrimination at higher storage and compute cost.

That geometric representation solves a classic help-center headache: vocabulary mismatch. A customer rarely writes the exact words inside your SOP. They ask about a "cracked kettle," while your warranty document says "transit damage on ceramic cookware." Because those phrases occupy nearby coordinates in vector space, semantic search retrieves the right passage even when zero keywords overlap—as illustrated in OpenAI's Retrieval documentation, where "The first lunar landing occurred in July of 1969" scores 65% semantic similarity to a moon query despite 0% word overlap.

The catch is that dense semantic vectors smooth over exact alphanumeric tokens. As Anthropic's Contextual Retrieval research points out, when a user searches for a specific identifier such as error code TS-999—or in retail support, SKU-409B, invoice prefix INV-2026, or promo code FALL15—a pure embedding model often retrieves chunks discussing error codes or kettles in general while missing the exact token.

Retrieval Method How Matching Works Where It Excels Where It Fails Alone
Semantic Vector Search Computes cosine distance between dense embedding coordinates in high-dimensional space. Paraphrased questions, synonyms, intent-based FAQ queries, and cross-lingual phrasing. Exact SKUs, part numbers, error codes, legal clause IDs, and rare proper nouns.
Lexical BM25 Search Scores exact term overlap using term frequency and inverse document frequency (TF-IDF) with length normalization. Exact SKU lookups, serial prefixes, promo codes, and verbatim policy identifiers. Synonyms and casual customer phrasing that share no exact words with the manual.
Hybrid Search (Vector + BM25) Runs both indexes in parallel and merges candidates via Reciprocal Rank Fusion (RRF), optionally followed by a reranker. Production customer support mixing conversational questions with exact product or order identifiers. Adds index complexity; still fails if underlying chunks were sliced mid-row or stripped of headings.

Both OpenAI's Retrieval API (via ranking_options.hybrid_search tuning embedding vs. sparse text weights) and Anthropic's Contextual Retrieval benchmark converge on the same pattern: combining contextualized embeddings with contextual BM25 cut top-20 retrieval failure rates by 49% (from 5.7% down to 2.9%), and adding a reranking pass cut failures by 67% (down to 1.9%).

Chunk-Size Tradeoffs: Naive Splits vs. Oversized Blobs vs. Structure-Aware Chunks

Even with hybrid indexing enabled, your chunking geometry governs retrieval precision and monthly token spend. Most teams fall into one of three chunking designs, and picking either extreme creates immediate operational failure costs.

Dark-mode diagnostic chart plotting Retrieval Precision and Token Load across 128, 450, 1,200, and 2,400 token chunk sizes with a 300 to 600 token sweet spot, paired with callout cards contrasting broken mid-row splits and oversized page dumps against header-preserved chunks.
Figure 2: Chunk-size tradeoffs across 128 to 2,400 tokens showing why 300 to 600 token structure-aware chunks with header injection avoid both severed price rows and diluted, high-cost context blobs.
Chunking Strategy Quantitative Thresholds Root Technical & Economic Mechanism Exact Failure Cost When Chosen Wrong
Option A: Naive Fixed-Character Splitting Fixed 200–500 character cuts with 0% overlap and zero awareness of markdown, rows, or headings. Cuts strictly by character count, severing table cells from column headers and separating "except when..." clauses from the rule above. AI hallucinates prices or attaches the wrong currency/MOQ to a SKU; support agents spend hours correcting bad quotes and honoring unintended discounts.
Option B: Oversized Page-Level Chunks 2,000+ tokens per chunk (or dumping entire multi-section PDFs into single passages). A single embedding vector averages dozens of unrelated topics together, diluting similarity scores; large top-K payloads trigger middle-context attention decay and token bloat. Relevant SKU lines vanish in long prompts (Lost in the Middle), while top-5 retrieval injects 10,000+ context tokens per turn—inflating monthly token bills by 2x–3x.
Option C: Structure-Aware + Header Injection + Hybrid 300–600 tokens per chunk (or managed defaults like 800 max / 400 overlap tuned down for dense tables), 10–15% overlap, intact rows, parent breadcrumbs, and Vector + BM25 retrieval. Aligns vector boundaries with semantic units while preserving hierarchical headings and exact identifier tokens for BM25 matching. If teams skip table-row protection on wide CSVs or forget to re-index after price updates, stale or split rows still surface until caught by pre-live evals.

Look closely at why Option B hurts both accuracy and budget. In Lost in the Middle: How Language Models Use Long Contexts (arXiv:2307.03172), Liu et al. demonstrated that language models retrieve facts most reliably at the very beginning or very end of an input context, while accuracy drops sharply when key details sit buried in the middle of long prompts. Meanwhile, OpenAI's managed vector stores default to 800-token chunks with 400-token overlap (and allow static tuning down to 100 tokens), which works reasonably well for prose manuals but often packs too many catalog rows together unless you enforce smaller 300–600 token structural boundaries for pricing sheets.

How Document Structure and Header Injection Prevent Context Loss

If you inspect LangChain's Text Splitter architecture, splitters fall into three tiers: length-based (strict token or character counts), text structure-based (such as RecursiveCharacterTextSplitter, which tries to keep paragraphs intact before falling back to sentences and words), and document structure-based (splitting explicitly on Markdown headings, HTML tags, or JSON keys).

For business knowledge bases, document structure-based splitting paired with header injection solves the most common retrieval bug: context amnesia. Imagine a 15-page warranty handbook where page 9 reads simply:

"Items showing mineral scale buildup are excluded from free replacement after 14 days."

Embedded in isolation, that chunk never mentions which product category it governs. By prepending the parent heading hierarchy—for example, [Warranty Policy > Electric & Ceramic Kettles > Exclusions]—directly into the chunk text before embedding and BM25 indexing, both the semantic vector and keyword index retain the exact scope. Anthropic's Contextual Retrieval extends this principle further by using a fast model at ingestion time to prepend a concise 1–2 sentence summary locating each chunk within its full source document.

There is also an overlooked prerequisite before chunking even begins: extractable text layers. If a supplier sends your team a scanned image-only PDF price list—where every page is a flattened JPEG inside a PDF wrapper—a standard text parser extracts zero characters, producing zero chunks. Before blaming retrieval settings, open the PDF in a browser and verify you can highlight and copy individual SKU codes with your cursor.

5-Step Pricing-Sheet & Policy Chunking Readiness Checklist

Use this operational checklist before uploading or re-indexing any catalog, spreadsheet, or policy document into a customer-facing RAG assistant:

  1. Confirm an embedded text layer first: Open every PDF and test selecting SKU numbers and prices. If text cannot be selected, export from the original spreadsheet/doc or run external OCR before ingestion—never upload image-only scans expecting text retrieval to work.
  2. Normalize multi-column price tables into clean rows: Remove merged cells, multi-row headers, and decorative footers from spreadsheets. Ensure every row repeats its category or product name, SKU, unit price, currency, and minimum order quantity so no row depends on reading three lines above it.
  3. Write explicit, self-contained headings for every policy section: Replace vague headers like "Exceptions" or "Notes" with scoped titles such as "Ceramic Kettle Warranty Exceptions (30-Day Window)" so header-aware splitters preserve clear context breadcrumbs.
  4. Set target chunk windows around 300–600 tokens with 10–15% overlap for dense SOPs: Avoid 2,000+ token page dumps on mixed-topic handbooks, and keep structured pricing rows intact rather than letting fixed-character splitters cut mid-row.
  5. Run a 10-question adversarial retrieval check before going live: Test five paraphrased intent questions ("cracked pot return") and five exact-code lookups ("SKU-409B price") in pre-live evaluation, confirming the assistant cites the exact row rather than blending neighboring SKUs.

Putting It Into Practice

Inside TrolyPage, you do not have to wire vector databases or BM25 pipelines by hand: the AI agent builder ingests uploaded text documents, spreadsheets, and crawled website URLs (knowledge_web), then lets you inspect grounded answers inside a pre-live evaluation chat before publishing to live channels. Keeping source spreadsheets row-clean and policies under clear headings also protects your monthly token allowance—plans on TrolyPage Pricing estimate roughly 4,000 tokens per support exchange, so bloated retrieved passages consume quota faster than concise, well-structured chunks.

Keep two practical boundaries in mind when preparing files for TrolyPage. First, TrolyPage has no OCR pipeline for image-only scanned PDFs; PDF uploads require embedded text layers (while vision-capable models can interpret attached chat images). Second, automated AI agents run 24/7, while live TrolyPage vendor support operates during Vietnam business hours (UTC+7) and the public TrolyPage Docs portal is currently published in Vietnamese. Always verify updated catalogs in pre-live AI agent evaluation before enabling live auto-replies.

FAQ: Chunking & Embeddings for Operations Teams

Does changing the LLM fix bad chunking?

No. Upgrading to a larger or newer chat model improves reasoning and tone, but it cannot recover a SKU row that was sliced in half during ingestion or never retrieved from the index. Fixing table structure, headings, and hybrid retrieval almost always beats swapping models.

What is the best chunk overlap percentage for support docs?

For narrative SOPs and help articles, 10% to 15% overlap (roughly 50 to 80 tokens on a 450-token chunk) keeps sentences at boundary edges from losing transitional context without inflating storage unnecessarily. For structured spreadsheets or JSON product records, keeping each row or item self-contained with its header breadcrumb matters far more than raw character overlap.

When should a team skip RAG chunking altogether?

As Anthropic's Contextual Retrieval note highlights, if your entire knowledge base is static and well under 200,000 tokens—and your platform supports prompt caching without blowing per-turn latency or token budgets—passing a compact handbook directly in context can work. Once catalogs grow, update frequently, or require strict per-turn token predictability across thousands of chats, clean chunking plus hybrid retrieval becomes essential.

Comments

Your comment will appear after review.

Sign in to comment

No comments to show.