When a WooCommerce document is chunked for search or retrieval, the chunk should not become the only copy of the content. Product specifications, refund policies, tax rules, and implementation notes often need to be displayed in their original context. Recovering the original elements means preserving enough provenance to move from a retrieved chunk back to the parser’s source elements.
Why original elements matter
A chunk is an application-level view of a document. It may combine a heading with several paragraphs, split a table across boundaries, or include text from adjacent sections to improve retrieval. That is useful for embeddings, but it can be problematic when an agency needs to:
- Show the exact source passage behind an answer.
- Link a support response to a page, section, or table.
- Rebuild a product or policy record from structured elements.
- Diagnose why a retrieval result contained irrelevant text.
- Reprocess chunks after changing the chunking strategy without reparsing every file.
The solution is to treat parsed elements as durable source records and chunks as derived records.
Use a two-layer document model
Store the parser output separately from the chunks created for retrieval. A useful model has three layers:
- Document: the source file, tenant, checksum, parser configuration, and ingestion timestamp.
- Element: an original heading, paragraph, list, table, image description, or other parser-level unit.
- Chunk: a retrieval unit containing one or more element references and the text used for embedding.
A simplified element record might look like this:
{
"document_id": "returns-policy-2025",
"element_id": "returns-policy-2025:p3:e07",
"element_type": "paragraph",
"text": "Customers may request a return within 30 days of delivery.",
"page_number": 3,
"section_path": ["Returns", "Eligibility"],
"order": 7
}
The exact fields depend on the LlamaParse response format and the adapter used by the Undefined pipeline. The important properties are stable identifiers, source order, element type, and location metadata. Do not rely on array position alone; a parser update or a page-level change can alter that position.
Assign stable element identifiers
If the parser provides element identifiers, preserve them. If it does not, create deterministic identifiers from the document checksum, page or section location, and source order. For example:
element_id = document_checksum + ":p" + page_number + ":e" + order
Include a parser version and extraction configuration in the document record. If the file is parsed again, compare the new document checksum and parser version before deciding whether an existing element can be reused. This prevents a chunk from silently pointing to content from an older parse.
Build chunks with element references
When a chunk is created, keep both its rendered text and the identifiers of the elements that produced it:
{
"chunk_id": "returns-policy-2025:c014",
"document_id": "returns-policy-2025",
"text": "Returns\nCustomers may request a return within 30 days of delivery.",
"element_ids": [
"returns-policy-2025:p3:e06",
"returns-policy-2025:p3:e07"
],
"start_order": 6,
"end_order": 7,
"embedding_model": "your-embedding-model"
}
This design supports both directions: retrieval can return a chunk, and application code can resolve that chunk back to its original elements. It also lets you regenerate embeddings while keeping the source representation unchanged.
Recover elements after retrieval
At query time, resolve the element references after ranking rather than embedding a large amount of provenance into the searchable text. A recovery function should:
- Load the selected chunk.
- Fetch its element identifiers from the element store.
- Sort the elements by document order.
- Group adjacent elements when they belong to the same section.
- Return the original text and location metadata to the response layer.
For a WooCommerce support assistant, the response can then include the policy section, page number, and a link to the source document. If the source is stored in WordPress media, the recovered metadata can be mapped to a media URL or an internal editorial preview rather than exposing a private file.
Handle tables and lists as structured elements
Tables should not be recovered as unrelated cell fragments if the answer depends on row and column relationships. Preserve the table identifier, headers, row order, and the original representation. A chunk may contain a serialized table for retrieval, while the element record retains structured data for display.
The same principle applies to lists. Keep the list container and item order so that a recovered set of return conditions is rendered as a list instead of an ambiguous sequence of sentences. For product catalog documents, preserve units, currency, SKU labels, and variant relationships as metadata rather than expecting an embedding to retain them reliably.
Do not reconstruct by text matching alone
Searching the parsed document for the chunk text is tempting, but it is fragile. Whitespace normalization, repeated headings, OCR corrections, and duplicate policy language can produce multiple matches. Text matching is useful as a fallback validation step, not as the primary relationship between a chunk and its source.
Use explicit references first. If references are missing, store a content hash and a source range, then flag uncertain recoveries for review. A recovered element should carry a confidence or resolution status when the system cannot establish an exact match.
Practical checks for agency pipelines
- Integrity: verify that every chunk reference resolves to an element in the same document version.
- Ordering: ensure recovered elements are sorted by page, section, and source order.
- Isolation: include tenant or site identifiers in lookup keys so one store cannot resolve another store’s content.
- Versioning: invalidate or reprocess chunks when the source checksum or parser configuration changes.
- Observability: log document ID, chunk ID, element IDs, parser version, and retrieval score for debugging.
- Privacy: apply the same access controls to recovered source text that apply to the original document.
Example recovery flow
Suppose a retrieved chunk contains a return-policy heading, one paragraph, and a table describing excluded products. The retrieval service returns the chunk ID. The application then loads the referenced heading, paragraph, and table elements, restores their source order, and renders the result with the table intact. The language model receives the chunk for context, while the customer-facing response can cite the exact section and provide a controlled link to the policy.
This separation makes the Undefined pipeline easier to maintain: LlamaParse remains responsible for extracting document elements, the chunker decides how those elements are grouped for retrieval, and the application remains responsible for accurately presenting the original material.