Table of contents :

Real-Time Product Updates in a RAG Pipeline

100-days-of-rag-for-woocommerce-036

Table of contents :

Why product freshness matters in WooCommerce RAG

A retrieval-augmented generation system is only as reliable as the product data it retrieves. If a product is out of stock, a price has changed, or a variation has been disabled since the last indexing run, the assistant can produce an answer that is fluent but operationally wrong.

For WooCommerce agencies, real-time updates do not necessarily mean rebuilding the entire catalog for every change. A practical design captures product changes, converts them into small indexing jobs, updates the affected records, and makes the new version visible to retrieval as quickly as possible.

Separate the source of truth from the retrieval index

WooCommerce remains the source of truth for product data. The vector database, keyword index, or document store is a derived representation optimized for retrieval. This distinction is important because an index can be delayed, partially unavailable, or rebuilt without changing the store itself.

A useful product record usually contains both searchable content and filterable metadata:

  • Product and variation IDs
  • SKU, product type, and taxonomy terms
  • Title, short description, and long description
  • Attributes such as size, color, and material
  • Price and currency
  • Stock status and purchasable status
  • Catalog visibility
  • Last modified timestamp
  • A source version or update sequence

Keep frequently changing fields, such as price and stock, easy to update independently from slower-changing descriptive content. In some systems, the descriptive text is embedded while price and availability are stored as metadata used by filters or response-time checks.

Capture changes from WooCommerce

There are three common ways to detect changes: WordPress and WooCommerce hooks, WooCommerce webhooks, and scheduled reconciliation. A production implementation often uses more than one.

Hooks for local event publication

When the indexing worker runs in the same WordPress environment, hooks can publish an internal event after a product is saved. For example, an agency can enqueue a product ID instead of performing embedding or remote API calls during the admin request.

<?php
add_action( 'woocommerce_update_product', function ( $product_id ) {
    as_enqueue_async_action(
        'my_rag_index_product',
        array( 'product_id' => (int) $product_id ),
        'rag-indexing'
    );
} );

The exact hooks should be selected carefully. Product updates can trigger multiple saves, and a product may be changed by the block editor, an import process, a bulk editor, or a plugin. The callback should be lightweight and idempotent. It should not generate embeddings, call an external vector service, or rebuild related documents inside the request that saved the product.

Webhooks for decoupled services

If the RAG pipeline runs outside WordPress, WooCommerce webhooks can deliver product events to an ingestion endpoint. The endpoint should authenticate the request, record the event, acknowledge it quickly, and process it asynchronously. Do not make the WooCommerce request wait for document generation or vector database availability.

Webhook delivery should be treated as at-least-once delivery. The same event may arrive more than once, and events may be delayed or delivered out of order. Store a deduplication key when one is available, and also make the downstream operation safe to repeat by using the product ID and a current source version as the document identity.

Scheduled reconciliation

Hooks and webhooks can fail because of plugin errors, network outages, disabled actions, or incomplete bulk imports. A scheduled reconciliation job should query products modified after a stored checkpoint and compare the source state with the indexed state. A nightly full or partitioned scan is also useful for detecting missed deletions and metadata drift.

Use a durable event and job model

A basic event can contain the minimum information required to refresh a product:

{
  "event_id": "wc-product-4821-2025-03-08T10:15:22Z",
  "entity_type": "product",
  "entity_id": 4821,
  "operation": "upsert",
  "source_modified_at": "2025-03-08T10:15:22Z",
  "source_version": 187,
  "site_id": "store-example"
}

The event should identify the store as well as the product. This matters for agencies operating multiple WooCommerce sites in a shared ingestion service. A tenant-aware document key such as store-example:product:4821 prevents collisions between client stores.

Use a durable queue rather than an in-memory task list. Action Scheduler is suitable for many WordPress-hosted workflows. External queues such as SQS, RabbitMQ, or a managed task system may be preferable when several stores share workers or when ingestion volume is high.

Make updates idempotent and order-aware

An index worker should fetch the current product from WooCommerce or WordPress instead of trusting a possibly stale webhook payload. It should then determine whether the retrieved version is newer than the indexed version. A simple indexed state might contain:

{
  "document_id": "store-example:product:4821",
  "source_version": 187,
  "source_modified_at": "2025-03-08T10:15:22Z",
  "content_hash": "sha256:...",
  "indexed_at": "2025-03-08T10:15:25Z"
}

