RecomNext

Appendices

API cheat sheet and ClickHouse SQL.

10 - Appendices

A. Recommendation API cheat sheet

All need tenant auth (X-Tenant-Id / HMAC as configured).

MethodPathNotes
GET/recommendations/algorithmsRegistry list
GET/recommendations/algorithms/:logicTypeFiltered registry
GET/recommendations/user-to-item/:userIdcount, scenario
GET/recommendations/item-to-item/:itemIdcount, scenario, userId (purchase cap)
GET/recommendations/recently-viewed/:userIdcount, scenario
POST/recommendations/items-to-itemsbody { itemIds, count } + scenario, userId
GET/recommendations/similar-products/:itemIdcount, scenario, userId
POST/recommendationsUnified body: scenario / logicType / ids / count

Response includes algorithm used.

Ingestion

MethodPath
POST/ingestion/interactions
POST/ingestion/impressions

Analytics (Admin JWT)

MethodPath
GET/analytics/scenario/:slug/summary?days=30
GET/analytics/scenario/:slug/funnel-volume?days=30
GET/analytics/scenario/:slug/top-items?days=30
GET/analytics/top-recommended?days=30

B. ClickHouse recipes (driffle-dev examples)

Interaction mix (30d)

SELECT type, count() AS c, sum(weight) AS sum_w, round(avg(weight), 3) AS avg_w
FROM recomnext.interactions
WHERE tenant_id = 'driffle-dev'
  AND event_time >= now() - INTERVAL 30 DAY
GROUP BY type
ORDER BY c DESC;

Scenario summary (matches Admin CTR)

SELECT
  (SELECT count()
   FROM recomnext.impressions
   WHERE tenant_id = 'driffle-dev'
     AND scenario_slug = 'pdp-similar-products'
     AND event_time >= now() - INTERVAL 30 DAY) AS impressions,
  (SELECT count()
   FROM recomnext.interactions
   WHERE tenant_id = 'driffle-dev'
     AND scenario_slug = 'pdp-similar-products'
     AND type = 'view'
     AND event_time >= now() - INTERVAL 30 DAY) AS clicks_views,
  round(clicks_views / impressions * 100, 2) AS ctr_pct;

Weighted-history style item scores (global, illustrative)

SELECT item_id,
       sum(weight * multiIf(
         type = 'purchase', 4,
         type = 'cart', 2,
         type = 'rating', 3,
         1)) AS total_weight,
       countIf(type = 'view') AS views,
       countIf(type = 'cart') AS carts,
       countIf(type = 'purchase') AS purchases
FROM recomnext.interactions
WHERE tenant_id = 'driffle-dev'
  AND event_time >= now() - INTERVAL 30 DAY
GROUP BY item_id
ORDER BY total_weight DESC
LIMIT 20;

Co-occurrence for one seed

SELECT b.item_id AS related_item_id, count() AS co_count
FROM recomnext.interactions AS a
INNER JOIN recomnext.interactions AS b
  ON a.tenant_id = b.tenant_id AND a.user_id = b.user_id
WHERE a.tenant_id = 'driffle-dev'
  AND a.item_id = 'SEED_ITEM_ID'
  AND b.item_id != 'SEED_ITEM_ID'
  AND a.event_time >= now() - INTERVAL 30 DAY
  AND b.event_time >= now() - INTERVAL 30 DAY
GROUP BY related_item_id
ORDER BY co_count DESC
LIMIT 40;

Attribution health: views without impressions (same user+item)

WITH
  views AS (
    SELECT user_id, item_id, count() AS view_cnt
    FROM recomnext.interactions
    WHERE tenant_id = 'driffle-dev'
      AND scenario_slug = 'pdp-similar-products'
      AND type = 'view'
      AND event_time >= now() - INTERVAL 30 DAY
    GROUP BY user_id, item_id
  ),
  imps AS (
    SELECT user_id, item_id, count() AS imp_cnt
    FROM recomnext.impressions
    WHERE tenant_id = 'driffle-dev'
      AND scenario_slug = 'pdp-similar-products'
      AND event_time >= now() - INTERVAL 30 DAY
    GROUP BY user_id, item_id
  )
SELECT
  count() AS view_pairs,
  countIf(i.imp_cnt > 0) AS pairs_with_impression,
  sum(v.view_cnt) AS total_views,
  sumIf(v.view_cnt, i.imp_cnt = 0 OR isNull(i.imp_cnt)) AS views_orphan
FROM views v
LEFT JOIN imps i ON v.user_id = i.user_id AND v.item_id = i.item_id;

C. Type multipliers (weighted-history)

typemultiplier
purchase4
rating3
cart2
view / other1

Windows: personal history 30d; popularity fill 7d; purchase-cap history 90d.


D. Constraint defaults (conceptual)

FieldTypical default / note
purchasedItemsMaxPercent10 if unset
longTailPercentage10 when long-tail on
Freshness boost factor×1.5 inside window
minItems / maxItems6 / 12 common scenario defaults

E. Document map

FileContents
READMEHub
01Architecture
02Terms
03Events & CTR
04Pipeline & knobs
05Logics & algos
06ELSA / ReALM / beeFormer
07Calculations
08Ops
09Attribution failure
10This file