Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/labrijisaad/llm-rag

A Streamlit app leveraging a RAG LLM with FAISS to offer answers from uploaded files.
https://github.com/labrijisaad/llm-rag

chatgpt cicd embedding-vectors faiss llm machine-learning mlops openai rag rag-llm streamlit streamlit-webapp

Last synced: 10 days ago
JSON representation

A Streamlit app leveraging a RAG LLM with FAISS to offer answers from uploaded files.

Awesome Lists containing this project

README

        

# `LLM RAG` - Streamlit RAG Language Model App πŸ€–

## 🌟 Overview
This Streamlit app leverages Retrieval-Augmented Generation (RAG) by using OpenAI's Large Language Model (LLM) in conjunction with FAISS, a vector database. The app allows users to upload markdown files πŸ“‚, ask questions related to the content of these files ❓, and receive AI-generated answers based on the uploaded content πŸ“š.

## ❓ How It Works
The LLM RAG Streamlit app is structured into several key areas, each serving a specific function within the application:



- **Setup Knowledge Base** πŸ“‚: Upload markdown documents to establish the knowledge base.
- **Explore Knowledge Base** πŸ”: Browse and manage the uploaded documents.
- **RAG Query** πŸ’‘: Pose questions to receive answers referencing the knowledge base and the model's knowledge.

Additionally, the app offers advanced settings for customization based on user needs:



- **OpenAI Embedding Model Settings**: Select the embedding model for document vectorization.
- **OpenAI LLM Settings**: Choose the OpenAI language model variant for generating answers.
- **LLM Temperature**: Adjust the creativity of the model’s responses.
- **Max Completion Tokens**: Define the maximum length of the generated response.
- **Drop All Documents in Knowledge Base**: Clear the database by typing a confirmatory command.

## πŸ› οΈ System Architecture
The following diagram illustrates the flow of data through the system:

```mermaid
graph TD
A[Markdown Documents] -->|Data Cleaning &
Splitting in Chunks| B[Cleaned Text]
B -->|OpenAI Model
Embedding| C[Document Embeddings]
C -->|Store| D[(Vectorstore)]
D -->|Similarity Search| E[Relevant Documents]

F[User Question] -->|OpenAI Model
Embedding| G[Query Embedding]
G -->|Fetch| D

F --> J[Contextualized Prompt]
E --> J
J -->|OpenAI LLM Model| L[Answer]

subgraph Data Preparation
A
B
end

subgraph Vectorization
C
G
end

subgraph Relevant Documents Retrieval
D
E
end

subgraph LLM Querying
J
L
end

%% Styles
style A fill:#7f7f7f,stroke:#fff,stroke-width:2px
style B fill:#8fa1b3,stroke:#fff,stroke-width:2px
style C fill:#8fa1b3,stroke:#fff,stroke-width:2px
style D fill:#8fa1b3,stroke:#fff,stroke-width:2px
style E fill:#8fa1b3,stroke:#fff,stroke-width:2px
style F fill:#7f7f7f,stroke:#fff,stroke-width:2px
style G fill:#8fa1b3,stroke:#fff,stroke-width:2px
style J fill:#e07b53,stroke:#fff,stroke-width:2px
style L fill:#e07b53,stroke:#fff,stroke-width:2px
```

## Project Structure πŸ—οΈ
The project's main directories are laid out as follows:

```
LLM-RAG/
β”œβ”€β”€ .github/workflows/ # CI/CD pipeline definitions
β”œβ”€β”€ configs/ # Configuration files for the model (model names, pricing..)
β”œβ”€β”€ data/ # Data and indices used by the app (FAISS Knowledge Base)
β”œβ”€β”€ docker/ # Docker related files
β”œβ”€β”€ notebooks/ # Jupyter notebooks for experiments
β”œβ”€β”€ secrets/ # API keys and other secrets (excluded from version control)
β”œβ”€β”€ src/ # Source code for the LLM RAG logic
β”œβ”€β”€ streamlit_app/ # Streamlit app files for the Web Interface
β”œβ”€β”€ tests/ # Test cases for the application
β”œβ”€β”€ .dockerignore # Specifies ignored files in Docker builds
β”œβ”€β”€ .gitignore # Specifies untracked files ignored by git
β”œβ”€β”€ Dockerfile # Dockerfile for building the Docker image
β”œβ”€β”€ Makefile # Make commands for building and running the app πŸ§‘β€πŸ’»
β”œβ”€β”€ README.md # Documentation and instructions
β”œβ”€β”€ requirements.txt # Python dependencies for the project
└── (additional project files and scripts)
```

## πŸš€ Getting Started

To begin using the LLM RAG app, follow these simple steps:

1. **Clone the Repository:**
```
git clone https://github.com/labrijisaad/LLM-RAG.git
```

2. **Create the Environment:**
Set up your virtual environment using either venv or conda:
```
# Using venv
python -m venv env_llm_rag
source env_llm_rag/bin/activate

# Using conda
conda create --name env_llm_rag
conda activate env_llm_rag
```

3. **Install Dependencies:**
Install the required dependencies by

running:
```
pip install -r requirements.txt
```

4. **Set Up OpenAI API:**
Rename the example credentials file to `secrets/credentials.yml` and replace the placeholder key ('sk-xxx') with your actual OpenAI API key. You can obtain your API key by following the instructions provided in the [OpenAI documentation](https://platform.openai.com/docs/quickstart?context=python).
```
rename secrets/credentials-example.yml secrets/credentials.yml
```

5. **Run the Streamlit App:**
Launch the Streamlit app using either the provided Makefile command or directly via the Streamlit CLI:
```
# Using Makefile
make stream

# Or directly
streamlit run streamlit_app/main.py
```
## 🐳 Docker Version

The application is available as a Docker container and can be easily set up and run with a few commands. If you want to run the application using the Docker image from the public registry, ensure that you have a `secrets` directory with the necessary API keys as specified in the `secrets/credentials.yml`.

To pull and run the Docker container:

1. **Pull the Docker Image:**
You can pull the image directly from **Google Artifact Registry** using the following command:
```shell
docker pull europe-west1-docker.pkg.dev/llm-rag-application/llm-rag/llm_rag_app:latest
```

2. **Run the Docker Container:**
After pulling the image, you can run it with:
```shell
docker run -p 8501:8501 -v $(pwd)/secrets:/app/secrets europe-west1-docker.pkg.dev/llm-rag-application/llm-rag/llm_rag_app:latest
```
This command will start the container and mount your **`secrets`** directory for the application to use.

If you prefer to use the **Makefile**, the equivalent commands are provided for convenience:

```shell
# To pull the Docker image
make docker-pull

# To run the pulled Docker image
make docker-run-pulled
```

The Streamlit app will be available at **`http://localhost:8501`** once the container is running.

## 🌐 Connect with me



LinkedIn


GitHub