The Cache-Augmented Generation (CAG) System is a FastAPI-based API that leverages preloaded document contexts to answer questions using cache-augmented generation models. The system allows users to upload PDF files, processes them, and then uses those documents' content to answer questions posed by the user. The answers are generated using Gemini AI and can be translated into different languages.
- PDF Upload: Upload multiple PDF files for processing and extraction of text.
- Text Chunking: Split extracted text into chunks for better caching and faster processing.
- Question Answering: Use preloaded contexts to answer questions based on the content of the uploaded PDFs.
- Multilingual Support: Answers can be translated into different languages, including Sinhala.
- Health Check: An endpoint to verify the system's health status.
- Python 3.10 or higher
pip
(Python package installer)- Virtual environment (optional but recommended)
-
Clone this repository:
git clone https://github.com/ShanukaLakshan/Cache-Augmented-Generation.git cd Cache-Augmented-Generation
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up environment variables by creating a
.env
file in the root directory and adding the following variables:GEMINI_API_KEY=your_gemini_api_key_here
-
Run the application:
uvicorn app.main:app --reload
The server will start on
http://127.0.0.1:8000
.
- GET: Returns the health status of the API.
- Response:
{"status": "OK"}
- GET: Returns a welcome message.
- Response:
{"message": "Welcome to the Cache-Augmented Generation API."}
- POST: Uploads one or more PDF files for processing.
- Request: Form data with the files (
files
). - Response: JSON with a summary of the processed files and total chunks.
- GET: Returns the status of document processing, including metadata and processing time.
- POST: Ask a question based on the preloaded context. The system will return the answer using the cache-augmented generation model.
- Request: JSON with
language
andquestion
fields. - Response: JSON with the translated answer.
- POST: Ask a question and receive the answer in Sinhala.
- Request: JSON with
question
. - Response: JSON with the translated answer in Sinhala.
- POST: Clears the cached contexts and session state.
- Response: JSON with a confirmation message.
- Ensure all dependencies are installed correctly by running
pip install -r requirements.txt
. - Verify that the environment variable
GEMINI_API_KEY
is set correctly in the.env
file. - If you encounter any errors, check the logs in the terminal for more details.
This project is licensed under the MIT License - see the LICENSE file for details.