π The First Open-Source Agentic RAG System Designed for Campus Scenarios
Features β’ Architecture β’ Quick Start β’ Data Ingestion β’ Contributing
ChatDKU is a DSPy-based Agentic RAG system specifically designed for university campus scenarios, providing intelligent Q&A services.
Unlike traditional RAG systems, ChatDKU adopts an Agentic RAG architecture where the Agent can:
- Autonomous Planning: Automatically decide retrieval strategies based on user queries
- Quality Assessment: Judge module evaluates retrieval results and decides if additional retrieval is needed
- Iterative Retrieval: Supports multi-round retrieval until sufficient context is obtained
- Tool Calling: Extensible tools including SQL queries, API calls, etc.
User Query β Query Rewrite β Retrieval β Judge Assessment β Need More Info?
β β Yes
ββββββββββββββββββββββββββββββββ
β No
Synthesizer β Response
ChatDKU employs a Vector + Keyword hybrid retrieval architecture:
| Retrieval Type | Tech Stack | Characteristics |
|---|---|---|
| Vector Search | ChromaDB + HuggingFace Embeddings | Semantic similarity matching, understands synonyms and context |
| Keyword Search | Redis + BM25 | Exact matching, handles proper nouns and abbreviations |
| Result Fusion | Re-ranking | Combined ranking for improved retrieval accuracy |
- Course Syllabus Query: SQL Agent-based course database queries
- Campus Document Q&A: Supports PDF, Word, PPT, Excel and more
- User Document Upload: Users can upload private documents for Q&A
- Voice Input: Integrated Whisper model for speech-to-text
- Phoenix Integration: Complete LLM call tracing
- OpenTelemetry: Standardized monitoring metrics
- Performance Analysis: Token usage, latency analysis, cost statistics
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ChatDKU System Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Frontend (Next.js) β β
β β β’ Responsive Chat UI β’ Markdown Render β’ Voice Input β β
β β β’ File Upload β’ Dark/Light Theme β’ Mobile Ready β β
β βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ β
β β REST API β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Backend (Django + Flask) β β
β β β’ User Auth β’ Session Mgmt β’ File Processing β β
β β β’ API Routing β’ Streaming β’ STT (Whisper) β β
β βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β DSPy Agent Core β β
β β β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β β
β β βQuery RewriterβββββΆβ Planner βββββΆβ Judge β β β
β β β β β β β β β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββ¬ββββββββ β β
β β β β β
β β βββββββββββββββββββββββββββββββββββββββββββ€ β β
β β β β β β
β β βΌ βΌ β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β β Tools β β Synthesizer β β β
β β β β’ RAG β β β β β
β β β β’ SQL Query β ββββββββββββββββ β β
β β β β’ API Call β β β
β β ββββββββββββββββ β β
β β β β
β βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββΌββββββββββββββββββββββββ β
β βΌ βΌ βΌ β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β ChromaDB β β Redis β β Postgres β β
β β Vectors β β BM25 Idx β β Courses β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Observability (Phoenix) β β
β β LLM Tracing β’ Token Stats β’ Latency Analysis β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agent Processing Flow β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. User Input β
β β β
β βΌ β
β 2. Load Conversation History (Conversation Memory) β
β β β
β βΌ β
β 3. Query Rewriting (Query Rewriter) β
β β’ Fix spelling errors β
β β’ Add conversation context β
β β’ Generate retrieval-optimized query β
β β β
β βΌ β
β 4. Parallel Retrieval β
β ββββ KeywordRetriever (Redis BM25) ββββ β
β β ββββΆ Fusion + Re-rank β
β ββββ VectorRetriever (ChromaDB) βββββββ β
β β β
β βΌ β
β 5. Quality Assessment (Judge) β
β β β
β ββββ Context Sufficient βββΆ Go to Step 6 β
β β β
β ββββ Context Insufficient βββΆ Back to Step 3 β
β (use internal_memory to avoid duplicate retrieval) β
β (max iterations: max_iterations) β
β β β
β βΌ β
β 6. Answer Generation (Synthesizer) β
β β’ Combine retrieved context β
β β’ Reference conversation history β
β β’ Generate structured response β
β β β
β βΌ β
β 7. Conversation Memory Update β
β β’ Summarize current conversation β
β β’ Store to conversation_history β
β β β
β βΌ β
β 8. Return Response to User β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Function | Implementation |
|---|---|---|
| Query Rewriter | Fix spelling, add conversation context | DSPy Module |
| Planner | Plan tool calling strategy (multi-tool) | DSPy Module |
| Judge | Evaluate retrieval quality, decide continuation | DSPy Refine |
| VectorRetriever | Semantic similarity search | ChromaDB + BGE-M3 |
| KeywordRetriever | BM25 keyword search | Redis RediSearch |
| Synthesizer | Generate final answer based on context | DSPy Module |
| Syllabi Tool | SQL Agent for course database queries | Postgres + DSPy |
- Python 3.10+
- Node.js 18+ (LTS)
- Redis 7+
- Docker & Docker Compose (recommended)
# 1. Clone the repository
git clone https://github.com/xxx/ChatDKU.git
cd ChatDKU
# 2. Copy and edit configuration
cp docker/.env.example docker/.env
vim docker/.env # Set LLM API Key, etc.
# 3. Start all services
docker-compose -f docker/docker-compose.yml up -d
# 4. Check service status
docker-compose -f docker/docker-compose.yml ps
# 5. Access the application
# Frontend: http://localhost:3000
# Phoenix: http://localhost:6006# 1. Clone the repository
git clone https://github.com/xxx/ChatDKU.git
cd ChatDKU
# 2. Create Python virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# .venv\Scripts\activate # Windows
# 3. Install Python dependencies
cd chatdku
pip install -e ".[dev]"
# 4. Start Redis
redis-server
# 5. Start backend service
python chatdku/core/agent.py
# 6. Start frontend (new terminal)
cd chatdku/frontend
npm install
npm run dev
# 7. Visit http://localhost:3000Main environment variables (configure in .env file):
# ===== LLM Configuration =====
LLM_PROVIDER=openai # openai / vllm / ollama
LLM_MODEL=gpt-4o # Model name
LLM_URL=https://api.openai.com # API endpoint
LLM_API_KEY=sk-xxx # API Key
# ===== Embedding Configuration =====
EMBEDDING_MODEL=BAAI/bge-m3 # Embedding model
TEI_URL=http://localhost:8080 # TEI service URL (optional)
# ===== Database Configuration =====
REDIS_HOST=localhost
REDIS_PORT=6379
CHROMA_HOST=localhost
CHROMA_PORT=8001
# ===== Observability =====
PHOENIX_PORT=6006ChatDKU's data ingestion pipeline consists of three stages: Data Collection β Data Processing β Vector Indexing.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Ingestion Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Scraper β β Ingestion β β Loading β β
β β ββββββΆβ ββββββΆβ β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β
β β’ Website Crawler β’ File Parsing β’ ChromaDB β
β β’ Document Collect β’ Text Chunking β’ Redis BM25 β
β β’ PDF/HTML/... β’ Node Generation β’ Course DB β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Use async crawler to collect campus website content:
cd scraper
# Install dependencies
pip install -e .
# Run scraper (default: dukekunshan.edu.cn)
python scraper.py
# View scraping report
python report.py -s progress.pklOutput directory structure:
./dku_website/
βββ domain/
β βββ path/
β βββ index.html
β βββ ...
βββ progress.pkl # Scraping progress record
Convert raw files to searchable text nodes:
cd chatdku/chatdku/ingestion
# Incremental update (auto-detect added/deleted files)
python update_data.py \
--data_dir /path/to/data \
--user_id Chat_DKU \
-v TrueSupported file formats: PDF, HTML, CSV, XLSX, DOCX, TXT, Markdown
Output files:
nodes.json- All parsed text nodeslog.json- Record of processed files
Load processed nodes into vector databases:
Load to ChromaDB:
# Production (will reset existing data)
python load_chroma.py
# Testing (recommended)
python load_chroma.py \
--nodes_path /path/to/test/nodes.json \
--collection_name test_collectionLoad to Redis:
# Production
python -m chatdku.chatdku.ingestion.load_redis
# Testing (recommended)
python -m chatdku.chatdku.ingestion.load_redis \
--nodes_path /path/to/nodes.json \
--index_name test_index \
--reset FalseCourse syllabus data is stored in PostgreSQL:
# 1. Create database tables
psql -U chatdku_user -d chatdku_db -f create_table.sql
# 2. Import syllabi from PDF/DOCX
python local_ingest.py --input_dir /path/to/syllabiTech Stack: Next.js 15 + TailwindCSS + shadcn/ui
cd chatdku/frontend
# Development mode
npm install
npm run dev # http://localhost:3000
# Production build
npm run build # Output to out/ directory
# Deployment
sudo rsync -av --delete out/ /var/www/chatdku/Main Features:
- Responsive chat interface for desktop and mobile
- Markdown rendering with code highlighting
- Voice input (calls Whisper service)
- File upload (user private documents)
- Dark/Light theme toggle
Tech Stack: Django REST Framework + Flask
Django Service (Main API):
cd chatdku/django
# Start development server
python manage.py runserver 0.0.0.0:8000
# API Documentation
# http://localhost:8000/api/docs/ (drf-spectacular)Flask Service (Agent + STT):
cd chatdku/backend
# Start Agent service
python agent_app_parellel.py
# Start Speech-to-Text service
python stt_app.pyAPI Endpoints Example:
| Endpoint | Method | Description |
|---|---|---|
/api/chat/ |
POST | Send chat message |
/api/chat/stream/ |
POST | Streaming chat response |
/api/upload/ |
POST | Upload user document |
/api/stt/ |
POST | Speech to text |
/api/sessions/ |
GET | Get session list |
ChatDKU/
βββ chatdku/ # Core Python package
β βββ chatdku/
β β βββ core/ # Agent core
β β β βββ agent.py # Main Agent entry
β β β βββ dspy_classes/ # DSPy components
β β β β βββ query_rewriter.py
β β β β βββ judge.py
β β β β βββ synthesizer.py
β β β β βββ ...
β β β βββ tools/ # Agent tools
β β β βββ rag_tool.py
β β β βββ syllabi_tool/
β β βββ ingestion/ # Data ingestion
β β β βββ update_data.py # Incremental update
β β β βββ load_chroma.py # ChromaDB loader
β β β βββ load_redis.py # Redis loader
β β βββ backend/ # Flask backend
β β β βββ agent_app_parellel.py
β β β βββ stt_app.py
β β βββ django/ # Django API
β β β βββ chatdku_django/
β β βββ frontend/ # Next.js frontend
β β βββ app/
β β βββ components/
β β βββ public/
β βββ pyproject.toml
βββ scraper/ # Website scraper
βββ utils/ # Utility scripts
βββ benchmarks/ # Performance benchmarks
βββ docker/ # Docker configuration
β βββ docker-compose.yml
β βββ .env.example
βββ docs/ # Documentation
βββ LICENSE
βββ README.md
βββ CONTRIBUTING.md
# Install dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run linting
ruff check .
ruff format .
# Type checking
mypy chatdku/
# Run tests
pytest tests/ -vSee Issue #122 for how to add new tools to the Agent.
Basic steps:
- Create tool module in
chatdku/core/tools/ - Implement tool function returning retrieval results
- Register tool in
agent.py - Update Planner tool descriptions
| Metric | Value | Test Conditions |
|---|---|---|
| Time to First Token | ~1.5s | vLLM backend, A100 GPU |
| Retrieval Accuracy | 85%+ | DKU Q&A dataset |
| Context Relevance | 0.82 | RAGAS evaluation |
| End-to-End Latency | ~3s | Average query |
See benchmarks/ directory for details.
We welcome all forms of contributions! See CONTRIBUTING.md for details.
- π Report Bugs: Submit Issues describing problems
- π‘ Feature Suggestions: Submit Feature Requests
- π Improve Documentation: Help improve docs
- π§ Submit Code: Submit Pull Requests
feat: New feature
fix: Bug fix
docs: Documentation update
refactor: Code refactoring
test: Test related
chore: Build/tooling related
This project is licensed under the Apache License 2.0.
- DSPy - Agent framework
- LlamaIndex - RAG tooling
- ChromaDB - Vector database
- Phoenix - LLM observability
- shadcn/ui - UI component library
- GitHub Issues: Submit Issue
- Email: contact@chatdku.edu
- Discord: ChatDKU Community
Made with β€οΈ at Duke Kunshan University