A Retrieval-Augmented Generation (RAG) application built with FastAPI, LangChain, Google Gemini, and ChromaDB. The application allows users to upload PDF documents, generate embeddings, store them in a vector database, and ask natural language questions based on the uploaded content.
- Upload PDF documents
- Validate uploaded files
- Extract text using PyPDFLoader
- Split documents into chunks using RecursiveCharacterTextSplitter
- Generate embeddings using Google Gemini
- Store document embeddings in ChromaDB
- Retrieve relevant document chunks using semantic search
- Generate context-aware answers using Gemini LLM
- Return source citations including:
- Document Name
- Page Number
- Chunk ID
- Interactive API documentation using FastAPI Swagger
- Python 3.13
- FastAPI
- LangChain
- Google Gemini API
- ChromaDB
- Pydantic Settings
- UV Package Manager
git clone https://github.com/rishurajgit/multi-format-rag.git
cd multi-format-raguv syncCreate a .env file in the project root.
Example:
GEMINI_API_KEY=your_api_key
LLM_MODEL=your_Model_name
EMBEDDING_MODEL=your_embedding_model
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
CHROMA_DB_PATH=./chroma_db
UPLOAD_DIR=uploadsuv run uvicorn main:app --reloadThe server will start at:
http://127.0.0.1:8000
Swagger UI
http://127.0.0.1:8000/docs
ReDoc
http://127.0.0.1:8000/redoc
POST
/upload
Uploads a PDF document, extracts text, creates embeddings, and stores the document in ChromaDB.
Example Response
{
"message": "PDF uploaded successfully",
"document_name": "RAG Project 1.pdf",
"total_pages": 3,
"total_chunks": 6
}POST
/chat
Request
{
"question": "What is RAG?"
}Example Response
{
"answer": "RAG stands for Retrieval-Augmented Generation...",
"sources": [
{
"document_name": "RAG Project 1.pdf",
"page": 1,
"chunk_id": 3
}
]
}PDF Upload
│
▼
Document Loader
│
▼
Text Splitter
│
▼
Gemini Embeddings
│
▼
ChromaDB
│
▼
Retriever
│
▼
Prompt Template
│
▼
Gemini LLM
│
▼
Answer + Source Citation
- Currently supports PDF documents only.
- Conversation history is not maintained.
- Retrieval always returns the top matching chunks.
- Multiple document format support (DOCX, TXT, Markdown) is planned.
- DOCX support
- TXT support
- Markdown support
- Similarity score threshold
- Streaming responses
- Conversation memory
- Multi-document collections
- Better citation formatting
- Docker
Rishu Raj
GitHub: https://github.com/rishurajgit