Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Format RAG Assistant

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.


Features

  • 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

Tech Stack

  • Python 3.13
  • FastAPI
  • LangChain
  • Google Gemini API
  • ChromaDB
  • Pydantic Settings
  • UV Package Manager

Installation

Clone the Repository

git clone https://github.com/rishurajgit/multi-format-rag.git

cd multi-format-rag

Install Dependencies

uv sync

Environment Variables

Create 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=uploads

Running the Application

uv run uvicorn main:app --reload

The server will start at:

http://127.0.0.1:8000

API Documentation

Swagger UI

http://127.0.0.1:8000/docs

ReDoc

http://127.0.0.1:8000/redoc

API Endpoints

Upload PDF

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
}

Chat

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
    }
  ]
}

Current Workflow

PDF Upload
      │
      ▼
Document Loader
      │
      ▼
Text Splitter
      │
      ▼
Gemini Embeddings
      │
      ▼
ChromaDB
      │
      ▼
Retriever
      │
      ▼
Prompt Template
      │
      ▼
Gemini LLM
      │
      ▼
Answer + Source Citation

Current Limitations

  • 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.

Future Enhancements

  • DOCX support
  • TXT support
  • Markdown support
  • Similarity score threshold
  • Streaming responses
  • Conversation memory
  • Multi-document collections
  • Better citation formatting
  • Docker

Author

Rishu Raj

GitHub: https://github.com/rishurajgit

About

Multi-Format RAG Assistant built with FastAPI, LangChain, Gemini & ChromaDB.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages