Table of contents :

A Hybrid Parsing and Chunking Architecture

100-days-of-chunking-with-llamaparse-and-undefined-032

Table of contents :

A production retrieval system for WooCommerce rarely has one document type or one parsing strategy. Product manuals may arrive as PDFs, supplier catalogs may contain dense tables, policy pages may be HTML, and order or product data may already be structured JSON. Applying the same parser and chunking rule to every input usually produces either incomplete context or unnecessarily large retrieval units.

A hybrid architecture separates parsing from chunking and chooses the right strategy for each content region. The parser preserves structure, the router identifies the content type, and the chunker creates retrieval units that match how an agency’s support, merchandising, and operations teams ask questions.

Separate the pipeline into distinct stages

A useful architecture has five stages:

  1. Ingestion: Store the original file, URL, product identifier, tenant identifier, and content hash.
  2. Parsing: Convert the source into normalized blocks such as headings, paragraphs, lists, tables, images, and code samples.
  3. Classification: Assign each block a content type and identify boundaries such as product sections, policy clauses, or table groups.
  4. Chunking: Combine compatible blocks into bounded retrieval units while preserving parent-child relationships.
  5. Indexing: Generate embeddings and searchable text while retaining metadata needed for filtering and citation.

This separation matters because parsing errors and chunking errors have different causes. A malformed table should be fixed during parsing; a chunk that contains three unrelated product sections should be fixed during chunking.

Route documents by structure and risk

The first routing decision should be based on the source rather than on a universal token limit. LlamaParse is useful for documents where layout carries meaning, particularly PDFs with headings, columns, tables, lists, and mixed text. A lightweight HTML parser is generally preferable for WooCommerce product pages because the DOM already exposes headings, descriptions, lists, specifications, and links. JSON and database records should normally bypass document parsing altogether.

A practical routing table can look like this:

  • PDF manuals and supplier catalogs: Use a layout-aware parser such as LlamaParse, then normalize the returned elements.
  • HTML product and policy pages: Parse the DOM, remove navigation and promotional elements, and retain semantic elements such as h1, h2, table, and li.
  • CSV price lists: Convert rows into structured records and create row-group or product-level chunks.
  • WooCommerce REST API responses: Map fields directly into typed content blocks rather than flattening JSON into prose.
  • Scanned documents: Use OCR or a layout-aware parser, and record extraction confidence so low-confidence content can be reviewed.

The router should also consider document risk. A warranty clause, installation instruction, or safety warning may require smaller chunks and stronger citation metadata than a general marketing paragraph.

Normalize parser output into a common block model

Different parsers expose different response formats. Before chunking, convert them into a common internal representation. Each block should include its text, type, order, hierarchy, and source location.

{
  "document_id": "manual-4821",
  "blocks": [
    {
      "id": "b17",
      "type": "heading",
      "text": "Installation requirements",
      "level": 2,
      "page": 4,
      "order": 17
    },
    {
      "id": "b18",
      "type": "paragraph",
      "text": "Install the unit on a level surface...",
      "parent_id": "b17",
      "page": 4,
      "order": 18
    },
    {
      "id": "b19",
      "type": "table",
      "caption": "Electrical specifications",
      "headers": ["Model", "Voltage", "Amperage"],
      "rows": [["A200", "230 V", "4.2 A"]],
      "parent_id": "b17",
      "page": 4,
      "order": 19
    }
  ]
}

For WooCommerce work, add business metadata outside the text itself. Useful fields include site_id, product_id, sku, category_ids, language, document_version, source_url, page, and parser_version. This allows retrieval filters to enforce tenant, catalog, language, and product boundaries without relying on the embedding.

Use structure-aware chunking first

Structure-aware chunking should be the default for content with reliable headings or record boundaries. Start a new chunk at a meaningful section boundary, then append compatible paragraphs, lists, and tables until the chunk reaches a target size. Do not split a table merely because the preceding paragraph ended.

For example, a product documentation section can be represented as:

Chunk title: Installation requirements
Content: heading + explanatory paragraphs + installation checklist + electrical specifications table
Metadata: product_id, sku, document_id, page_start, page_end, section_path