If an older job finishes after a newer job, the worker must not overwrite the newer document. Compare a monotonic version, an authoritative modified timestamp, or a version assigned by the ingestion service. Timestamps alone can be unsafe when a system has limited precision or clocks are not synchronized, so a database revision number or event sequence is preferable where available.

Content hashes reduce unnecessary work. If the normalized product document has the same hash as the indexed document, skip embedding generation and update only operational metadata if necessary. This is particularly valuable when plugins save a product without changing its customer-facing content.

Handle product, variation, and deletion events

Variable products require an explicit indexing policy. A parent product document can describe the shared product, while each variation can be indexed as a separate document when customers ask questions about exact attributes, stock, or price. Store a parent ID on variation documents so retrieval can group or expand related results.

When a product is moved to draft, made private, hidden from the catalog, or deleted, the retrieval index must reflect that state. A delete operation should remove or tombstone every affected document, including variations and derived chunks. A tombstone can be useful when asynchronous jobs may still be in flight:

{
  "document_id": "store-example:product:4821",
  "deleted": true,
  "source_version": 188,
  "deleted_at": "2025-03-08T10:20:00Z"
}

Whether hidden products should be removed or merely excluded at query time depends on the use case. For a customer-facing shopping assistant, applying availability and visibility filters during retrieval is safer than relying only on prompt instructions.

Choose what must be real time

Not every field needs the same update path. A useful split is:

  • Immediate metadata updates: stock status, purchasable status, price, sale dates, and catalog visibility.
  • Near-real-time text updates: title, descriptions, attributes, and taxonomy terms.
  • Batch updates: large catalog imports, synonym generation, and full embedding model migrations.

For stock and price, consider a final source-of-truth check immediately before generating a purchase-related answer or presenting an add-to-cart action. Retrieval filters can remove out-of-stock products, but a checkout or cart operation must still validate the current WooCommerce state because inventory may change after retrieval.

Refresh documents without blocking retrieval

A common pipeline is:

  1. Receive a product change event.
  2. Deduplicate the event and place a job on a durable queue.
  3. Fetch the current product and related variations.
  4. Normalize the fields into a canonical document.
  5. Calculate a content hash and source version.
  6. Split changed content into chunks when required.
  7. Generate embeddings only for changed chunks.
  8. Upsert vectors and metadata using stable document IDs.
  9. Remove stale chunks and mark the new version active.
  10. Record latency, status, and the indexed version.

Use an atomic visibility strategy where the vector store supports it. Write the new chunks with a new version, then switch an active-version marker or filter. This prevents a reader from seeing a mixture of old and new chunks during a multi-chunk update. If atomic switching is unavailable, use stable IDs and an upsert order that minimizes the window of inconsistency.

Prevent stale answers in the application layer

Retrieval freshness is not only an indexing concern. The application should pass relevant constraints into the retriever, such as store ID, language, channel, catalog visibility, and current availability. It should also expose the indexed timestamp or source version to observability systems so an agency can measure actual freshness rather than assuming that a successful queue operation means the index is current.

For high-risk fields, include the product ID in the answer-generation context and resolve the final price, stock, or purchasability from WooCommerce before displaying an action. The language model can summarize the retrieved product, but it should not be the authority for transactional state.

Monitor freshness and failure modes

Track metrics per store and per event type:

  • Event receipt-to-index latency
  • Queue age and retry count
  • Embedding generation failures
  • Vector upsert failures
  • Number of stale documents by source version
  • Deletion lag
  • Webhook authentication failures
  • Reconciliation corrections

Keep a dead-letter queue for events that exceed the retry limit. Provide an admin or operational command to reindex a product, a parent product with all variations, a category, or the entire store. Logging should include the tenant, product ID, event ID, source version, indexed version, and correlation ID without exposing customer data.

Practical agency implementation pattern

For a typical WooCommerce client, start with an event adapter in WordPress or a WooCommerce webhook. Publish only the store ID, product ID, operation, and source version. Let a worker fetch the canonical product, normalize it, and update the retrieval store. Add Action Scheduler or an external queue for durability, a reconciliation task for recovery, stable document IDs for idempotency, and source-version checks for ordering.

This design keeps WooCommerce responsive, limits embedding costs, supports multiple client stores, and gives the agency measurable control over how quickly product changes become visible to the RAG system.

Trending posts
You might also like