Skip to content

About

No description, website, or topics provided.

Resources

Stars

124 stars

Watchers

0 watching

Forks

Repository files navigation

RAG Agent

Intelligent Q&A and customer-service agent for Douyin shop buyers, combining crm_agent (unified API) and RAG_mode (Streamlit console + knowledge-base retrieval). Target reply latency: about 15 seconds.

Quick Start

cd crm_agent/crm_agent
venv\Scripts\activate
python main.py

Restart Streamlit Manually (Optional)

cd RAG_mode/mode
python -m streamlit run app.py --server.port 7121 --server.headless true

Unified API (Recommended)

All capabilities go through the unified agent endpoint POST /api/v1/chat:

curl -X POST http://localhost:7120/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "message": "How soon will this ship? Is there shipping insurance?",
    "user_id": "buyer_001",
    "session_key": "dy_session_001",
    "buyer_name": "Buyer Li"
  }'

Flow: intent detection → routing → (consultative) RAG retrieval → read chat history → build context → LLM generation (reply_mode: rag / no_hit, etc.; mode / user_tag are deprecated).

Legacy field aliases: talent_id ↔ buyer_name, contact_username ↔ session_key.

Endpoints

Method Path Description
POST /api/v1/chat Primary entry — unified chat
GET /api/v1/health Health check
GET /api/v1/meta Service metadata
GET /console/ IM console (Douyin-style customer-service UI)
GET /docs Swagger interactive docs
GET /redoc ReDoc documentation

Response Format

{
  "data": {
    "mode": "agent",
    "route": "unified_agent",
    "answer": "...",
    "reply_mode": "rag",
    "rag_hit": true,
    "sources": [],
    "history_count": 0,
    "tag_upgrade": null
  },
  "state": {"code": 0, "message": "ok"}
}

Full field reference: API.md (v2.1.0).

Project Structure

RAG_Agent/
├── API.md                   # API documentation
├── services/                # [shared] RAG retrieval, intent routing, core business logic
├── rag/                     # [shared] Knowledge-base ingest pipeline (chunk / load / embed)
├── data/                    # [shared] Knowledge-base documents
├── scripts/                 # [shared] Ingest / test / simulation scripts
├── embedding.py             # [shared] BGE-M3 embedding
├── vectorstore.py           # [shared] Milvus hybrid vector search
├── reranker.py              # [shared] BGE-Reranker re-ranking
├── shared_config/           # [shared] Redis/MySQL session config
├── web/                     # IM console frontend (mounted at /console/)
├── crm_agent/crm_agent/
│   ├── main.py              # API entry :7120
│   ├── settings.py          # System settings
│   ├── app/                 # FastAPI app layer (routes / agent orchestration)
│   ├── config.yaml          # LLM config
│   └── agents.yaml          # Agent definitions
├── RAG_mode/mode/
│   ├── app.py               # Streamlit console (port 7121)
│   └── settings.py          # System settings
└── start_api.bat

After starting the API, open http://localhost:7120/console/ for local integration. When opening the static page alone, pass ?api=http://localhost:7120 to point at the backend.

Streamlit Console (RAG_mode, Optional)

cd RAG_mode/mode
streamlit run app.py

Dependencies

  • D:\Milvus — Milvus Lite vector store (rag_collection, dense + sparse hybrid search)
  • D:\BGE-M3 — Local BGE-M3 embedding model
  • D:\BGE-Reranker-v2-m3 — BGE-Reranker (GPU re-ranking)
  • Redis + MySQL — session state (shared by RAG_mode and crm_agent)
    • Copy repo-root .env.session.example → .env.session and edit that one file
    • Code entry: shared_config/session_store.py
  • API key: set env var DEEPSEEK_KEY (see each subproject’s .env.example)

Knowledge-Base Ingest

# Run from the repository root
python scripts/ingest_bd_docx.py --file "path/to/your_kb.docx"
# Or rebuild the index
python scripts/ingest_documents.py --rebuild

About

No description, website, or topics provided.

Resources

Stars

124 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages