How cpkee/techjam-conversational-search works
Purpose and execution model
This repository implements and evaluates a turn-based conversational e-commerce search agent. The agent receives an anonymized profile plus customer messages, may ask one structured clarification per turn, and returns up to 10 catalog parent_asin recommendations. It has at most 10 turns to surface the hidden target.
Primary entry points are starter/agent.py (agent implementation) and evaluator/local_evaluator.py (local session simulator and scorer). The submission package mirrors the runtime implementation under submission/agent.py and submission/starter/.
Agent orchestration and session state
Agent.reset() initializes per-session state from the preference profile; Agent.respond() drives each turn, combines incoming language with accumulated state, decides whether/how to clarify, and emits the API-contract response.
Core orchestration and state boundaries:
• starter/agent.py
• starter/slot_state.py
• starter/profile_store.py
State is session-scoped: profile-derived preferences, extracted conversational slots, prior questions, and retrieval context must not leak between session IDs.
Intent extraction, slot schema, and clarification policy
The agent converts user utterances into normalized product constraints such as category, material, color, size, style, brand, budget, feature, and use case. A fixed schema constrains both extracted fields and the evaluator-facing ask_attribute value.
Clarification logic selects an unresolved, high-value field and produces a natural-language question. Policy must balance information gathering against early recommendation because successful Top-10 results end sessions.
Relevant components:
• starter/clarify.py
• starter/slot_schema.py
• starter/policy.py
Retrieval and catalog access
Candidate generation operates over the local 50,000-product catalog, keyed by parent_asin. The catalog index supports lexical/catalog-field retrieval, while dense retrieval embeds user intent and catalog text for semantic browsing-style requests. Candidate IDs are subsequently available for ranking and response serialization.
Key paths:
• starter/catalog_index.py
• starter/embeddings.py
• data/catalog.bge_embeddings_ids.json
The full catalog (data/catalog.jsonl) is an externally downloaded runtime asset, not present in this tree. Embedding vectors are cached locally; first use may generate data/catalog.bge_embeddings.npy.
Fusion and ranking stages
The system combines retrieval signals and applies a ranking layer to produce the final bounded recommendation list. Fusion is the boundary between candidate generators and rank ordering; rank output must preserve exact catalog parent_asin IDs.
Core paths:
• starter/fusion.py
• starter/rankllm.py
• starter/stage2.py
This multi-stage design permits cheap broad retrieval before more selective model-assisted ranking.
Model and service dependencies
The runtime uses Python 3.10+, NumPy, PyTorch, and Transformers. Dense embeddings default to Hugging Face model BAAI/bge-small-en-v1.5, using Apple MPS when available or CPU otherwise.
LLM-backed extraction/ranking/response behavior calls a locally served Ollama API at http://localhost:11434/api/chat, with qwen3:8b configured by the agent. Service failures are handled as no-op/fallback behavior rather than evaluator crashes.
Integration boundary:
• starter/ollama_client.py
• starter/embeddings.py
• starter/agent.py
Evaluation and delivery boundary
The deterministic evaluator reads released sessions, invokes the Agent API turn-by-turn, validates/scorers recommendations, and writes aggregate/per-session results. It measures Hit Rate@10, MRR, and mean time to conversion; private sessions are held externally.
Key paths:
• evaluator/local_evaluator.py
• data/public_set.jsonl
• docs/agent_api_contract.json
For delivery, submission/agent.py and its copied submission/starter/ package form the portable submission artifact; changes intended for grading must be reflected there if submission packaging is used.
Main entry points: agent.py Agent API · embeddings.py Dense retrieval · rankllm.py LLM ranker · fusion.py Signal fusion
Components 18
Agent runtime
Turn-based session orchestration and decision policy.
- Agent API · Resets sessions and produces one contract response per turn.
starter/agent.py - Profile store · Holds profile-derived preferences by session.
starter/profile_store.py - Slot state · Tracks extracted constraints, prior questions, and retrieval context.
starter/slot_state.py - Slot schema · Constrains normalized slots and ask_attribute values.
starter/slot_schema.py - Clarification builder · Builds a natural-language question for an unresolved field.
starter/clarify.py - Turn policy · Balances clarification against early recommendation.
starter/policy.py
Retrieval and ranking
Catalog candidate generation through final Top-10 ordering.
- Catalog index · Searches catalog fields and parent_asin candidates.
starter/catalog_index.py - Embedding ID map · Maps cached catalog vectors to catalog IDs.
data/catalog.bge_embeddings_ids.json - Dense retrieval · Embeds intent and catalog text for semantic requests.
starter/embeddings.py - Signal fusion · Combines lexical and dense candidate signals.
starter/fusion.py - LLM ranker · Selectively reranks fused candidates.
starter/rankllm.py - Final ranking · Produces bounded recommendations with exact parent_asin IDs.
starter/stage2.py
Local model dependencies
Optional semantic and LLM capabilities with fallbacks.
- Ollama chat API · qwen3:8b extraction, ranking, and response support; failures fall back.
starter/ollama_client.py - BGE embedding model · BAAI/bge-small-en-v1.5 runs on MPS or CPU.
starter/embeddings.py
Evaluation and delivery
Local scoring and portable grading artifact.
- Local evaluator · Runs released sessions, validates outputs, and scores results.
evaluator/local_evaluator.py - Public sessions · Released turn-by-turn evaluation set.
data/public_set.jsonl - Agent API contract · Defines evaluator-facing response requirements.
docs/agent_api_contract.json - Submission artifact · Mirrors the agent runtime for grading delivery.
submission/agent.py
Connections 22
- Local evaluator → Agent API: invokes turns
- Public sessions → Local evaluator: released sessions
- Agent API contract → Local evaluator: validates
- Agent API contract → Agent API: response contract
- Agent API → Profile store: initializes
- Agent API → Slot state: updates per turn
- Slot schema → Slot state: constrains slots
- Agent API → Turn policy: chooses action
- Turn policy → Clarification builder: requests question
- Clarification builder → Slot schema: uses ask field
- Agent API → Catalog index: retrieves candidates
- Agent API → Dense retrieval: semantic retrieval
- Dense retrieval → Embedding ID map: loads ID mapping
- Dense retrieval → BGE embedding model: embeds intent
- Catalog index → Signal fusion: lexical candidates
- Dense retrieval → Signal fusion: dense candidates
- Signal fusion → LLM ranker: fused candidates
- LLM ranker → Final ranking: rerank signal
- Final ranking → Agent API: Top-10 parent_asins
- Agent API → Ollama chat API: extraction and response
- LLM ranker → Ollama chat API: LLM ranking
- Submission artifact → Agent API: mirrors runtime