What is RAG? Beginner Friendly Article
│
├── app.py # Command-line interface
├── RestFul-RAG-API.py # API interface using Flask
├── streamlit-RAG-ChatBot.py # User interface using Streamlit
│
├── requirements.txt # List of project dependencies
├── README.md # Project documentation
│
├── .env # Environment variables file (not in version control)
│
├── images/
│ ├── image.png
│ ├── image-1.png
│ └── image-2.png
│
└── helper.py # components
Welcome to the Retrieval-Augmented Generation (RAG) Application! This project is designed to demonstrate the power of RAG by allowing users to generate context-aware responses from both URLs and PDF inputs. We’ve implemented three variants of the application to cater to different use cases: command-line interface, API interface, and user interface.
-
Command-Line Interface (
app.py
):- Easily access RAG functionality from your terminal.
- Supports URL-based input.
-
API Interface (
RestFul-RAG-API.py
):- Exposes API endpoints using Flask for integration into other applications.
- URL-based input support for document retrieval.
-
User Interface (
streamlit-RAG-ChatBot.py
):- A sleek and interactive GUI using Streamlit for ease of use.
- Supports both URL and PDF inputs, perfect for a web-based experience.
- Drag-and-drop functionality for PDFs for seamless input.
- Generation: Powered by Google’s Gemini API, providing rich, context-driven responses.
- Embeddings: Utilizes the BAAI/bge-base-en-v1.5 model for efficient and accurate embeddings.
- Additional Tools:
- LangChain for managing chains and retrieval logic.
- ChromaDB for efficient vector storage and search.
- HuggingFace for leveraging pre-trained models.
- Flask, RestAPI to serve API endpoints.
- Streamlit for the web-based user interface.
Run RAG via the terminal:
python app.py --url <your-url>
python app.py --url https://example.com
Start the Flask API:
python RestFul-RAG-API.py
Access the API endpoint:
- POST:
/url
with URL as payload to create Vector Store Resource.
{
"input": {
"url": "https://medium.com/artical-url"
}
}
- POST:
/query
with query as payload to get response from the model.
{
"input": {
"query": "What are adapters?"
}
}
Launch the Streamlit app:
streamlit run streamlit-RAG-ChatBot.py
You can either:
- Enter a URL for text retrieval, or
- Upload a PDF to retrieve relevant content and generate responses. Example:
While the command-line and API interfaces are designed for URL inputs, the Streamlit GUI brings extra functionality by allowing PDF input. Simply drag and drop your PDF into the interface to retrieve content, ask questions, and receive generated responses. This makes it ideal for document-based workflows.
- Python 3.9+
- Install dependencies:
pip install -r requirements.txt
- Create
.env
file and add your Google Gemini API key and HuggingFace credentials in the.env
file.
GEMINI_API_KEY=your-api-key
HUGGINGFACE_API_KEY=your-api-key
Feel free to fork this repository and contribute! Whether it's improving the UI, optimizing retrieval logic, or integrating new models, contributions are welcome.
This project is licensed under the MIT License.
Enjoy exploring the capabilities of RAG across multiple interfaces!
Thank you for your time.