Ask the admin chatbot on your WooCommerce store what revenue was last quarter and it will hand you a number in seconds. Whether that number is real is a separate question, and RAG for WooCommerce usually fails on it quietly. Emmimal P Alexander benchmarked this on 100,000 transaction rows and wrote up the results on Towards Data Science: a retrieval pipeline that saw 8 percent of the data answered a “total spend by category” question with a breakdown worth about half the real figure. Each jump in context size made the answer longer, more confident, and no more correct.
Where RAG for WooCommerce breaks first
Retrieval scores rows by similarity and passes the top N to the model. That handles “find transactions from Jennifer Banks”, the lookup example from the source. It cannot handle a SUM, because the correct total depends on rows retrieval never returned, and the model doesn’t run a sum either. What you get back is prose that looks like an aggregation over whatever text it was handed.
The benchmark numbers make the failure visible. On a five-row context the error is obvious. At 8,000 rows out of 100,000 the answer still misses half the total, but it comes out as a report with all 14 categories present and specific figures, so a reader can’t easily catch it. The author calls this Error Observability Collapse, and the name fits: confidence scales with context and correctness doesn’t.
The engine already exists in your database
The author’s fix was a deterministic engine that scans the full CSV and returns exact numbers (under 200ms on 100,000 rows), plus a router that sends aggregation questions to it. A store already has that engine, because MySQL is it. A total, a count, an average: each is one call to $wpdb->get_var(). Since WooCommerce 8.2, HPOS keeps the order total in a real column, total_amount. The router is the only part that’s new for us.
In PHP, with the same tier order the source uses:
<?php
// Tier 1: aggregation verbs. Tier 3: lookup verbs. Same order as the source.
function bbioon_route_store_query( string $question ): string {
$compute = '/\b(total|revenue|sum|how many|average|percentage|lowest|highest|at least)\b|\b(greater|more|less) than\b/i';
$retrieve = '/\b(find|show me|list|search)\b/i';
if ( preg_match( $compute, $question ) ) {
return 'compute';
}
if ( preg_match( $retrieve, $question ) ) {
return 'retrieve';
}
return 'compute'; // ambiguous, so it fails loudly later
}
function bbioon_completed_order_total( float $min = 0.0 ): ?float {
global $wpdb;
if ( ! \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) {
return null; // legacy storage: caller shows an error, never falls back to the LLM
}
return (float) $wpdb->get_var(
$wpdb->prepare(
"SELECT SUM(total_amount) FROM {$wpdb->prefix}wc_orders
WHERE status = %s AND total_amount >= %f",
'wc-completed',
$min
)
);
}For anything grouped, WooCommerce maintains the wc_order_product_lookup table for analytics, so revenue by category joins to that instead of scanning order rows. For lookups, wc_get_orders() with field_query covers questions like one customer’s order history, and the order query docs are the reference for that. The null return on legacy storage matters. On stores still running orders in postmeta, the query answers nothing, which is loud. An LLM fallback would answer something.
Where the other side has a point
Retrieval still earns its place on the fuzzy side. “Which reviews mention the strap running small” is a similarity question, and the source routes those to retrieval too. I’ve written about grounding a WooCommerce chatbot in real store data before, and none of that retrieval work changes here.
RAG is being asked to compute, and it can’t do that.
The source is honest about its limits, and the big one transfers badly to stores. The engine reads one flat CSV, with no joins. Revenue by category on a store means orders joined to line items, variation pricing, refunds and taxes, and the same figures on HPOS and legacy storage. That’s a week of careful work. Uploading a CSV and letting the model talk about it is an afternoon, and that gap is why wrong numbers keep shipping. I’d still pay the week, because store owners restock and set ad budgets from these figures. (I haven’t tested the router against non-English phrasing, so I can’t say how the patterns hold up there.)
The default I’d keep
If a question matches no pattern, the source routes it to computation and lets the engine throw an error when it can’t parse the query. That default looks like a worse experience, and I’d keep it anyway. In a plugin it means returning a WP_Error or calling wp_send_json_error() instead of falling through to the LLM, so the failure is visible and you learn the router needs another pattern. The alternative is a silent wrong number in someone’s Monday meeting.
Keep the model for what it’s good at: pass it the aggregate result or the retrieved rows and let it write the response. I sketched the same split when writing about what a WooCommerce data agent actually needs, and the router slots straight into it.
If you’re building a store chatbot and want the numbers to survive the demo, that’s the kind of work I take on: the query routing, the exact SQL for both storage modes, and the tests that keep them agreeing.
Start with one number: pick a figure the chatbot gave you this week and run the equivalent SQL yourself. In the source’s benchmark the model’s category breakdown summed to less than half of the $1,140,033.24 ground truth. If they match, you may not have the problem yet. If they don’t, you’ve found the missing router.