Skip to content

Edge-Intelligence-Lab/ChatDKU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

ChatDKU

πŸŽ“ The First Open-Source Agentic RAG System Designed for Campus Scenarios

English | δΈ­ζ–‡

License Stars Issues Python Next.js

Features β€’ Architecture β€’ Quick Start β€’ Data Ingestion β€’ Contributing


✨ Features

ChatDKU is a DSPy-based Agentic RAG system specifically designed for university campus scenarios, providing intelligent Q&A services.

πŸ€– Agentic RAG Core

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

πŸ” Hybrid Retrieval System

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

πŸŽ“ Campus-Specific Tools

  • 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

πŸ“Š Observability

  • Phoenix Integration: Complete LLM call tracing
  • OpenTelemetry: Standardized monitoring metrics
  • Performance Analysis: Token usage, latency analysis, cost statistics

πŸ— Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        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 Workflow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         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                                              β”‚
β”‚                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

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

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+ (LTS)
  • Redis 7+
  • Docker & Docker Compose (recommended)

Option 1: Docker Deployment (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

Option 2: Local Development

# 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:3000

Configuration

Main 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=6006

πŸ“₯ Data Ingestion

ChatDKU's data ingestion pipeline consists of three stages: Data Collection β†’ Data Processing β†’ Vector Indexing.

Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Data Ingestion Pipeline                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚   Scraper   β”‚     β”‚  Ingestion  β”‚     β”‚   Loading   β”‚               β”‚
β”‚  β”‚             │────▢│             │────▢│             β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚                                                                         β”‚
β”‚   β€’ Website Crawler   β€’ File Parsing      β€’ ChromaDB                   β”‚
β”‚   β€’ Document Collect  β€’ Text Chunking     β€’ Redis BM25                 β”‚
β”‚   β€’ PDF/HTML/...      β€’ Node Generation   β€’ Course DB                  β”‚
β”‚                                                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1. Data Collection (Scraper)

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.pkl

Output directory structure:

./dku_website/
β”œβ”€β”€ domain/
β”‚   └── path/
β”‚       β”œβ”€β”€ index.html
β”‚       └── ...
└── progress.pkl  # Scraping progress record

2. Data Processing (Ingestion)

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 True

Supported file formats: PDF, HTML, CSV, XLSX, DOCX, TXT, Markdown

Output files:

  • nodes.json - All parsed text nodes
  • log.json - Record of processed files

3. Vector Indexing (Loading)

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_collection

Load 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 False

4. Course Data Import

Course 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/syllabi

🌐 Frontend & Backend

Frontend

Tech 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

Backend

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.py

API 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

πŸ“ Project Structure

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

πŸ§ͺ Development Guide

Setup

# 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/ -v

Adding New Tools

See Issue #122 for how to add new tools to the Agent.

Basic steps:

  1. Create tool module in chatdku/core/tools/
  2. Implement tool function returning retrieval results
  3. Register tool in agent.py
  4. Update Planner tool descriptions

πŸ“Š Benchmarks

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.


🀝 Contributing

We welcome all forms of contributions! See CONTRIBUTING.md for details.

Ways to Contribute

  • πŸ› Report Bugs: Submit Issues describing problems
  • πŸ’‘ Feature Suggestions: Submit Feature Requests
  • πŸ“ Improve Documentation: Help improve docs
  • πŸ”§ Submit Code: Submit Pull Requests

Commit Convention

feat: New feature
fix: Bug fix
docs: Documentation update
refactor: Code refactoring
test: Test related
chore: Build/tooling related

πŸ“œ License

This project is licensed under the Apache License 2.0.


πŸ™ Acknowledgements


πŸ“¬ Contact


Made with ❀️ at Duke Kunshan University

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published