ChatDKU is a Retrieval-Augmented Generation (RAG) intelligent Q&A system designed for Duke Kunshan University (DKU) faculty and students. The system adopts an Agentic RAG architecture, capable of retrieving relevant content from multi-source data including campus policies, course information, and academic resources, and generating accurate, citable answers through large language models.
- ๐ค Agentic RAG Architecture: Intelligent Agent based on DSPy, supporting multi-round retrieval and reasoning
- ๐ Hybrid Retrieval System: Combines vector retrieval (ChromaDB) and keyword retrieval (Redis BM25)
- ๐ง Intelligent Judging Mechanism: Automatically evaluates retrieval sufficiency, iterative retrieval on demand
- ๐ฌ Conversation Memory Management: Supports long conversation context compression and memory retention
- ๐ Observability: Integrated Phoenix (Arize) for full-chain tracing
- ๐ Flexible Deployment: Supports Agent-Only (CLI) and Full (Web application) modes
flowchart TB
subgraph Frontend["Frontend Layer"]
UI[Next.js Web UI]
end
subgraph Backend["Backend Layer"]
API[Django REST API]
Agent[Core Agent]
end
subgraph AgentCore["Agent Core"]
QR[QueryRewrite<br/>Query Rewriting]
Judge[Judge<br/>Sufficiency Judging]
Synth[Synthesizer<br/>Answer Synthesis]
Memory[ConversationMemory<br/>Conversation Memory]
end
subgraph Retrieval["Retrieval Layer"]
DR[DocumentRetriever<br/>Document Retriever]
VR[VectorRetriever<br/>Vector Retrieval]
KR[KeywordRetriever<br/>Keyword Retrieval]
RR[Reranker<br/>Reranking]
end
subgraph Storage["Storage Layer"]
Chroma[(ChromaDB<br/>Vector Database)]
Redis[(Redis<br/>BM25 Index)]
PG[(PostgreSQL<br/>User Data)]
end
subgraph External["External Services"]
LLM[LLM Server<br/>OpenAI-compatible]
Embed[TEI Server<br/>Embedding Service]
Phoenix[Phoenix<br/>Observability]
end
UI --> API
API --> Agent
Agent --> QR
QR --> DR
DR --> VR
DR --> KR
VR --> Chroma
KR --> Redis
DR --> RR
RR --> Judge
Judge -->|Insufficient| QR
Judge -->|Sufficient| Synth
Synth --> LLM
Agent <--> Memory
Agent --> Phoenix
API --> PG
VR --> Embed
sequenceDiagram
participant User as User
participant Agent as Agent
participant QR as QueryRewrite
participant Retriever as Hybrid Retrieval
participant Judge as Judge
participant Synth as Synthesizer
participant LLM as LLM
User->>Agent: Ask Question
Agent->>QR: Query Rewriting (with history)
QR->>Retriever: Semantic Query + Keyword Query
Retriever->>Retriever: Vector Retrieval + BM25 Retrieval
Retriever->>Retriever: Reranking
Retriever->>Judge: Return Retrieval Results
Judge->>Judge: Evaluate Retrieval Sufficiency
alt Insufficient Retrieval
Judge->>QR: Re-retrieve
else Sufficient Retrieval
Judge->>Synth: Pass Context
Synth->>LLM: Generate Answer
LLM->>User: Stream Answer
end
Agent->>Agent: Update Conversation Memory
| Component | Technology | Version | Purpose |
|---|---|---|---|
| Agent Framework | DSPy | 3.0.3 | LLM programmatic orchestration and optimization |
| Retrieval Framework | LlamaIndex | 0.13.1 | Document indexing and retrieval |
| Vector Database | ChromaDB | 1.0.15 | Semantic vector storage |
| Cache/Index | Redis | 5.2.1 | BM25 keyword index |
| Backend Framework | Django | 5.2.3 | REST API and user management |
| Frontend Framework | Next.js | 15+ | React server-side rendering |
| Task Queue | Celery | 5.5.3 | Asynchronous task processing |
| Observability | Phoenix (Arize) | 11.36.0 | Chain tracing and monitoring |
Implement optimizable LLM programs using DSPy:
- QueryRewrite: Rewrite queries with conversation history
- Judge: Evaluate retrieval result sufficiency (Chain-of-Thought)
- Synthesizer: Generate answers based on context
- ConversationMemory: Intelligently compress conversation history
# Retrieval Pipeline
Vector Retrieval (ChromaDB) + Keyword Retrieval (Redis BM25)
โ
Merge Candidate Documents (top_k=20)
โ
Reranking (Reranker, top_k=5)
โ
Judge SufficiencyImplement closed-loop retrieval through Judge module:
- Insufficient retrieval โ Rewrite query โ Re-retrieve (max 3 rounds)
- Sufficient retrieval โ Proceed to answer generation
- Docker & Docker Compose (recommended)
- Python 3.11+ (local development)
- LLM Service: OpenAI API or compatible service (e.g., sglang, vLLM)
- Embedding Service: TEI (Text Embeddings Inference) or compatible service
Suitable for quick testing, CLI interaction, API integration:
# 1. Clone project
git clone https://github.com/Edge-Intelligence-Lab/ChatDKU.git
cd ChatDKU
# 2. Configure environment variables
cp .env.example .env
# Edit .env file, configure LLM_BASE_URL, LLM_API_KEY, TEI_URL, etc.
# 3. Start services (Redis + ChromaDB + Agent)
docker compose -f docker-compose.agent.yml up --build
# 4. Initialize data
bash scripts/setup_agent_data.sh
# 5. Use CLI interaction
docker compose -f docker-compose.agent.yml exec agent python -m chatdku.core.agent๐ Detailed documentation: Agent-Only Quick Start
Includes frontend, backend, user management, file upload, and other complete features:
# 1. Configure environment variables
cp .env.example .env
# Configure database, Redis, LLM, and other services
# 2. Start complete service stack
docker compose up --build
# 3. Access Web interface
# http://localhost:3005๐ Detailed documentation: Full Version Deployment Guide
| Feature | Agent-Only | Full |
|---|---|---|
| Deployment Time | 5-10 minutes | 30-60 minutes |
| Resource Requirements | 2C4G | 8C16G+ |
| Interaction Method | CLI / API | Web UI |
| User Management | โ | โ |
| File Upload | โ | โ |
| Feedback System | โ | โ |
| Async Tasks | โ | โ (Celery) |
| Use Cases | Testing, Development, Integration | Production Environment |
$ python -m chatdku.core.agent
ChatDKU Agent (type 'quit' to exit)
> Please introduce the core courses of the Data Science major
[Retrieving...]
According to the retrieved course information, the core courses of the Data Science major include:
1. COMPSCI 201 - Data Structures and Algorithms
2. STATS 210 - Probability and Statistical Inference
3. COMPSCI 316 - Database Systems
...
> What are the prerequisites for these courses?
[Retrieving...]
According to the course syllabus:
- COMPSCI 201 requires COMPSCI 101 as prerequisite
- STATS 210 requires MATH 105 or equivalent
...from chatdku.core.agent import Agent
# Initialize Agent
agent = Agent()
# Single-turn conversation
response = agent.query("What is DKU's academic integrity policy?")
print(response)
# Multi-turn conversation
conversation_id = "user_123"
agent.query("Introduce the Computer Science major", conversation_id=conversation_id)
agent.query("What are the tracks in this major?", conversation_id=conversation_id)# Send question
curl -X POST http://localhost:8007/api/chat/ \
-H "Content-Type: application/json" \
-d '{
"message": "What research centers does DKU have?",
"session_id": "session_123"
}'
# Streaming response
curl -X POST http://localhost:8007/api/chat/stream/ \
-H "Content-Type: application/json" \
-d '{"message": "Introduce the Environmental Science major"}' \
--no-bufferSupports multiple document formats:
- ๐ PDF, Word (
.docx), PowerPoint (.pptx) - ๐ Markdown (
.md), Plain text (.txt) - ๐ HTML web pages
# 1. Place documents in data/ directory
cp your_documents/* ./data/
# 2. Run data processing script
cd chatdku/chatdku/ingestion
python update_data.py --data_dir ./data --user_id Chat_DKU -v True
# 3. Load to vector database
python load_chroma.py --nodes_path ./data/nodes.json --collection_name chatdku_docs
# 4. Load to Redis (BM25 index)
python -m chatdku.ingestion.load_redis --nodes_path ./data/nodes.json --index_name chatdku๐ Detailed documentation: Data Import Guide
Key configuration items (.env file):
# LLM Service
LLM_BASE_URL=http://your-llm-server:18085/v1
LLM_API_KEY=your_api_key
LLM_MODEL=Qwen/Qwen3.5-4B
# Embedding Service
TEI_URL=http://your-tei-server:8080
EMBEDDING_MODEL=BAAI/bge-m3
# Vector Database
CHROMA_HOST=chromadb
CHROMA_DB_PORT=8010
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
# Agent Configuration
MAX_ITERATIONS=3 # Maximum retrieval rounds
CONTEXT_WINDOW=4096 # LLM context window
LLM_TEMPERATURE=0.1 # Generation temperature
# Frontend Configuration (Full version)
NEXT_PUBLIC_API_BASE_URL=http://localhost:8007Complete configuration reference: .env.example
- ๐ Agent-Only Quick Start
- ๐ Agent-Only Complete Deployment
- ๐ Full Version Deployment Guide
- ๐ Architecture and Port Documentation
- ๐ Technical Report (English)
- ๐ ๆๆฏๆฅๅ๏ผไธญๆ๏ผ
System integrates Arize Phoenix for full-chain tracing:
# Access Phoenix UI
http://localhost:6006
# View content:
# - Agent execution traces
# - Retrieval result quality
# - LLM call details
# - Performance bottleneck analysis# Docker logs
docker compose logs -f agent
docker compose logs -f backend
# Local logs
tail -f logs/backend_$(date +%Y%m%d).logContributions, issue reports, and suggestions are welcome!
- Fork this repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Submit Pull Request
See: CONTRIBUTING.md
This project is open-sourced under the MIT License - see LICENSE file for details
- Mingxi Li - Project Lead
- Yuxiang Lin - Core Developer
- Cody Qin - Core Developer
- Ningyuan Yang - Core Developer
Thanks to the following open-source projects:
- DSPy - LLM programmatic framework
- LlamaIndex - Data framework
- ChromaDB - Vector database
- Phoenix - LLM observability
- ๐ง Email: theta.lin@yandex.com
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
โญ If this project helps you, please give us a Star!
Made with โค๏ธ by ChatDKU Team