Table of contents :

RAG for WooCommerce Product Comparisons

100-days-of-rag-for-woocommerce-024

Table of contents :

Product comparison is one of the most useful commerce applications for retrieval-augmented generation (RAG), but it is also one of the easiest to get wrong. A useful comparison must identify the correct WooCommerce products, normalize their attributes, distinguish product-level data from variation-level data, and avoid presenting outdated prices or unsupported claims as facts.

What RAG adds to WooCommerce comparisons

A language model can write a fluent comparison from a product feed, but fluency does not guarantee that the products are relevant or that the details are current. RAG provides a controlled path from a shopper’s question to the store’s product data:

  1. Interpret the shopper’s requirements, such as budget, dimensions, compatibility, or intended use.
  2. Retrieve candidate products using semantic and exact matching.
  3. Load authoritative product and variation fields for those candidates.
  4. Compare only the retrieved evidence and identify missing information.
  5. Generate an answer with citations, product links, and appropriate qualification.

For an agency, this approach is preferable to placing the entire catalog in a prompt. It reduces token usage, improves relevance, and makes the answer traceable to WooCommerce records.

Model the catalog for comparison, not just search

Product comparison requires more structure than a basic document index. Store each product as a searchable record, but preserve important fields as typed metadata. A useful record can include:

  • Identity: product ID, SKU, name, permalink, parent product ID, and product type.
  • Commercial data: regular price, sale price, currency, stock status, purchasability, and tax or pricing context.
  • Attributes: brand, material, dimensions, capacity, compatibility, color, size, and other taxonomy or custom attributes.
  • Operational data: shipping class, lead time, backorder status, downloadable status, and fulfillment restrictions.
  • Descriptive evidence: short description, long description, specifications, manuals, FAQs, and approved marketing content.

Use embeddings for descriptive text and semantic requirements, but use metadata filters and structured comparisons for numeric or categorical requirements. An embedding should help retrieve products described as suitable for a small workspace; it should not decide whether a product weighs less than 10 kilograms.

Use hybrid retrieval

A shopper may ask, “Compare waterproof hiking jackets under $200 that fit a 40-inch chest.” This request contains semantic intent, exact constraints, and numeric conditions. A practical retrieval pipeline combines:

  • Keyword or lexical search for exact terms such as model names, standards, SKUs, and compatibility codes.
  • Vector search for concepts such as “for cold-weather commuting” or “easy to install.”
  • Metadata filtering for product category, price range, stock status, brand, and normalized attributes.
  • Reranking to prioritize products that satisfy the largest number of explicit requirements.

Do not apply a price filter to text alone. Extract the budget into a structured query and compare it with the correct price field. For variable products, define whether the filter uses the cheapest purchasable variation, the selected variation, or all available variations. That policy should be visible in the application logic rather than left to the model.

Normalize WooCommerce attributes before indexing

WooCommerce catalogs often contain inconsistent values. One product may use “Blue,” another “navy,” and a third may place the value in the description. Dimensions may appear as “20cm,” “20 cm,” or “7.87 in.” A comparison system should normalize these values during ingestion.

Keep both the original display value and a normalized comparison value. For example:

{"attribute":"capacity","display_value":"20 litres","normalized_value":20,"unit":"L","source":"woocommerce_attribute"}

For categorical fields, maintain controlled mappings where appropriate. For measurements, convert to a canonical unit while retaining the storefront unit for presentation. If a value cannot be parsed reliably, mark it as unknown rather than estimating it from nearby text.

Handle products and variations separately

Many comparison errors occur when a parent product is treated as though it has one universal price, stock state, or specification. A variable product may have different dimensions, capacities, colors, prices, or compatibility details for each variation.

Index the parent product for general discovery and index variations, or variation-specific records, for attributes that affect purchasing. The retrieval result should identify the source level:

  • Product-level fact: applies to the parent product and all relevant variations.
  • Variation-level fact: applies only to a specific option combination.
  • Derived fact: calculated by the application, such as the lowest current purchasable price.

When the shopper has not selected a variation, the answer should state the scope clearly. For example, “Prices start at $79” is different from “The medium, black variation costs $79.”

Separate volatile data from durable content

Descriptions and technical specifications may change occasionally, while price, stock, sale dates, and availability can change frequently. Do not rely on a week-old embedded product document for volatile commercial facts.

A robust implementation can retrieve descriptive evidence from the vector index and then fetch current commercial data from WooCommerce immediately before generation. Depending on the store architecture, this may use the WooCommerce REST API, Store API, a custom read model, or a database-backed service that applies the store’s pricing and visibility rules.

For example, the final comparison context might contain:

{"product_id":4812,"name":"Trail Shell Jacket","url":"https://example.com/product/trail-shell-jacket/","current_price":149.00,"currency":"USD","stock_status":"instock","specifications":{"waterproof_rating":"20,000 mm","weight_g":410},"evidence":[{"field":"waterproof_rating","source_url":"https://example.com/product/trail-shell-jacket/"}]}

Design the comparison prompt around evidence

The generation step should receive a compact, labeled evidence set rather than unrestricted catalog text. Instruct the model to:

  • Use only retrieved product records and approved store policies.
  • Keep product facts separate from recommendations or inferred suitability.
  • Never invent a missing specification.
  • Explain when products are not directly comparable.
  • Preserve units and currency, or state conversions explicitly.
  • Link each product to its current product page.
  • Report when price or stock was checked.

A useful response format can include a short selection rationale, an HTML comparison table, product-specific advantages and limitations, and a note about unknown fields. If the user has supplied hard constraints, the application should validate them after generation and reject or revise any row that violates the retrieved data.

Example comparison workflow

  1. Parse “Compare three office chairs under $500 for users up to 120 kg” into category, result count, price ceiling, and supported load.
  2. Apply category and purchasability filters.
  3. Run semantic retrieval for office chairs and relevant ergonomic content.
  4. Normalize price and maximum supported load into numeric fields.
  5. Rerank products that satisfy both constraints.
  6. Fetch current price, stock, and variation information for the top candidates.
  7. Generate a comparison using only the validated records.
  8. Run post-generation checks for unsupported numbers, broken product links, and products outside the budget.

Evaluation criteria for agencies

Test comparison quality with a dataset of real shopper questions and expected constraints. Useful measurements include:

  • Constraint satisfaction: the percentage of returned products that meet explicit requirements.
  • Attribute accuracy: agreement between generated values and the current WooCommerce record.
  • Variation accuracy: whether price, size, and stock belong to the cited variation.
  • Coverage: whether the answer addresses the user’s requested comparison fields.
  • Abstention quality: whether the system admits that a specification is unavailable.
  • Freshness: the age of price and inventory data at generation time.

Include adversarial cases such as conflicting descriptions, discontinued products, sale prices with scheduled dates, duplicate SKUs, unit conversions, and products whose marketing copy implies a feature that is not represented in structured attributes.

Operational safeguards

Cache embeddings and stable product content, but use short-lived caching or real-time reads for price and stock. Reindex products when WooCommerce product, variation, attribute, or taxonomy data changes. Keep source URLs and field-level provenance in the retrieval records so support teams can inspect an answer.

Also treat product descriptions as untrusted input. A description could contain instructions intended to manipulate the model. Delimit catalog content, give system instructions precedence, and prevent retrieved text from changing tools, filters, permissions, or response rules.

For stores with regulated products or safety-sensitive specifications, require a deterministic field check before publishing a comparison. The model can explain the differences, but the application should decide whether a product meets a hard technical or compliance requirement.

Trending posts
You might also like