Spaces:
Paused
RAG and Agent-based Q&A System
Table of Contents
- Introduction
- Features
- System Architecture
- Prerequisites
- Installation
- Usage
- API Endpoints
- Frontend Interface
This project implements a sophisticated Question-Answering system that combines Retrieval-Augmented Generation (RAG) with an intelligent agent. The system is designed to answer queries related to NCERT textbooks chapters, specifically focusing on the Sound chapter, while also handling general queries using web search capabilities. Do not: Don't forget to specify your open-ai key in the .env file
The application serves two main functionalities:
- A RAG system that retrieves relevant information from a vector database containing NCERT textbook content.
- An agent-based system that can perform smart actions based on the user's query, including invoking the RAG system when appropriate and using additional tools like web search.
Introduction
This project implements a sophisticated Question-Answering system that combines Retrieval-Augmented Generation (RAG) with an intelligent agent. The system is designed to answer queries related to NCERT textbooks, specifically focusing on the Sound chapter, while also handling general queries using web search capabilities.
The application serves two main functionalities:
- A RAG system that retrieves relevant information from a vector database containing NCERT textbook content.
- An agent-based system that can perform smart actions based on the user's query, including invoking the RAG system when appropriate and using additional tools like web search.
Features
RAG System:
- Utilizes a vector database to store and retrieve relevant information from NCERT textbooks.
- Provides accurate and concise answers to questions related to the Sound chapter.
Intelligent Agent:
- Determines when to use the RAG system based on the query content.
- Incorporates additional tools, including web search for non-textbook related queries.
- Calculates word count of responses when requested.
FastAPI Backend:
- Serves both RAG and Agent functionalities via separate endpoints.
- Ensures efficient and scalable handling of requests.
Gradio Frontend:
- Provides an intuitive user interface for interacting with both the RAG and Agent systems.
- Allows easy testing and demonstration of the system's capabilities.
System Architecture
The system is built using the following key components:
- Vector Store: Stores embeddings of NCERT textbook content for efficient retrieval.
- LangChain: Facilitates the creation of the RAG chain and the agent.
- OpenAI's ChatGPT: Powers the language model for generating responses.
- DuckDuckGo Search API: Enables web search capabilities for the agent.
- FastAPI: Provides the backend API framework.
- Gradio: Creates the frontend user interface.
Installation
- Clone the repository and create a virtual env
python -m venv venv
source venv/bin/activate
2.Install the required packages:
pip install -r requirements.txt
- Setup up .env with all the environment variables
OPEN_API_KEY=your_openai_api_key
UVICORN_HOST = 127.0.0.1
UVICORN_PORT = 7860
SOURCE_DATA = "../pdf_data"
VECTOR_STORE = "../chroma_langchain_db"
Usage
To start the application run:
python3 main_app.py
This will start the FastAPI server and launch the Gradio interface. You can access the Gradio interface by navigating to http://localhost:8000
in your web browser.
API Endpoints
The application exposes two main endpoints:
/rag
(POST): For querying the RAG system- Request body:
{ "question": "Your question here" }
- Response:
{ "answer": "Generated answer" }
- Request body:
/agent
(POST): For interacting with the intelligent agent- Request body:
{ "question": "Your question here" }
- Response:
{ "answer": "Agent's response" }
- Request body:
Frontend Interface
The Gradio interface provides two tabs:
- RAG System: For asking questions related to the NCERT Sound chapter.
- Agent: For general queries, including those that may require web search or other tools.
Users can type their questions in the input box and receive answers in real-time.
RAG System Interface
Agent Interface
API Documentation
The FastAPI automatic interactive API documentation is available at /docs
endpoint: