ecommerce-catalog-agent

ecommerce-catalog-agent

Enables conversational product search and validation for e-commerce catalogs, with hybrid retrieval and live price/stock checks from a database.

Category
访问服务器

README

Ecommerce Catalog Agent

A conversational AI agent that answers product questions over an online store's catalog. It understands natural-language queries, finds matching products via hybrid search, and always reports live price and availability validated against the database.

Built as a tool-calling (ReAct) agent with a strict trust boundary: the model decides what to say and which products to show, but code owns the customer-facing numbers — so a hallucinated or injected price can never reach the user.

Features

  • Hybrid retrieval — BM25 (keyword) + vector embeddings (semantic) + Reciprocal Rank Fusion + cross-encoder reranking. Catches word forms and synonyms that exact matching misses (e.g. "взуття для бігу" → running shoes).
  • Filter-first — hard constraints (price, stock) are applied in SQL to build the candidate set before semantic ranking, avoiding the classic "top-k then filter → zero results" trap.
  • Two sources of truth — PostgreSQL is authoritative for volatile fields (price/stock); the vector index is a search cache only. Price and stock are re-fetched live before every answer.
  • Structured-output contract — the agent finishes by calling present_results with product SKUs + prose; price/stock are filled by code from live SQL. The model has no field to write a number into → containment against hallucination and prompt injection ("attacker needs capability, not just instruction").
  • Bounded agent loop — independent stoppers (max iterations, token budget, latency) plus deterministic, score-based escalation to a human operator (on the reranker confidence, never the model's self-report).
  • Conversation memory — per-session history for multi-turn context.
  • Custom MCP server — the catalog tools are exposed over the Model Context Protocol, so one contract serves the agent, an internal copilot, and Claude Desktop.
  • Multi-channel — a FastAPI /chat service, a Telegram bot via n8n (webhook), and a standalone aiogram bot (long-polling).
  • Eval harness — a golden set scored with Recall@K / MRR to catch retrieval regressions with numbers, not vibes.

Architecture

  Customer channels  (Telegram / web / Claude Desktop)
            │
        [n8n]  webhook intake + routing ── low confidence ──► human operator
            │
        [FastAPI /chat]  models warmed at startup
            │
        [ReAct agent loop]  bounded: max_iter / budget / latency
            │   parse → retrieve → validate → respond
            ▼
        [catalog tools]  (also exposed as a custom MCP server)
          search_products  → hybrid BM25 + vector + rerank, filter-first
          get_live_price / check_stock  → live SQL
            │
   PostgreSQL (price/stock = truth)   +   Chroma (search cache)
            ▲
   n8n schedule: XML feed → parse → upsert → re-embed

Tech stack

Python · FastAPI · OpenAI (LiteLLM-swappable) · PostgreSQL · Chroma · BM25 · sentence-transformers · cross-encoder reranker · custom MCP server · n8n · aiogram

Quick start

pip install -r requirements.txt
cp .env.example .env            # fill OPENAI_API_KEY + PG_*

# create the schema, load the sample feed (builds the hybrid index)
psql -d catalog -f schema.sql
python ingest.py

# ask from the CLI
python agent.py "червоні кросівки до 2000 в наявності"

# or run the HTTP service
uvicorn api:app --port 8000     # → http://localhost:8000/docs

# or the Telegram bot (set TELEGRAM_BOT_TOKEN in .env)
python bot.py

Project layout

File What
agent.py ReAct agent loop, bounded stoppers, structured-output contract
retrieval.py hybrid retrieval (BM25 + vector + RRF + cross-encoder) + confidence scores
catalog_tools.py read-only catalog tools + structured get_facts for live validation
server.py the catalog tools exposed as a custom MCP server
api.py FastAPI /chat service (per-session memory, warmup at startup)
bot.py standalone Telegram bot (aiogram, long-polling)
ingest.py XML feed → PostgreSQL + rebuild the hybrid index
eval.py retrieval eval on a golden set (Recall@K / MRR)
n8n/workflow.json Telegram → /chat → reply + escalation routing

Design notes

  • Why hybrid, not pure vector — vector search alone can't honor exact filters (price/stock) or exact tokens (SKUs, model codes); BM25 + structured SQL cover what embeddings miss.
  • Why the vector index is never the source of price/stock — it's rebuilt on a schedule, so its copy of volatile fields is stale by design; the answer always re-validates against SQL.
  • Why MCP — the catalog tools are reused across consumers (the agent, an internal copilot, Claude Desktop): one contract, many clients.

The sample catalog and prompts are in Ukrainian; the agent replies in the customer's language.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选