The section path, such as Manual > Installation > Electrical requirements, should be included in the chunk text or metadata. It gives an embedding useful context when the body contains pronouns or abbreviated references such as “this unit” or “the adapter.”

Tables need special handling. Preserve headers with every table fragment, repeat the relevant product or model identifier, and serialize rows into readable text as well as structured fields. A row containing only “A200 | 230 V | 4.2 A” is much less useful than “Model: A200; Voltage: 230 V; Amperage: 4.2 A.”

Apply semantic or token-based fallback selectively

Not every parser output has dependable structure. OCR text, long unbroken descriptions, and badly formatted supplier exports may require a fallback chunker. A fallback strategy can split oversized blocks by sentence boundaries, then by token count when necessary. Keep a small overlap only when a concept is likely to cross a boundary; excessive overlap increases index size and can cause duplicate retrieval results.

Use different targets for different content classes. A support article may work well at approximately 300–600 tokens, while a tightly related specification table may need to remain intact even if it is larger. The exact value should be measured against the embedding model, query length, answer-generation context, and retrieval evaluation set rather than selected as a universal constant.

When a block exceeds the maximum size, preserve its parent metadata on every child chunk:

  • Keep the section heading and section path in each child.
  • Assign stable child identifiers such as document_id:section_id:part_02.
  • Record the character or token range for citation and debugging.
  • Use sentence-aware boundaries before applying hard token limits.
  • Mark whether the chunk is a complete section, a table fragment, or a continuation.

Combine parent and child retrieval units

A hybrid index can store small child chunks for accurate retrieval and larger parent sections for answer context. The child chunk supplies the embedding match, while the parent supplies surrounding definitions, prerequisites, or exceptions.

For a WooCommerce agency, a query such as “Can the A200 be installed on a 120 V circuit?” may match a small electrical-specification chunk. The application can then expand that result to the parent installation section, where voltage requirements, grounding instructions, and model limitations are available together.

Parent expansion should be bounded. Retrieve the matched child, its section heading, and a limited number of adjacent blocks instead of loading the entire manual. If the system retrieves multiple children from the same parent, deduplicate them and preserve the highest-scoring evidence first.

Handle WooCommerce content as typed data

Product data should not be treated exactly like a PDF paragraph. Store important fields in metadata and, where useful, create a readable product summary for semantic search. Keep values such as price, stock status, SKU, dimensions, and variation attributes separately queryable.

{
  "content_type": "product",
  "product_id": 913,
  "sku": "A200-BLK",
  "text": "A200 black commercial mixer. Capacity: 12 L. Voltage: 230 V.",
  "attributes": {
    "capacity_l": 12,
    "voltage_v": 230,
    "color": "black"
  },
  "source_url": "https://example.com/product/a200-black"
}

This allows a hybrid query process: semantic retrieval can find products described with different wording, while structured filters can enforce an exact voltage, category, language, or stock condition. Do not depend on generated text to answer volatile questions such as current price or inventory when the authoritative WooCommerce data can be queried directly.

Make parsing and chunking observable

Store parser version, chunker version, source hash, extraction timestamp, token count, block count, and failure status for every document. These fields make reprocessing deterministic and help an agency explain why a client’s answer changed after a catalog update.

Useful automated checks include:

  • Every chunk has a non-empty source identifier and citation location.
  • Every table fragment contains its headers and relevant parent context.
  • No chunk crosses tenant, product, language, or document-version boundaries unless explicitly allowed.
  • Chunk sizes remain within the configured limits, with exceptions recorded.
  • HTML boilerplate, navigation, cookie notices, and duplicated footer text are removed.
  • Product identifiers and numeric specifications survive normalization unchanged.

Build an evaluation set from real agency queries: compatibility questions, installation requirements, product comparisons, warranty lookups, and catalog filters. Compare fixed-size, structure-aware, and hybrid strategies using retrieval recall, citation accuracy, duplicate rate, latency, and index cost. The best architecture is usually not the one with the smallest chunks; it is the one that preserves the evidence needed for a correct answer while keeping retrieval precise.

Trending posts
You might also like