Adaptive AI tutoring system based on Knowledge Graph-enhanced Retrieval-Augmented Generation (KG-RAG).
Paper: How to build an adaptive AI tutor for any course using KG-RAG (Dong et al., ICEIT 2025, IEEE).
Student query
│
├─► Chat history reuse (MiniLM / embedding similarity ≥ 0.85)
│
├─► RAG: vector similarity over course chunks
│
└─► KGR: knowledge-graph traversal for expanded context
│
▼
DeepSeek-V3 response synthesis
- KG construction — chunk course PDFs (~1,000 tokens), extract
[Entity, Relation, Entity]triples with DeepSeek-V3, save todata/knowledge_graph.xlsx. - Knowledge-Guided Retrieval — embed the query, match KG nodes, traverse neighbors for interconnected context.
- Response synthesis — combine similarity context + KG-expanded context and generate the tutoring answer.
git clone https://github.com/098765d/AI_Tutor.git
cd AI_Tutor
pip install -r requirements.txt
cp config.example.yaml config.yamlEdit config.yaml and add your keys:
llm:
api_key: "" # DeepSeek API key
embeddings:
api_key: "" # DashScope API key (optional — falls back to local MiniLM)Run the app:
streamlit run app.py- Open the sidebar and click Build / Rebuild Course Index (uses PDFs in
pdf/). - Ask questions in the chat box.
- Switch between KG-RAG and Standard RAG to compare modes.
| Key | Purpose |
|---|---|
llm.api_key |
DeepSeek-V3 chat completions |
embeddings.api_key |
Alibaba text-embedding-v2 (paper default) |
kg_rag.chunk_size |
PDF chunk size in words |
kg_rag.kg_hop_depth |
Graph traversal depth for KGR |
kg_rag.chat_history_threshold |
Reuse threshold (default 0.85) |
If DashScope key is empty, embeddings automatically fall back to sentence-transformers/all-MiniLM-L6-v2.
AI_Tutor/
├── app.py # Streamlit UI
├── config.yaml # API keys (gitignored — copy from config.example.yaml)
├── config.example.yaml
├── pdf/ # Bundled course materials
├── src/
│ ├── tutor.py # KG-RAG orchestration
│ ├── knowledge_graph.py # KG build + KGR
│ ├── vector_store.py # RAG retrieval
│ ├── llm.py # DeepSeek client
│ ├── embeddings.py # DashScope / local embeddings
│ ├── documents.py # PDF loading & chunking
│ ├── chat_history.py # History reuse (Fig. 6 in paper)
│ └── export.py # HTML chat export
└── data/ # Generated index files (gitignored)
See LICENSE.