> Markdown version of https://www.imranjan.cn/projects/p-shopping-copilot for AI agents and other programs. It carries the same public information as the web page. Built 2026-11-30.

August 2026

# Shopping Copilot by KI

Conversational shopping agent

TikTok TechJam 2026, Track 4

An offline shopping agent I built at TikTok TechJam that asks useful questions and keeps track of requests that change mid-conversation. It runs entirely on the local machine with no LLM calls.

Tags: Hackathon, AI Agent, Information Retrieval, SQLite FTS5

![Shopping Copilot by KI](https://www.imranjan.cn/images/projects/shopping-copilot-2026/ki-mark.svg)

### Project resources

The full code is public on GitHub, with steps to reproduce the evaluation in the README. The demo video plays on Google Drive, and the Devpost page has the full submission write-up.

[Source code](https://github.com/narmi924/shopping-copilot)
[Watch the demo](https://drive.google.com/file/d/1wGowJKAkjicNARgGQhL6CxnYbV%5FNhrIA/view?usp=sharing)
[Devpost submission](https://devpost.com/software/shopping-copilot-by-ki)

## Event

#### Hackathon

TikTok TechJam 2026
Track 4: Shopping Copilot

- **Organizer**: TikTok Singapore
- **Challenge**: Build a conversational shopping assistant that finds the one product a customer wants among 50,000 clothing, shoe and bag items in at most 10 turns
- **Result**: Not selected for the grand final
[Hackathon website](https://tiktoktechjam2026.devpost.com/)

#### Entrant (KI)

- [Me](https://github.com/narmi924)
Designed the retrieval and dialogue policy; accelerated prototyping and modules with Codex.
- **Time**: Three days
- **Code**: About 3,100 lines of core Python, 78 tests
- **Runtime**: No network, no LLM calls, about 70 seconds per evaluation run

## Background

Shoppers rarely state everything up front. They start vague, add “waterproof” or “under $80” after seeing a few options, and sometimes switch from a backpack to shoes halfway through. A search that only reads the latest message forgets what came before; one that piles every message together lets outdated requests keep shaping the results.

Track 4 of TikTok TechJam asked for exactly this kind of shopping assistant: a Python agent that, within ten turns of conversation, finds the one product a customer ends up buying from 50,000 clothing, shoe and bag listings, as early and as high in the ranking as possible. Each turn the agent can recommend up to ten products and ask one question.

I kept everything offline with no LLM calls: remember every request the customer made and its current status, ask only when a question will actually narrow things down, rank the candidates and keep a few slots for other possibilities. On the 200 official public sessions, Hit Rate@10 went from the baseline’s 12.5% to 94%, using zero model tokens.

### System architecture

Each turn, the message first goes through an intent router that decides whether the customer is buying, browsing or changing their mind, and the constraint ledger records every request with its status and the turn it came from. Retrieval runs six routes; the numbers are their fusion weights, with exact evidence weighted highest. Underneath sits one read-only catalog with a full-text index, an evidence fingerprint index and candidate facets. After reranking, the candidate portfolio decides which Top-10 slots go to the most likely products and which are kept for exploration, and the question value estimator decides whether to ask something this turn, and what. The ledger carries its state into the next turn.

![Shopping Copilot offline decision pipeline](https://www.imranjan.cn/images/projects/shopping-copilot-2026/architecture.png)

Shopping Copilot’s pipeline, redrawn from the final code.

## How It Is Measured

The catalog comes from the clothing, shoes and jewelry category of Amazon Reviews 2023, 50,000 products in all. Each has a title, features, description, price, categories, details, rating and store. Prices are patchy: only about 21% of products have one.

During evaluation the evaluator plays the customer. It picks a few of the target product’s own features and details as requirements and states them through scenario templates. Each turn the agent can recommend, or ask about one attribute (category, material, color, size, style, brand, budget, feature, use case or other), and the customer answers by rule. All results below come from the 200 official public sessions.

50,000products

200public sessions

10turns at most

10recommendations per turn at most

### Four kinds of session

40%

#### Buying

The customer states one hard requirement up front.

“I’m looking for shoes. A key requirement is…”

40%

#### Browsing

The need is still vague and the customer is just looking.

“I’m looking at coats, but I’m still exploring.”

15%

#### Intent override

On turn 3 or 4 the customer drops an earlier preference; hits before that don’t count.

“Actually, ignore my earlier preference. What I need is…”

5%

#### Boundary

The first time the agent asks, the customer has no preference and leaves it to the agent.

“I don’t have a preference; please use your judgment.”

### Metrics

TechnicalScore = 0.5 × HR@10 + 0.3 × MRR + 0.2 × Efficiency

- **HR@10**: Whether the target appears in the top 10 in some turn.
- **MRR**: One over the target’s rank in the first turn it appears: rank 1 scores 1, rank 2 scores 0.5.
- **MTTC**: The turn of the first hit, lower is better; a miss counts as 11.
- **Efficiency**: Derived from MTTC: (11 − MTTC) ÷ 10.

## Problems Solved

##### Retrieved, but ranked too low

**What happened**Of the 33 sessions an early version missed, 25 targets had actually been retrieved and sat below rank 10; only one was never retrieved.

**What I changed**I stopped widening recall and worked on ranking: constraint-coverage reranking, a portfolio that protects the top slots, and questions aimed at attributes that actually split the candidates.

##### “$80” matched “80% nylon”

**What happened**The current-message route treated budget numbers as keywords, so “under $80” pushed up products whose material read “80% nylon”.

**What I changed**Budget numbers are removed from the current-message query and handled by dedicated price scoring.

##### Nearly three minutes per run

**What happened**Version 1 took 165 seconds for the 200 sessions; the baseline took 24.

**What I changed**Bounded caches for queries and documents brought it to a steady 70 seconds, with a peak of about 642 MiB.

##### Semantic retrieval didn’t help

**What happened**A TF-IDF plus 96-dimension SVD route took 16.6 seconds to index and peaked at 885 MiB, did nothing for browsing sessions, and lost an override hit.

**What I changed**I removed the route and spent the time on dialogue state and questioning.

## A Conversation

Three turns in the demo interface. The interface is a React demo layer over the same agent that was evaluated.

![Demo turn 1: travel backpack recommendations with a follow-up question](https://www.imranjan.cn/images/projects/shopping-copilot-2026/demo-turn1.png)

Turn 1: category and use case recorded; recommendations plus a question about features.

Turn 1

> I’m exploring travel backpacks for a week away.

The agent reads this as browsing, records the category “backpacks” and the use case “travel”, returns ten candidates and asks which feature matters most. Among the top 60 candidates, feature has the widest coverage and the most even split, so it is the most useful question.

![Demo turn 2: the chest bag whose feature text matches the customer’s words ranks first](https://www.imranjan.cn/images/projects/shopping-copilot-2026/demo-evidence.png)

Turn 2: the top chest bag’s feature text matches the customer’s words exactly.

Turn 2

> For that, what matters is: High-Density And Durable Material: This Chest Bag Is Made Of High-Quality High-Density, Durable Material…

The customer pastes a product description verbatim. The evidence fingerprint index finds the one matching product among more than 220,000 feature strings, and it goes straight to rank 1\. The agent then asks about brand.

![Demo turn 3: the recommendation context panel with active and superseded constraints](https://www.imranjan.cn/images/projects/shopping-copilot-2026/demo-override.png)

Turn 3: the recommendation context panel; struck-out items are superseded constraints.

Turn 3

> Actually, not a backpack but lightweight walking shoes under 80 dollars.

The customer changes their mind. The “not … but” phrasing is read as a category replacement with 0.98 confidence: backpacks, bags and the earlier feature evidence are struck out and “backpack” becomes an exclusion, while the under-$80 budget and the travel use case stay. The recommendations switch to walking shoes. The panel on the right shows the constraint ledger at that moment.

## Engineering

The official evaluation calls only reset() and respond() on starter.agent.Agent. The core uses nothing but the Python standard library and an in-memory SQLite database: no network requests and no model calls, with state isolated per session\_id. The four parts below map to the main modules in the architecture diagram.

##### Constraint ledger

Every requirement carries its attribute, value, source turn, status and confidence. Status is active, superseded or negative, and attributes the customer declined or that are exhausted are tracked separately.

The difference matters: “no preference” retracts the attribute’s condition, while “no additional preference” only stops further questions and keeps what was already said.

[Read the session state](https://github.com/narmi924/shopping-copilot/blob/main/src/shopping%5Fcopilot/state.py)

##### Question value estimator

For each attribute not yet asked or declined, it looks at the top 60 candidates: how many have the attribute, how evenly it splits them, how relevant it is to the current intent, how close the top ten scores are, and how many turns remain.

It asks only when the value is high enough, and still recommends in the same turn. Open “other” questions are capped at two.

[Read the questioning code](https://github.com/narmi924/shopping-copilot/blob/main/src/shopping%5Fcopilot/question%5Fvalue.py)

##### Exact evidence retrieval

The simulated customer repeats product features and details verbatim. The evidence fingerprint index normalizes that text for every product into 228,000 keys, so when the customer quotes it, the product is found directly.

Rarer strings score higher, and keys shared by more than 5,000 products are skipped.

[Read the evidence index](https://github.com/narmi924/shopping-copilot/blob/main/src/shopping%5Fcopilot/evidence.py)

##### Adaptive candidate portfolio

The top of the Top 10 is a precision core ranked by score. When intent is uncertain, the last two or three slots go to candidates covering different features.

Buying gives all ten slots to the core, an override gives 8 plus 2, and browsing 7 plus 3 or 8 plus 2; the clearer the constraints, the fewer exploration slots.

[Read the portfolio code](https://github.com/narmi924/shopping-copilot/blob/main/src/shopping%5Fcopilot/portfolio.py)

### Multi-route retrieval and fusion

Each turn searches several routes separately, merges them with weighted Reciprocal Rank Fusion (rank constant 50), and passes the result to a reranker that scores constraint coverage. On an override turn the current message gets more weight and the strict all-keywords route is switched off.

| Route              | What it uses                                                    | Weight (override turn) |
| ------------------ | --------------------------------------------------------------- | ---------------------- |
| Exact evidence     | Exact matches between the customer’s words and catalog features | 12.0                   |
| Strict match       | Every keyword of the current message                            | 6.0 (off)              |
| Current message    | What was said this turn                                         | 4.5 (6.0)              |
| Active constraints | Conditions still active in the ledger                           | 3.0 (3.2)              |
| Stable context     | Earlier information that wasn’t replaced                        | 1.8 (1.2)              |
| Anonymous profile  | Preference tags and summary                                     | 0.35 (0.20)            |

Full-text search uses SQLite FTS5 with BM25 weighted by field (title, categories, features and so on).

### Tech stack

#### Agent core

Python standard librarySQLite FTS5

#### Demo backend

FastAPI

#### Demo frontend

ReactTypeScriptViteAnt Design

#### Testing and CI

pytestGitHub Actions

The 78 tests cover override phrasings, declined versus exhausted attributes, exact evidence matching, stable ordering in retrieval and fusion, session isolation, and rules such as runtime code never referencing evaluation labels. CI runs the tests on Python 3.10 and 3.13 and checks that official files are unchanged.

## Results

Results on the 200 public sessions with the official evaluator.

__Official 200 public sessions__
| Metric                 | Official baseline | Shopping Copilot |
| ---------------------- | ----------------- | ---------------- |
| Hits                   | 25 / 200          | 188 / 200        |
| Hit Rate@10            | 0.125             | 0.940            |
| MRR                    | 0.068             | 0.646            |
| MTTC (lower is better) | 9.810             | 3.985            |
| TechnicalScore         | 0.107             | 0.804            |

### Hit rate by session type

Buying76 / 80

Browsing77 / 80

Intent override25 / 30

Boundary10 / 10

One evaluation run takes about 70 seconds with a peak of about 642 MiB, no network requests, and zero model tokens or external service cost.

### An LLM reranker I tried and dropped

I wanted to know whether one could pull missed targets into the top 10\. An audit of 400 sessions found that in 10 of 23 misses the target was already in the top 40, which looked promising.

I built a constrained DeepSeek reranker: it saw anonymous IDs for the top 40 candidates, could only reorder them, could never generate a product ID, and any failure fell back to the offline ranking. On 200 synthetic sessions TechnicalScore rose from 0.8366 to 0.8419\. On 800 sessions the gain shrank to 0.001, MRR dropped, buying sessions lost two hits, and only 97.91% of JSON outputs were valid, short of the 99% I required.

A gain that small wasn’t worth the network, key and reliability risk, so the submission stayed fully offline.

- **Experiment cost**: about US$2.08
- **Median response**: 1.19 s
- **Gain on 200 sessions**: +0.0053
- **Gain on 800 sessions**: +0.0010
- **Valid JSON**: 97.91%

## Demo & Submission

The demo video runs about three minutes: the approach and results first, then the three turns above in the local interface.

[![The evaluation results panel in the Shopping Copilot demo](https://www.imranjan.cn/images/projects/shopping-copilot-2026/demo-evaluation.png)Watch the demoOpens on Google Drive](https://drive.google.com/file/d/1wGowJKAkjicNARgGQhL6CxnYbV%5FNhrIA/view?usp=sharing)

[Source code (GitHub)](https://github.com/narmi924/shopping-copilot)
[Devpost submission](https://devpost.com/software/shopping-copilot-by-ki)

## Other pages

- [Home](https://www.imranjan.cn/index.md)
- [About me](https://www.imranjan.cn/about.md)
- [Projects](https://www.imranjan.cn/projects.md)
- [Photography](https://www.imranjan.cn/gallery.md)
- [LCIMS Cloud](https://www.imranjan.cn/projects/p-lcims.md)
- [imranjan.cn](https://www.imranjan.cn/projects/p-portfolio.md)
- [Open-source tools](https://www.imranjan.cn/projects/p-open-source.md)
- [Gatehouse](https://www.imranjan.cn/projects/p-gatehouse.md)
- [PlusOne](https://www.imranjan.cn/projects/p-plusone.md)
- [Gantry](https://www.imranjan.cn/projects/p-gantry.md)
- [BYOF Agent](https://www.imranjan.cn/projects/p-byof-agent.md)
- [Look2Act](https://www.imranjan.cn/projects/p-look2act.md)
- [AccessAudit - On-Chain Access Approval & Audit System](https://www.imranjan.cn/projects/p-accessaudit.md)
- [Eye Touch - Real-time Eye Tracking and Gaze Control System](https://www.imranjan.cn/projects/p-eyetouch.md)
- [China Collegiate Computer Competition—Mobile Application Innovation Contest](https://www.imranjan.cn/projects/p-yigui.md)
- [Nilufar Restaurant Expense Management System](https://www.imranjan.cn/projects/p-nilufar.md)
- [Voice-Interactive LED Light Panel](https://www.imranjan.cn/projects/p-led.md)
- ["Mengsheng Cup" Electronic Design Competition](https://www.imranjan.cn/projects/p-msb.md)
- [NUS SOC SWS 2024](https://www.imranjan.cn/projects/p-nus.md)

中文版本：https://www.imranjan.cn/zh/projects/p-shopping-copilot.md
