KHOLO LogoDocs v1.0
Architecture

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 MessageActual Official Catalog SKUWhy 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:

Extraction Pipeline Flow
1. Customer WhatsApp
"Pls send 10 bags of whites 12.5kg and 5 coke 2lt"
2. OrderExtractor
Extracts quantities, units & raw names. Never invents SKUs.
3. Structured JSON
[{"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:

5-Step Catalog Resolution Waterfall
SkuMatcher Engine
1
Trade CanonicalizationPre-processing
Cleans text, standardizes units (10kg, 2L), and expands South African FMCG abbreviations ("whites", "stoney", "ricoffy").
↓
2
Exact Customer Alias MatchConfidence: 1.0 (Green)
Queries customer-specific jargon taught by clerks in prior orders. If found, instant 100% match.
↓ (if no customer alias)
3
Global Distributor Alias MatchConfidence: 0.95 (Green)
Checks if any customer or clerk across the depot previously taught this phrase.
↓ (if no alias)
4
Size & Packaging Unit VerificationFilter & Penalty
Extracts explicit package sizes (e.g. 12.5kg vs 10kg). Imposes a 60% penalty if pack sizes conflict.
↓
5
Fuzzy Similarity SearchThreshold Evaluation
Levenshtein and trigram matching against product descriptions. Scores ≥ 0.85 pass; lower scores route to Clerk Review.
Score ≥ 0.85:Auto-approved for 1-click sync
Score < 0.85:Flagged for Clerk "Resolve & Teach"

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 meal
    • stoney $\rightarrow$ stoney ginger beer
    • ricoffy $\rightarrow$ nescafe ricoffy
    • sunlight green $\rightarrow$ sunlight green laundry soap bar
    • dlite $\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):

Amber (0.72 Confidence)Line 2: "10x 12.5 whites"
Clerk Action Required
Resolve & Teach Customer Alias:Suggested: White Star Maize 12.5kg

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:

  1. Instant Order Correction: The current OrderLine updates to productId = 'WSTAR-12.5KG' with recalculation of unit prices and line subtotals.
  2. 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');
  1. Audit Trail: An immutable AuditLog record is captured documenting the user ID, timestamp, before/after values, and the newly taught phrase.
  2. 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 StageAverage AccuracyClerk Time per OrderRole of Human Clerk
Day 1: Shadow Mode~74% baseline4 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 Live96%+< 10 seconds (1-click)Automated Sage SO creation, pick slip printing, customer WhatsApp confirmation.
Week 2 Onward98%+AutonomousHuman-in-the-loop only for out-of-stock items or credit holds.

On this page