Worked examples
Formulas and driffle-dev calculations.
07 - Worked examples
Numbers use driffle-dev ClickHouse snapshots from 2026-07-23 unless labeled hypothetical.
A. Weighted-history score
Formula reminder
total_weight = Σ weight × multiIf(purchase→4, cart→2, rating→3, else→1)
Hypothetical user
| Item | Raw events (weight=1) | Computation | total_weight |
|---|---|---|---|
| 1001 | 2 views, 1 cart | 2×1 + 1×2 | 4 |
| 1002 | 1 purchase | 1×4 | 4 |
| 1003 | 5 views | 5×1 | 5 → #1 |
After scenario booster boost by 1.5 where 'featured' = true on 1001 only:
- 1001 →
4 × 1.5 = 6→ becomes #1 if featured.
Live catalog popularity (30d interaction totals by item)
Top items by the same weighted formula aggregated across all users (not a single user - illustrative of weight mass):
| item_id | total_weight | views | carts | purchases |
|---|---|---|---|---|
| 9994434 | 3413 | 3413 | 0 | 0 |
| 9879164 | 1129 | 1129 | 0 | 0 |
| 9884392 | 1067 | 1067 | 0 | 0 |
Interpretation: almost all signal is views; cart/purchase are still rare in this tenant window - collaborative strength will be view-heavy until commerce events grow.
B. Co-occurrence
Hypothetical
Seed S. In 30d:
| Candidate | Distinct users who also touched S | Score before boosters |
|---|---|---|
| R1 | 25 | 25 |
| R2 | 10 | 10 |
| R3 | category fallback only | 0.5 |
Booster boost by 2 where 'platform' = 'Steam' on R2 → score 20 (may pass R1 if R1 doesn’t match).
C. RRF (multi-seed-hybrid)
Two ranked lists, rrfK = 60:
Co-list: [A, B, C]
Vector-list: [B, D, A]
| Item | Co contrib | Vec contrib | RRF sum |
|---|---|---|---|
| A | 1/(60+1)=0.01639 | 1/(60+3)=0.01587 | 0.03226 |
| B | 1/(60+2)=0.01613 | 1/(60+1)=0.01639 | 0.03252 → #1 |
| C | 1/(60+3)=0.01587 | 0 | 0.01587 |
| D | 0 | 1/(60+2)=0.01613 | 0.01613 |
B wins even if raw co_count and vector distances aren’t comparable - RRF only uses ranks.
D. Constraints: diversity + freshness + purchase cap
Start scored list (category, score):
- G1 games 10
- G2 games 9
- G3 games 8
- S1 software 7
- G4 games 6
maxPerCategory = 2 → keep G1, G2, S1, then next non-games… (G3/G4 dropped by diversity).
Freshness: if S1 is “fresh”, score 7 × 1.5 = 10.5 → may reorder above G2 after re-sort.
Purchase cap 10% on 10 results → max 1 already-purchased item in the final 10 (floor of 10×0.1, at least 1 when purchases exist).
E. Scenario CTR (live)
pdp-similar-products, ~30d:
impressions = 48,696
clicks (type=view & slug) = 114,385
CTR = round(114385 / 48696 * 10000) / 100 = 234.9%
Tenant-wide interactions same window: views 114,554 · carts 17 · purchases 13.
Reading: CTR here is not “rail click-through.” See 09.
F. End-to-end PDP similar (intended happy path)
If the host instead calls trackView(currentSku, pdp-similar-products) on every PDP, CH fills with slug-views unrelated to rail impressions → CTR explodes.
G. Geo ranking v1 (hypothetical)
Shrinkage k = 500. Grain volumes: country n_c = 1500, cluster n_r = 2000.
α_c = 1500 / (1500 + 500) = 0.75
α_r = 2000 / (2000 + 500) × (1 - 0.75) = 0.80 × 0.25 = 0.20
α_g = 1 - 0.75 - 0.20 = 0.05
Fill blended_count (weighted-history Option B)
Item X has 7d counts count_c = 40, count_r = 50, count_g = 100:
blended_count(X) = 0.75×40 + 0.20×50 + 0.05×100 = 30 + 10 + 5 = 45
Fill rows keep score 0.5; only membership/order uses blended_count.
Personal score beats fill 0.5
User touched item A twice (views) → personal score 2. Geo-popular item B has a high blended_count but fill score stays 0.5. Score-sort keeps A above B. That is why this path does not lift personal or fill scores.
Lift above 1 (i2i / similar / ML factors)
Same α_*. Tenant 7d totals: total_c = 1500, total_r = 2000, total_g = 10000. Item over-indexes in-country: count_c = 30, count_r = 20, count_g = 50.
rate_c = 30/1500 = 0.02
rate_r = 20/2000 = 0.01
rate_g = 50/10000 = 0.005
rate_blend = 0.75×0.02 + 0.20×0.01 + 0.05×0.005 = 0.01725
lift = 1 + (0.75+0.20) × (0.01725/0.005 - 1) = 1 + 0.95×2.45 = 3.3275
If the algorithm score was 10 → final = 33.275. No upper cap in v1.
Lift below 1 (regional under-index)
Same totals. Item globally hot, weak in-country: count_c = 3, count_r = 8, count_g = 200.
rate_c = 3/1500 = 0.002
rate_r = 8/2000 = 0.004
rate_g = 200/10000 = 0.02
rate_blend = 0.75×0.002 + 0.20×0.004 + 0.05×0.02 = 0.0033
lift = 1 + 0.95 × (0.0033/0.02 - 1) = 1 + 0.95×(-0.835) = 0.20675
Score 10 → final ≈ 2.07 (ranks down vs _global_). Not a bug; do not floor lift at 1.
n_c = 0 → lift 1
No 7d events in the request country (n_c = 0) and no cluster grain (unclustered / OTH / skip cluster → n_r = 0):
α_c = 0, α_r = 0, α_g = 1
lift = 1 + 0 × (rate_blend/rate_g - 1) = 1
Same lift 1 when the tenant has no 7d interactions at all (total_g = 0) or the item has count_g = 0. Sparse country ≈ global behaviour.
