Fine-tuned LLM (Qwen2.5-7B) with RAG-powered API for Gamatrain's educational platform.
An AI assistant that:
- Answers questions about Gamatrain's educational content (courses, tests, blogs)
- Uses RAG (Retrieval-Augmented Generation) for accurate, context-aware responses
- Maintains conversation memory for follow-up questions
- Prevents hallucination with similarity threshold checks
| Feature | Description |
|---|---|
| Fine-tuned LLM | Qwen2.5-7B trained on Gamatrain content |
| RAG Integration | LlamaIndex-powered retrieval from 2000+ blogs |
| Anti-Hallucination | Similarity threshold + entity verification |
| Conversation Memory | Remembers context for follow-up questions |
| Educational Format | Structured teaching responses with concept explanation, examples, and comprehension checks |
| OpenAI-Compatible API | Drop-in replacement for OpenAI endpoints |
| Multi-Provider | Supports Ollama (local), Groq, OpenRouter |
| Metric | Value |
|---|---|
| Base Model | Qwen2.5-7B-Instruct |
| Training Dataset | 2,614 samples |
| Domain Data | 2,422 (Gamatrain blogs, tests, courses) |
| General Data | 192 (math, logic, chat - weighted 4x) |
| Output Format | GGUF (4-bit quantized) |
| RAG Test Pass Rate | 92.9% |
gamatrain-ai-research/
βββ api/ # API Server
β βββ llm_server.py # Development server (Ollama)
β βββ llm_server_production.py # Production server (Groq/OpenRouter)
β βββ requirements.txt # Development dependencies
β βββ requirements-production.txt # Production dependencies
β βββ .env.production.example # Environment template
βββ data/ # Training & RAG Data
β βββ custom_docs.json # Custom RAG documents
β βββ gamatrain_final_dataset.jsonl # Final training dataset
β βββ gamatrain_finetune_data.jsonl # Fine-tuning data
β βββ general_knowledge.jsonl # General knowledge samples
β βββ scripts/ # Data processing scripts
βββ model/
β βββ Modelfile # Ollama model configuration
βββ scripts/ # Testing & Utility Scripts
β βββ test_model_and_rag.py # Main test suite
β βββ test_random_blogs.py # Random blog RAG tests
β βββ rebuild_index.py # Index rebuilding utility
βββ notebooks/
β βββ fine-tuning-complete.ipynb # Training notebook (Colab)
βββ docs/ # Documentation
β βββ DEPLOYMENT.md # Basic deployment guide
β βββ PRODUCTION.md # Production deployment guide
β βββ RESEARCH.md # Research findings
β βββ TRAINING.md # Fine-tuning guide
βββ storage/ # RAG Index Storage
β βββ faiss_index.bin # FAISS vector index
β βββ documents.json # Document store
β βββ metadata.json # Index metadata
βββ docker-compose.production.yml # Production Docker setup
βββ Dockerfile.production # Production Docker image
# 1. Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# 2. Import the fine-tuned model
cd model/
# Place qwen2.5-gamatrain.gguf here (see model/README.md)
ollama create gamatrain-qwen -f Modelfile
# 3. Start the API server
cd api/
pip install -r requirements.txt
python llm_server.py
# Server runs on http://localhost:8000Uses cloud LLM providers (Groq is free and fast).
# 1. Setup environment
cd api/
cp .env.production.example .env
# Edit .env and add your GROQ_API_KEY (free at https://console.groq.com)
# 2. Install and run
pip install -r requirements-production.txt
python llm_server_production.py
# Server runs on http://localhost:8001docker-compose -f docker-compose.production.yml up -d| Endpoint | Method | Description |
|---|---|---|
/v1/query |
POST | RAG query with streaming |
/v1/chat/completions |
POST | OpenAI-compatible chat |
/v1/refresh |
POST | Refresh RAG index |
/v1/session/{id} |
DELETE | Clear conversation memory |
/health |
GET | Health check |
# Simple query
curl -X POST http://localhost:8000/v1/query \
-H "Content-Type: application/json" \
-d '{"query": "What is Gamatrain?", "session_id": "user1"}'
# Follow-up question (uses conversation memory)
curl -X POST http://localhost:8000/v1/query \
-H "Content-Type: application/json" \
-d '{"query": "Tell me more about that", "session_id": "user1"}'
# Refresh RAG index (after new content is added)
curl -X POST http://localhost:8000/v1/refresh{
"query": "What is Gamatrain?",
"response": "Gamatrain is an educational technology company...",
"confidence": "high",
"similarity_score": 0.897,
"session_id": "user1"
}| Variable | Default | Description |
|---|---|---|
PROVIDER |
ollama | LLM provider: ollama, groq, openrouter |
GROQ_API_KEY |
- | Groq API key (free tier available) |
GROQ_MODEL |
llama-3.1-8b-instant | Model to use with Groq |
OLLAMA_MODEL |
gamatrain-qwen | Local Ollama model name (Qwen2.5-7B based) |
SIMILARITY_THRESHOLD |
0.45 | RAG confidence threshold |
MAX_TOKENS |
1024 | Maximum response tokens |
PORT |
8000/8001 | Server port |
The system prevents made-up responses through:
- Similarity Threshold - Low-confidence queries return "I don't know"
- Entity Verification - Checks if mentioned entities exist in context
- Strict Prompting - Instructs model to only use provided context
# Main test suite (RAG + Model)
python scripts/test_model_and_rag.py
# Random blog RAG tests
python scripts/test_random_blogs.py- PRODUCTION.md - Production deployment guide (recommended)
- DEPLOYMENT.md - Basic deployment guide
- TRAINING.md - Fine-tuning guide
- RESEARCH.md - Research findings
- β Model Upgrade: Upgraded to Qwen2.5-7B-Instruct for better performance
- β Enhanced Teaching Format: Structured educational response format
- β Fine-tuned model with 2,614 training samples
- β RAG system with 2000+ blog documents
- β Conversation memory and follow-up question handling
- β Anti-hallucination with similarity thresholds
- β Multi-provider support (Ollama, Groq, OpenRouter)
- β Comprehensive test suite with 92.9% pass rate
- β Production-ready Docker deployment
- β Initial release with Qwen2-1.5B model
- β Basic RAG and conversation memory
- π§ Modular architecture with separate components
- π§ Source citation and automatic linking
- π§ Response regeneration endpoint
- π§ Enhanced RAG techniques
- π§ Extended test coverage
Fine-tuning only on domain data caused the model to "forget" basic abilities.
Solution: Mix domain data with general knowledge samples (weighted 4x).
| Before | After |
|---|---|
2 + 2 = 0 β |
2 + 2 = 4 β
|
MIT License