基于LLM的教育RAG组件,支持解题、文献分析、知识点答疑
Project description
EduRAG
An LLM-based Retrieval-Augmented Generation (RAG) component for education, supporting problem solving, academic literature analysis, and knowledge Q&A.
Features
- Two RAG Modes: SimpleRAG (simple & efficient) and AgenticRAG (intelligent reasoning)
- Multi-LLM Support: OpenAI GPT series, Google Gemini, Ollama local models
- Multiple Document Formats: PDF, DOCX, DOC, TXT, Markdown
- Teacher Persona Customization: Custom teacher name, subject, grade level, teaching style
- Multi-turn Conversation: Context-aware continuous Q&A
- Vector Store Persistence: Avoid repeated embedding, fast knowledge base loading
Installation
pip install edurag
Install optional dependencies:
# Use AgenticRAG (based on LangGraph)
pip install edurag[agentic]
# Use Google Gemini
pip install edurag[gemini]
# Use Ollama local models
pip install edurag[ollama]
# Install all optional dependencies
pip install edurag[all]
Quick Start
Basic Usage
from edurag import SimpleRAG
# Initialize
rag = SimpleRAG(api_key="your-openai-api-key")
# Load documents
rag.load_documents("textbook.pdf")
# Ask questions
answer = rag.ask("What is the main content of this document?")
print(answer)
Custom Teacher Persona
from edurag import SimpleRAG, TeacherProfile
# Create teacher profile
teacher = TeacherProfile(
name="Mr. Wang",
subject="High School Physics",
grade_level="Grade 12",
teaching_style="Focus on concept understanding, good at explaining abstract principles with real-life examples",
introduction="20 years of teaching experience, physics competition coach"
)
# Initialize RAG
rag = SimpleRAG(
api_key="your-openai-api-key",
teacher_profile=teacher
)
# Load textbooks
rag.load_documents([
"physics_chapter1.pdf",
"mechanics_topics.docx"
])
# Ask - AI will respond as Mr. Wang with his teaching style
answer = rag.ask("Why is the acceleration of free fall constant?")
Using Different LLMs
# OpenAI
rag = SimpleRAG(
api_key="sk-xxx",
llm_provider="openai",
llm_model="gpt-4o"
)
# Google Gemini
rag = SimpleRAG(
api_key="your-google-key",
llm_provider="gemini",
llm_model="gemini-pro"
)
# Ollama local model (no API Key required)
rag = SimpleRAG(
llm_provider="ollama",
llm_model="llama3"
)
Persistent Vector Store
# First time: auto-save vector store
rag = SimpleRAG(
api_key="sk-xxx",
vectorstore_path="./my_knowledge_base"
)
rag.load_documents("./documents/")
# Later: load existing store (skip embedding)
rag = SimpleRAG.from_vectorstore(
vectorstore_path="./my_knowledge_base",
api_key="sk-xxx"
)
AgenticRAG (Intelligent Reasoning)
Suitable for complex problems. The Agent autonomously decides whether to retrieve and supports multi-step reasoning.
from edurag import AgenticRAG, TeacherProfile
teacher = TeacherProfile(
name="Mr. Wang",
subject="High School Physics",
grade_level="Grade 12",
teaching_style="Good at analogies, explains with real-life examples"
)
rag = AgenticRAG(
api_key="sk-xxx",
teacher_profile=teacher
)
rag.load_documents(["physics_textbook.pdf"])
# Agent automatically decides whether to retrieve, supports multi-step reasoning
answer = rag.ask("Compare the similarities and differences of Newton's three laws")
# View reasoning process
result = rag.ask_with_steps("Explain the law of conservation of momentum")
print(result["steps"]) # View Agent's reasoning steps
print(result["answer"]) # Final answer
SimpleRAG vs AgenticRAG:
| Feature | SimpleRAG | AgenticRAG |
|---|---|---|
| Retrieval | Always retrieves | Agent decides |
| Reasoning | Single-step | Multi-step |
| Speed | Faster | Slower |
| Cost | Lower | Higher |
| Use Case | Simple Q&A | Complex analysis |
API Reference
SimpleRAG
Main RAG class providing document loading and Q&A functionality.
Initialization Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str | None | LLM API key |
llm_provider |
str | "openai" | LLM provider: openai/gemini/ollama |
llm_model |
str | "gpt-4o" | Model name |
teacher_profile |
TeacherProfile | None | Teacher persona configuration |
config |
EduRAGConfig | None | Full configuration object |
Methods
load_documents(sources): Load documents into knowledge baseask(question): Ask and get answerask_with_sources(question): Ask and return answer with source documentssearch(query, top_k): Directly search relevant documentsclear_history(): Clear conversation historysave_vectorstore(path): Save vector store
TeacherProfile
Teacher persona configuration class.
from edurag import TeacherProfile
teacher = TeacherProfile(
name="Mr. Li", # Teacher name
subject="Mathematics", # Teaching subject
grade_level="Middle School", # Grade level
teaching_style="...", # Teaching style
introduction="...", # Introduction (optional)
language="English" # Response language
)
EduRAGConfig
Full configuration class for advanced customization.
from edurag import EduRAGConfig
config = EduRAGConfig(
llm_provider="openai",
llm_model="gpt-4o",
api_key="sk-xxx",
temperature=0.7, # Generation temperature
chunk_size=1000, # Document chunk size
chunk_overlap=200, # Chunk overlap
retrieval_top_k=4, # Number of retrieval results
vectorstore_path=None # Vector store path
)
Preset Teacher Templates
from edurag.prompt.teacher_profile import PRESET_TEACHERS
# Available presets
teacher = PRESET_TEACHERS["physics_senior"] # High School Physics
teacher = PRESET_TEACHERS["math_college"] # College Mathematics
teacher = PRESET_TEACHERS["english_junior"] # Middle School English
teacher = PRESET_TEACHERS["chemistry_senior"] # High School Chemistry
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file edurag-0.1.2.tar.gz.
File metadata
- Download URL: edurag-0.1.2.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6ae30b5fe772383c7e513386ecfdd8a7d2cb69c3d9b08375feaf9bdaffdd01a
|
|
| MD5 |
c66c06915e8ced134e5c8c532cb4d5c0
|
|
| BLAKE2b-256 |
8cc48e391bf2a6b50cdde2df5992ce942bb2375c6843655df8ed8c232e49b5b3
|
File details
Details for the file edurag-0.1.2-py3-none-any.whl.
File metadata
- Download URL: edurag-0.1.2-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d358b598f8a87f34d598629caf8252704b934c9b2a33d72575c7cf435807fe0
|
|
| MD5 |
584cb99bcc1c2d49ca7a31d934efc203
|
|
| BLAKE2b-256 |
f318ab6430130182ea388b8c9869900ebdf1f9f55f448c8b5c382ba06d0f99b4
|