Skip to content
Ahmad Raza
Menu
All posts

5 min read

Chunking Product Docs So Agents Stop Inventing Specs

When an agent invents a battery life or a fabric blend, the problem is usually how the docs were chunked. Chunk by SKU and spec, attach metadata, and test with hard questions.

Chunking Product Docs So Agents Stop Inventing Specs
On this page

An agent tells a shopper the 15 inch laptop has 18 hours of battery life. The real number is 11. The 18 came from the 13 inch model, which sat in the same PDF two pages earlier. The model did not hallucinate out of thin air. It read a real number from a real document and attached it to the wrong product.

Most "the agent made up a spec" bugs look like this. The fix is less about the model and more about how product documentation gets split, labelled, and retrieved.

Why fixed size chunking breaks product docs

The default in many RAG tutorials is to split text every 500 or 1,000 tokens with some overlap. That is fine for blog posts. It is bad for spec sheets, for three reasons:

  1. Chunks cross product boundaries. One chunk ends with Model A's dimensions and starts Model B's weight. The retriever returns it for a question about either.
  2. Specs lose their subject. A chunk that says "Battery: 11 hours. Weight: 1.6 kg" without the product name is just floating numbers. The model has to guess who they belong to.
  3. Tables get shredded. Comparison tables split mid row, so a value ends up next to the wrong column header.

The model then does what it is trained to do: produce a fluent, confident answer from whatever context it was handed.

Chunk by product, then by section

Flip the approach. Instead of splitting by length, split by meaning:

  • One product (or variant family) per document. If your source PDF covers five models, break it into five documents before chunking.
  • One section per chunk inside that product. Overview, dimensions, materials, battery and power, compatibility, care, warranty. These usually map to headings already.
  • Repeat the subject in every chunk. Prepend a short header like Product: Aurora 15 Laptop (SKU AUR-15-512). It costs a few tokens and removes the ambiguity completely.

A chunk then reads like this:

Product: Aurora 15 Laptop (SKU AUR-15-512)
Section: Battery and power
Battery: 11 hours mixed use. Charger: 65W USB-C. Fast charge: 50% in 30 minutes.

That chunk cannot be confused with the 13 inch model, even if it ranks first for a vague question.

Turn tables into rows, not text blobs

Comparison tables need special handling. Convert each table into one record per product, where every value carries its own label. "Aurora 13 | 18 h | 1.2 kg" becomes "Aurora 13: battery 18 hours, weight 1.2 kg." Now each row is a self contained fact.

If a spec matters for purchase decisions, consider storing it as structured data too and serving it through a catalog tool. Numbers you can read from a field should not depend on retrieval quality at all. RAG is for the prose around the numbers: what "mixed use" means, how the warranty works, what is in the box.

Metadata that actually helps

Every chunk should carry metadata the retriever and the agent can use:

  • sku and product_handle
  • variant where relevant (size, colour, storage)
  • section (battery, materials, dimensions)
  • source and doc_version
  • market if specs differ by region (plugs, voltages, certifications)

Two uses matter most. First, filtering: when the user is on a product page or names a product, filter retrieval to that SKU before ranking. This alone kills most cross product mixups. Second, citation: tell the agent to mention which product and section each spec came from. If it cannot cite one, it should say it does not have that detail.

Tell the agent what to do when the spec is missing

A lot of invented specs happen because the right chunk simply does not exist. The user asks about waterproof rating, the docs never mention it, and the model fills the gap with something plausible.

Add an explicit rule to the system prompt:

Only state a specification if it appears in the retrieved context for that exact product. If it is missing, say you do not have that detail and offer to connect the shopper with support.

Then check that rule in testing, because prompts alone are not a guarantee.

Build a hard question test set

You cannot judge chunking by reading chunks. You judge it by asking questions that are designed to trip it. Write 30 to 50 questions in these buckets:

  • Sibling confusion. "What is the battery life of the Aurora 15?" when the Aurora 13 has a different number.
  • Missing spec. Ask for a detail that is not in the docs. The right answer is "I don't have that."
  • Variant specific. "Is the large size machine washable?" when care differs by material.
  • Comparison. "Which is lighter, the 13 or the 15?" requires two correct retrievals.
  • Units and regions. "Does it come with a UK plug?"

For each question, record the expected answer and the expected source chunk. Then measure two things separately: did retrieval return the right chunk in the top few results, and did the final answer match? If retrieval is right and the answer is wrong, look at the prompt. If retrieval is wrong, look at chunking and metadata first.

Run this set every time you re-ingest docs or change the chunker. It takes minutes and catches the embarrassing failures before customers do.

A simple ingestion pipeline

Putting it together, an ingestion job for product docs looks like this:

  1. Split source files into one document per product or variant family.
  2. Parse headings into sections; convert tables to labelled rows.
  3. Prepend a product and section header to each chunk.
  4. Attach metadata: SKU, handle, variant, section, version, market.
  5. Embed and store, keeping each product's chunks under its SKU.
  6. Run the hard question test set and block deploy if accuracy drops.

None of this is exotic. It is mostly careful parsing. But it is the difference between an agent that sounds smart and one that is actually right about the thing someone is about to buy.

Where to go from here

If your store assistant keeps confusing products, start with one category. Rechunk it by SKU and section, add metadata filters, and write twenty hard questions. You will see the difference quickly.

I help ecommerce teams build agents and RAG pipelines on Next.js and Shopify that stay grounded in real product data. If you want a second pair of eyes on your setup, get in touch through my contact page or at ahmadraza365pro@gmail.com.

  • 5 min read

    A 30-Day Agentic Commerce Rollout for a Next.js Store

    A practical, week by week plan to make a Next.js store ready for AI shopping agents: clean the data, ship a read only catalog MCP server, add carts, hand off to confirmed checkout, then log and cap everything.

  • 5 min read

    Fraud and Abuse When Agents Shop Your Checkout

    AI shopping agents look a lot like bots, and bots look a lot like agents. Here is how to tell them apart, where to put bot challenges, and why hosted checkout like Shop Pay is your best trust boundary.

  • 4 min read

    Hydrogen SDK vs Calling Storefront API Yourself in 2026

    Shopify's Hydrogen SDK now reaches beyond Remix and React Router into other frameworks. Here is what it gives you for agent ready storefronts, what a thin Next.js client gives you, and when each one pays off.