Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VLearn - RAG System with FastAPI & Groq

This project is a Retrieval-Augmented Generation (RAG) System built using FastAPI and Groq's LLM. It enables users to:

  • Ingest PDF documents into a vector database (ChromaDB).
  • Query the database using natural language.
  • Retrieve relevant document chunks and metadata.
  • Generate AI-powered responses using Groq's LLM.

📌 Features

  • FastAPI-based API for querying documents.
  • Document ingestion system for processing PDFs.
  • ChromaDB integration for storing and retrieving vectorized documents.
  • Groq AI-powered responses based on retrieved document context.
  • Metadata filtering for refining document retrieval (class, subject, chapter).
  • Poetry for package management to ensure a clean and isolated environment.

📦 Installation

1. Clone the Repository

git clone https://github.com/your-repo/rag-system.git
cd rag-system

2. Install Poetry (if not installed)

pip install poetry

3. Install Dependencies

poetry install

4. Set Up Environment Variables

Create a .env file and add the following variables:

GROQ_API_KEY=your_groq_api_key
VECTOR_DB_PATH=path_to_your_vector_database
LLM_MODEL=model_name

🚀 Running the Application

create the /data directory in app directory upload all the pdfs required -name the pdf in this format classX_subject_chapterY (ex:class10_hist_C1)

after that run the script- ingestion.py using the command

python -m app.ingestion 

Start the FastAPI Server

poetry run uvicorn app.main:app --reload

The API will be available at: http://127.0.0.1:8000


📜 API Endpoints

1️⃣ Home Route

  • URL: /
  • Method: GET
  • Description: Returns a welcome message.
  • Example Response:
{
  "message": "Welcome to the Groq-based RAG API"
}

2️⃣ Query Documents

  • URL: /query
  • Method: GET
  • Description: Queries the vector database to retrieve relevant documents and generates a response using Groq.
  • Query Parameters:
    • q (string) - The query text.
    • class_name (string, optional) - Filter by class (e.g., "Class 8").
    • subject (string, optional) - Filter by subject (e.g., "Geo").
    • chapter (string, optional) - Filter by chapter (e.g., "Chapter 1").
  • Example Request:
curl -X 'GET' 'http://localhost:8000/query?q=What is global warming?&class_name=Class 8&subject=Geo'
  • Example Response:
{
  "query": "What is global warming?",
  "response": "Global warming refers to the long-term increase in Earth's average temperature...",
  "metadata": [{"class": "Class 8", "subject": "Geo", "chapter": "Chapter 3"}]
}

3️⃣ Ingest Documents

  • URL: /ingest
  • Method: POST
  • Description: Ingests all PDFs from the specified folder and stores them in the vector database.
  • Body Parameters:
    • folder_path (string) - Path to the folder containing PDFs.
  • Example Request:
curl -X 'POST' 'http://localhost:8000/ingest' -H 'Content-Type: application/json' -d '{"folder_path": "/path/to/pdf/folder"}'
  • Example Response:
{
  "message": "Documents from /path/to/pdf/folder have been successfully ingested into the vector database."
}

📂 Project Structure

rag-system/
│── app/
│   ├── main.py          # FastAPI application
│   ├── retrieval.py     # Handles document retrieval from ChromaDB
│   ├── ingestion.py     # Processes PDF documents and stores vectors
│   ├── config.py        # Configuration settings
│   ├── logger.py        # Logging setup
│── data/                # Stores the vector database
│── requirements.txt     # Python dependencies
│── README.md            # Project documentation
│── pyproject.toml       # Poetry dependency manager

🛠 Troubleshooting

1. Poetry Not Found?

If you get a command not found: poetry error, ensure you have added Poetry to your PATH:

export PATH="$HOME/.local/bin:$PATH"

2. Invalid Folder Path for Ingestion?

Ensure the folder contains valid PDFs and is accessible.

ls /path/to/pdf/folder

3. Groq API Key Issues?

  • Ensure your GROQ_API_KEY is valid and correctly set in .env.
  • If using a remote server, check network permissions.

📌 Future Improvements

  • 📝 Improve metadata handling in retrieval.
  • 🚀 Optimize embeddings for faster queries.
  • 🤖 Enhance AI responses using fine-tuned models.

🚀 Now you're ready to use the RAG system! 🎉

About

A RAG-based AI system using FastAPI, ChromaDB, and Groq LLM to ingest PDFs, retrieve relevant content, and generate context-aware answers.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages