A lightweight Retrieval-Augmented Generation (RAG) API built with FastAPI, ChromaDB, SentenceTransformers embeddings, and Ollama.
The system:
- Ingests
.pdfand.txtfiles fromdata/ - Splits documents into chunks
- Stores embeddings in persistent ChromaDB (
db/) - Answers questions grounded in retrieved context using
llama3via Ollama
- FastAPI backend with
/askendpoint - Local vector store using ChromaDB
- PDF parsing via PyMuPDF (
fitz) - Source citation list in responses
- Docker Compose setup for API + Ollama
DocuMind-RAG/
├── main.py
├── requirements.txt
├── docker-compose.yml
├── DockerFile
├── data/
│ ├── raw_text/
│ └── source_pdfs/
├── db/
└── src/
├── ingest.py
├── query.py
├── schemas.py
└── config.py
- Python 3.11+
- Ollama installed and running (for local non-Docker run)
- Git (optional)
- Clone and enter the repo:
git clone https://github.com/sudeisf/DOCUMIND-RAG.git
cd DOCUMIND-RAG- Create and activate virtual environment:
python -m venv venv
.\venv\Scripts\Activate.ps1python -m venv venv
source venv/Scripts/activate- Install dependencies:
pip install -r requirements.txt- Start Ollama and pull model:
ollama pull llama3
ollama serve-
Add documents to
data/(or subfolders likedata/raw_text/,data/source_pdfs/). -
Ingest documents:
python src/ingest.py- Start API:
python -m uvicorn main:app --reload --host 127.0.0.1 --port 8000- Open docs:
- Swagger UI: http://127.0.0.1:8000/docs
GET /
Response:
{
"message": "Welcome to DocuMind-RAG API"
}POST /ask
Request body:
{
"question": "What does the policy say about retention period?"
}Response body:
{
"answer": "...",
"sources": ["raw_text/policy.txt", "source_pdfs/guide.pdf"]
}curl -X POST "http://127.0.0.1:8000/ask" \
-H "Content-Type: application/json" \
-d '{"question":"Summarize the key points"}'This repo includes docker-compose.yml for two services:
ollamaon port11434apion port8000
Run:
docker compose up --buildThen ingest data inside the API container (first-time / whenever docs change):
docker compose exec api python src/ingest.pyOpen:
- API Docs: http://localhost:8000/docs
db/is persisted and ignored by git except for a placeholder file.- Ingestion uses upsert semantics, so re-ingestion updates existing chunk IDs.
- You may see a transformer load warning like
embeddings.position_ids | UNEXPECTED; this is commonly benign for this embedding setup.
Use keyword args when creating app (already fixed in this repo):
app = FastAPI(title="DocuMind-RAG API", version="1.0")If shell path gets corrupted, temporarily restore path:
export PATH="/usr/bin:/bin:/mingw64/bin:/c/Program Files/Git/cmd:$PATH"- Ensure you ingested files:
python src/ingest.py - Confirm docs exist under
data/ - Ensure Ollama is running and
llama3is available