| title | Education Graph RAG |
|---|---|
| emoji | 🎓 |
| colorFrom | blue |
| colorTo | indigo |
| sdk | docker |
| app_port | 7860 |
| pinned | false |
This project is a Gemini-powered RAG chatbot for education platforms. It uses Neo4j AuraDB as both the knowledge graph and vector retrieval layer:
Book -> Chapter -> Chunkgraph structure- Neo4j vector index for semantic retrieval
- Neo4j full-text index for keyword retrieval
- Reciprocal Rank Fusion for hybrid search
- Gemini API for grounded answers
- FastAPI backend and Streamlit chat UI
config.py- environment settingsgraph.py- Neo4j driver and embedding model helpersdata_sources.py- public-domain book manifestingest.py- downloads books, chunks them, embeds them, and writes the graphsearch.py- vector + keyword hybrid retrievalgenerate.py- Gemini prompt and answer generationapi.py- FastAPI backendstreamlit_app.py- Streamlit UIchatbot.py- terminal chatbotapp.py- Neo4j/model connectivity check
pip install -r requirements.txt
cp .env.example .envFill .env with your Neo4j AuraDB credentials and Gemini API key.
The default ingestion downloads public-domain books from Project Gutenberg and stores them as graph nodes with vector embeddings.
python ingest.pyFor a quick smoke test:
python ingest.py --book elements-style --max-chunks-per-book 10To rebuild the graph data created by this project:
python ingest.py --clearuvicorn api:app --reloadHealth check:
curl http://localhost:8000/healthChat:
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"question":"How can I write more clearly?","limit":5}'In a second terminal:
streamlit run streamlit_app.pyThe UI calls the FastAPI backend at http://localhost:8000 by default.
- Embed the user query with
all-MiniLM-L6-v2. - Retrieve vector candidates from Neo4j's
chunk_vectorindex. - Retrieve lexical candidates from Neo4j's
chunk_keywordfull-text index. - Fuse both rankings with Reciprocal Rank Fusion.
- Send the top chunks, with book/chapter graph metadata, to Gemini.
- Return an answer with source citations.
NEO4J_URI=neo4j+s://your-aura-host.databases.neo4j.io
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your_neo4j_password
GEMINI_API_KEY=your_gemini_api_key
GEMINI_MODEL=gemini-2.5-flashOptional tuning:
CHUNK_SIZE_WORDS=220
CHUNK_OVERLAP_WORDS=45
VECTOR_K=12
KEYWORD_K=12
FINAL_K=5
RRF_K=60The project includes containerization files (Dockerfile and start.sh) to run both the FastAPI backend and Streamlit UI in a single container.
- Build the image:
docker build -t education-rag . - Run the container:
docker run -p 7860:7860 --env-file .env education-rag
- Open
http://localhost:7860in your browser.
- Create a new Space on Hugging Face, select Docker as the SDK, and choose the Blank template.
- In the Space's Settings tab, add your credentials as Secrets:
NEO4J_URINEO4J_USERNAMENEO4J_PASSWORDGEMINI_API_KEYGEMINI_MODEL(value:gemini-2.5-flash)
- Clone the Space's Git repository, copy the project files in (do not include
venvor.env), commit, and push.
- Neo4j AuraDB must support vector indexes.
- The first run may download the sentence-transformer model.
--clearonly deletes nodes labeledBook,Chapter,Chunk, orTopic.