An open API service indexing awesome lists of open source software.

https://github.com/chitrakumarsai/rag_app

This is a full-stack web application that enables users to upload documents, query an index built from those documents and retrieve responses powered by a Large Language Model (LLM) using Retrieval-Augmented Generation (RAG).
https://github.com/chitrakumarsai/rag_app

docker flask generative-ai llama-index llm openai react retrival-augmented-generation

Last synced: 3 months ago
JSON representation

This is a full-stack web application that enables users to upload documents, query an index built from those documents and retrieve responses powered by a Large Language Model (LLM) using Retrieval-Augmented Generation (RAG).

Awesome Lists containing this project

README

          

# RAG-Based LLM Full-Stack Application

This is a full-stack web application that enables users to upload documents, query an index built from those documents and retrieve responses powered by a Large Language Model (LLM) using **Retrieval-Augmented Generation (RAG)**.


## The application consists of:

* **Frontend**: A React-based user interface.

* **Backend**: A Flask API server that interacts with the index server.

* **Index Server**: A Python-based service managing document indexing and query processing using LlamaIndex.

## Features

* Upload files to build an index.

* Query the indexed documents using natural language.

* Retrieve results with relevant context provided by LlamaIndex.

## Technologies Used

### **Backend**

* Python 3.11

* **Flask:** For serving API requests.

* **Flask-CORS:** For cross-origin requests.

* **LlamaIndex:** To manage document indexing and querying.

### **Frontend**
* **React:** For building the user interface.

* **Bootstrap:** For styling the application.

## Deployment

**Docker:** For containerizing and deploying the application.

## Project Structure

```
RAG_APP/
├── backend/ # Backend Flask application
│ ├── app.py # Flask API server
│ ├── index_server.py # Index server for LlamaIndex
│ ├── requirements.txt # Backend dependencies
├── frontend/ # React frontend
│ ├── src/ # Source code for the frontend
│ ├── Dockerfile # Dockerfile for frontend
│ ├── package.json # Frontend dependencies
├── data/ # Directory for uploaded files
├── storage/ # Directory for storing index files
├── .env # Environment variables
├── docker-compose.yml # Docker Compose configuration
└── README.md # This README file
```
## Installation and Setup

## Prerequisites

* Docker and Docker Compose installed on your machine.

* An OpenAI API Key (required for LlamaIndex).

## Environment Variables

* Create a `.env` file in the project root and include your OpenAI API key:

* `OPENAI_API_KEY=your_openai_api_key`

## Steps to Run the Application

* Clone the Repository:

* `git clone `

* `cd RAG_APP`

## Build and Start the Containers:

* `docker-compose up --build`

## Access the Application:

* **Frontend:** `http://localhost:3000`

* **Backend (API):** `http://localhost:5001`

## API Endpoints

### Query Index

* **URL:** `/query`

* **Method:** `GET`

* **Parameters:** `text` (required): The query string.

#### Example:

```
curl "http://localhost:5001/query?text=What%20is%20a%20transformer"
```
## Upload File

* **URL:** `/uploadFile`

* **Method:** `POST`

* **Parameters:** `file` (required): The file to upload.

## Example:

```
curl -X POST -F "file=@example.txt" http://localhost:5001/uploadFile
```
## Frontend Features

* **Upload Document:** Use the "Upload File" button to add documents to the index.

* **Query Index:** Enter your query in the text box and press "Submit Query" to retrieve results.

Troubleshooting

## Common Issues

#### Port Conflicts:

* Ensure ports 3000, 5001, and 5602 are not in use.

* Update `docker-compose.yml` or application code to use alternative ports if needed.

#### Timeout Connecting to index_server:

* Verify that the `index_server` is running and accessible on port 5602.

#### Check Docker logs for errors:

* docker-compose logs index_server

#### Empty Replies from Server:

* Check if `.env` contains a valid OpenAI API key.

* Ensure the `index_server` is initialized with documents in the `/app/data` directory.

## Development

### Backend

* Install dependencies:

`pip install -r backend/requirements.txt`

* Run the Flask API server:

`python backend/app.py`

### Frontend

* Install dependencies:

`cd frontend`

`npm install`

* Start the React development server:

`npm start`

## Contributing

### Contributions are welcome! Please follow these steps:

* Fork the repository.

* Create a new branch for your feature or bug fix.

* Submit a pull request with a detailed explanation of your changes.

### License

This project is licensed under the MIT License. See the LICENSE file for details.