How hoangsyviet04/rag_ecommerce_b2c works
This is a Vietnamese B2C e-commerce sales assistant: the frontend submits a chat request, the API delegates to a chat service, and the intent router selects policy retrieval, product lookup, chitchat, or human handoff. The service loads short-term conversation context, applies response guardrails, and the API schedules SQL chat-history persistence. Separate product capabilities include SQL-to-vector synchronization, document ingestion, and RAG evaluation. Edges follow shown calls or README descriptions; unsampled subsystems are included only where documented.
Main entry points: routes.py API routes · retriever.py Hybrid retriever · chat_service.py Chat service · router.py Intent router
Components 24
User interface
- Chat frontend
frontend/index.html - FastAPI app
src/api/main.py - API routes
src/api/routes.py
Chat orchestration
- Chat service
src/services/chat_service.py - Intent router
src/engine/router.py - LLM generator
src/engine/generator.py - Output guardrails
src/engine/guardrails.py - Chat memory
src/engine/memory.py - Redis cache
Knowledge and retrieval
- Hybrid retriever
src/engine/retriever.py - Vector DB access
src/database/vector_db.py - ChromaDB
data/chroma_db - BM25 index
data/bm25_index.pkl - Document ingestion
src/processing/langchain_ingestion.py - Policy documents
data/raw
Commerce data
- SQL chat history
data/init.sql - Product tools
src/tools/product_tools.py - SQL access
src/database/relational_db.py - SQL Server
data/init.sql - Product sync
src/processing/sync_handler.py
Operations
- RAG evaluation
src/utils/evaluation.py - LangSmith tracing
monitoring/langsmith_tracer.py
Other components
- Customer
- LangSmith
Connections 29
- Customer → Chat frontend: asks
README.md - Chat frontend → FastAPI app: submits chat
README.md - FastAPI app → API routes: mounts routes
src/api/main.py - API routes → Chat service: processes chat
src/api/routes.py - Chat service → Redis cache: reads/writes context
src/services/chat_service.py - Chat service → Intent router: routes query
src/services/chat_service.py - Intent router → LLM generator: generates replies
src/engine/router.py - Intent router → Hybrid retriever: retrieves policy
src/engine/router.py - Intent router → Product tools: dispatches tools
src/engine/router.py - Chat service → Output guardrails: filters reply
src/services/chat_service.py - API routes → Chat memory: saves history
src/api/routes.py - Chat memory → SQL access: writes messages
src/engine/memory.py - SQL access → SQL Server: connects
src/database/relational_db.py - API routes → SQL access: inserts products
src/api/routes.py - Product tools → SQL access: queries products
src/tools/product_tools.py - Product tools → Hybrid retriever: semantic search
src/tools/product_tools.py - Hybrid retriever → Vector DB access: uses vector search
src/engine/retriever.py - Vector DB access → ChromaDB: searches vectors
src/database/vector_db.py - Hybrid retriever → BM25 index: loads keyword index
- Policy documents → Document ingestion: supplies documents
src/processing/langchain_ingestion.py - Document ingestion → ChromaDB: writes embeddings
src/processing/langchain_ingestion.py - Document ingestion → BM25 index: writes index
src/processing/langchain_ingestion.py - API routes → Product sync: schedules sync
src/api/routes.py - Product sync → SQL Server: reads products
src/processing/sync_handler.py - Product sync → ChromaDB: upserts/deletes products
src/processing/sync_handler.py - FastAPI app → LangSmith tracing: enables tracing
src/api/main.py - LangSmith tracing → LangSmith: traces runs
monitoring/langsmith_tracer.py - RAG evaluation → Hybrid retriever: evaluates retrieval
README.md - RAG evaluation → LLM generator: evaluates answers
README.md