Content
# Tool List
Based on **LangChain + bge-large-zh + Milvus + DeepSeek** for a full-process RAG adaptive question generation system.
Automatically ingest documents from textbooks/question banks, perform semantic search, dynamically generate questions with LLM, and adjust question difficulty in real-time based on student performance.
## Project Structure
config.py---Global configuration (model path, database, API Key)
ingest.py---Knowledge base construction: load documents → split → Embedding →入库(含难度标注)
retriever.py---Semantic search: vectorized query → Milvus similarity search → return results
chain.py---LLM chain: question generation chain + judgment chain
main.py---Main entry: adaptive question generation loop
.env---API Key configuration
requirements.txt---Python dependencies
Dockerfile---Docker containerization
## Workflow
Through ingest.py, load docx documents for Chinese splitting, vectorize with bge-large-zh, and store in Milvus vector database with automatic difficulty level labeling;
runtime main.py retrieves knowledge points from corresponding difficulty range based on current student level,
DeepSeek dynamically generates multiple-choice/fill-in-the-blank questions,
user answers, LLM judges and displays correct answers,
the system automatically adjusts difficulty based on continuous question performance,
forming an adaptive closed loop.
### ① **Local Terminal Mode:**
Document ingestion → Chinese splitting and vectorization → Milvus storage (with difficulty labeling) → main.py adaptive question generation loop →
retrieve based on difficulty → LLM generate questions → user answers → judgment → dynamic difficulty adjustment
### **② MCP Mode (mounted to Dify/Coze etc.):**
mcp_server.py (SSE protocol)
retrieve_knowledge(query, difficulty) → retrieve knowledge points
generate_quiz(query, difficulty) → generate questions
## Tech Stack
| Component | Description |
| ---------------------------------- | ------------------------------------------- |
| **LangChain** | Document loading, splitting, LLM chain orchestration (LCEL pipeline syntax) |
| **bge-large-zh** | Chinese semantic vector model (1024 dimensions) |
| **Milvus Lite** | Local vector database (cosine similarity retrieval) |
| **DeepSeek API** | Large model question generation and judgment (deepseek-v4-flash) |
| **Docx2txtLoader** | Microsoft Word document loading |
| **RecursiveCharacterTextSplitter** | Intelligent Chinese text splitting |
| MCP protocol | RAG capabilities encapsulated as standard tools, can be mounted to Dify/Coze |
| **Docker** | Containerized deployment |
| **Dify** | Open-source intelligent agent platform, MCP tool integration |
## Quick Start
### 1. Install Dependencies
```bash
pip install -r requirements.txt
```
### 2. Configuration
Edit .env file:
DEEPSEEK_API_KEY=sk-your-key
DEEPSEEK_BASE_URL=https://api.deepseek.com
Edit config.py to modify document path and model path
### 3. Build Knowledge Base
```bash
python ingest.py
```
This will load documents → Chinese splitting → vectorization →入库(含难度标注).
### 4. Start Adaptive Question Generation
```bash
python main.py
```
# Start MCP Server Locally:
```bash
python mcp_server.py
```
Listen to http://0.0.0.0:8000, SSE endpoint /sse.
# Mount to Dify:
1. Deploy Dify (Docker Compose):
```bash
git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env
# If you need to change the port, edit EXPOSE_NGINX_PORT=80 in .env
docker compose up -d
```
2. Access http://localhost(), register admin account
3. Create **Agent** application → Tools → **+ Add Tool** → MCP → SSE
Server endpoint URL: http://host.docker.internal:8000/sse or URL: http://your-server-IP:8000/sse
4. If your MCP Server and Dify are on the same server, you can use localhost or host.docker.internal.
If not on the same server, ensure firewall allows port 8000.
5. Agent system prompt suggestion:
You must use retrieve_knowledge and generate_quiz tools to answer questions.
All answers must be based on the content returned by the tools.
Mount to Coze:
============
Coze Bot → Tools → Custom → MCP → Stdio
Command:
```bash
python mcp_server.py
```
(Need to change transport to stdio or deploy to server and use SSE)
Docker Containerization:
==============
### Build Image:
```bash
docker build -t rag-quiz .
```
### Run:
```bash
docker run -p 8000:8000 rag-quiz
```
### Adaptive Difficulty Strategy:
- **3 levels of difficulty**: easy → medium → hard
- **Upgrade condition**: continuously answer 2 questions correctly
- **Downgrade condition**: continuously answer 2 questions incorrectly
- Automatically label difficulty level for each chunk through keyword matching during ingestion
### Customization:
- **Difficulty keywords**: modify ingest.py's DIFFICULTY_KEYWORDS
- **Question generation prompt**: modify chain.py's get_quiz_chain()
- **Adjustment strategy**: modify main.py's _adjust_difficulty()
- **Retrieval number**: modify config.py's TOP_K
Interaction Example:
==========
Adaptive question generation system v1.0
Enter exit to quit | Enter skip to skip this question
--- Current difficulty: easy ---
----------------------
【Question】
...(hidden correct answer question)
Your answer: A
[Correct!]
Correct answer: A
...
--- Statistics: correct 1/1(100%)---
`
## Adaptive Difficulty Strategy
- **3 levels of difficulty**: easy → medium → hard
- **Upgrade condition**: continuously answer 2 questions correctly
- **Downgrade condition**: continuously answer 2 questions incorrectly
- Automatically label difficulty level for each chunk through keyword matching during ingestion