The RAG-based QA System is a question-answering application that leverages Retrieval-Augmented Generation (RAG) to provide accurate and contextually relevant answers. It combines the power of retrieval-based models and generative models to enhance the quality of responses. The system supports file uploads, asking question, and logs management to deliver a seamless user experience.
- Python 3.8 or higher
- Docker (optional, for containerized deployment)
- MongoDB
- Clone the repository:
git clone https://github.com/vahidaskari/RAG-QA-system
- Navigate to the project directory:
cd RAG-QA-system
- Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.lock
Before running the application, copy the .env.sample
file to .env
and update the environment variables based on your setup:
cp .env.sample .env
To start the QA system, use the following command:
fastapi run
Build and run the application using Docker:
docker build -t rag_app .
docker run --rm --name rag-app -p 127.0.0.1:8000:8000 --network host --env-file ./.env -v ./../data:/app/data rag_app
- change the MONGODB_CONNECTION_STRING value to "mongodb://mongodb:27017/" in
.env
file\ - run:
docker compose up
Upload one or more files for processing. Files are saved, and text is extracted to create a document stored in ChromaDB.
- Endpoint:
POST /file
- Description: Uploads multiple files and returns a unique
document_id
to reference the stored documents. - Request:
- Form-data:
documents
(list of files)
- Form-data:
- Response:
{"document_id": "<unique_document_id>"}
- Example:
curl -X POST "http://127.0.0.1:8000/file" -F "[email protected]"
Send a query and receive a response based on the provided document context.
- Endpoint:
POST /chat
- Description: Retrieves context from the document and generates a response using an LLM.
- Request Body:
{ "query": "What is the content of the uploaded file?", "document_id": "<unique_document_id>" }
- Response:
{ "response": "<generated_response>" }
- Example:
curl -X POST "http://127.0.0.1:8000/chat" -H "Content-Type: application/json" -d '{"query":"What is in the file?","document_id":"12345"}'
Retrieve logs or records of interactions with the system.
- Endpoint:
POST /logs
- Description: Fetches logs for a specific document or all logs if no
document_id
is provided (to get all logs, send an empty JSON as body). here, "document_id" refers to mongodb document id (_id) . - Request Body:
{ "document_id": "<optional_document_id>" }
- Response:
- Single log:
{ ...log_data... }
- Multiple logs:
[ ...list_of_log_data... ]
- Single log:
- Example:
curl -X POST "http://127.0.0.1:8000/logs" -H "Content-Type: application/json" -d '{"document_id":"12345"}'