The Learning Loop & Alias Engine
How SkuMatcher, trade canonicalizer, and alias learning work together.
One of the central differentiators of KHOLO is its ability to learn and adapt to informal wholesale jargon, regional dialects, brand nicknames, and shorthand abbreviations without requiring manual rule coding.
This document details the mechanics of the Extraction Engine, the SKU Matcher, and the Human-in-the-Loop "Resolve & Teach" learning mechanism.
1. The Real-World Challenge: Informal B2B Trade
In South African wholesale and FMCG distribution, retail customers (spaza shops, general dealers, restaurants, catering businesses) do not order using formal ERP codes. They message via WhatsApp in freeform text or voice:
| Customer WhatsApp Message | Actual Official Catalog SKU | Why Standard Systems Fail |
|---|---|---|
| "10 whites 12.5" | WSTAR-12.5KG (White Star Maize Meal 12.5kg) | Standard software looks for "White Star", misses "whites". |
| "2 cases stoney 2L" | STONEY-2L (Stoney Ginger Beer 2L x 6) | Needs unit understanding (cases vs single bottles). |
| "5 red sugar 10kg" | HUL-SUG-10KG (Huletts White Sugar 10kg) | Red bag packaging refers to Huletts white sugar in colloquial trade. |
| "4 boxes zamalek" | CBL-500ML-24S (Carling Black Label 500ml Cans x 24) | Township slang for Carling Black Label beer. |
| "3 tins ricoffy big" | RICOF-750G (Nescafé Ricoffy 750g Tin) | "Big" must be disambiguated from 250g and 1.5kg tins. |
2. Phase 1: Strict AI Extraction (OrderExtractor)
A common mistake in AI order processing is asking an LLM to simultaneously extract items and pick the database SKU. This causes hallucinations, wrong pack sizes, and ERP sync failures.
KHOLO strictly separates Extraction from Catalog Matching:
[{"item": "whites 12.5kg", "qty": 10},{"item": "coke 2lt", "qty": 5}]
The System Prompt Architecture
The extraction prompt is conditioned specifically for wholesale trade:
- Recognizes African quantity words and mixed language patterns (e.g., "fipha 10", "ngicela 5").
- Separates customer conversational pleasantries ("Good morning brother, how is family...") from genuine order lines.
- Identifies order intent (
new_order,add_to_order,remove_from_order,status_check).
3. Phase 2: Multi-Tier Matching (SkuMatcher)
Once OrderExtractor isolates { raw_item, quantity }, SkuMatcher evaluates the item against the distributor's catalog using a 5-step waterfall algorithm:
1. Trade Canonicalization
Before searching, the input string is cleaned and standardized:
- Units normalized:
10 kgs,10 kilo,10k$\rightarrow$10kg. - Volumes normalized:
2 litres,2 lt,2lts$\rightarrow$2l. - Well-known South African FMCG brand expansions:
whites$\rightarrow$white star maize mealstoney$\rightarrow$stoney ginger beerricoffy$\rightarrow$nescafe ricoffysunlight green$\rightarrow$sunlight green laundry soap bardlite$\rightarrow$dlite cooking oil
2. Size & Pack Penalty Logic
If the customer asks for 10kg and the candidate product is 2.5kg, KHOLO imposes an automatic penalty to prevent dangerous incorrect picks:
if (itemSize && candidateSize && itemSize !== candidateSize) {
// Severe confidence penalty for mismatched packaging sizes
confidence = confidence * 0.4;
}4. Phase 3: The Human-in-the-Loop "Resolve & Teach" Mechanism
When confidence falls below the auto-approval threshold ($< 0.85$) or multiple ambiguous products exist, the order is routed to the Clerk Control Centre (/dashboard):
WSTAR-12.5KG - White Star Super Maize Meal 12.5kg
Scope: This Customer Only (permanent alias saved for Clerk Spaza)
What Happens When the Clerk Confirms:
- Instant Order Correction: The current
OrderLineupdates toproductId = 'WSTAR-12.5KG'with recalculation of unit prices and line subtotals. - Permanent Alias Ingestion: A new record is inserted into
ProductAlias:
INSERT INTO "ProductAlias" ("tenantId", "productId", "aliasText", "customerId")
VALUES ('tenant-uuid', 'prod-wstar-12.5', '12.5 whites', 'customer-uuid');- Audit Trail: An immutable
AuditLogrecord is captured documenting the user ID, timestamp, before/after values, and the newly taught phrase. - Immediate Learning: The next time this customer sends "12.5 whites", Step 2 triggers: Confidence = 1.0 (Instant Green).
5. Accuracy Compounding Over Time
In pilot deployments, KHOLO demonstrates a rapid compounding accuracy curve:
| Deployment Stage | Average Accuracy | Clerk Time per Order | Role of Human Clerk |
|---|---|---|---|
| Day 1: Shadow Mode | ~74% baseline | 4 minutes (manual entry) | Clerks type manually in Sage; Kholo mirrors in background. |
| Day 2: Hybrid Mode | ~88% - 92% | 35 seconds (review) | Clerks review amber items and teach aliases via dashboard. |
| Day 3: Full Live | 96%+ | < 10 seconds (1-click) | Automated Sage SO creation, pick slip printing, customer WhatsApp confirmation. |
| Week 2 Onward | 98%+ | Autonomous | Human-in-the-loop only for out-of-stock items or credit holds. |