From 6a70a9c7d5164b99d16ab5de0af5ab5aa63c49a1 Mon Sep 17 00:00:00 2001 From: Labriji Saad Date: Tue, 28 May 2024 10:39:05 +0200 Subject: [PATCH] Updated the Readme file --- README.md | 83 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 142390b..aca8637 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,84 @@ # `LLM RAG` - Streamlit RAG Language Model App πŸ€– ## 🌟 Overview -This is a Streamlit app leveraging a RAG (Retrieval-Augmented Generation) Language Model (LLM) with FAISS to offer answers from uploaded markdown files πŸ“‚. The app allows users to upload files, ask questions related to the content of these files, and receive relevant answers generated by the RAG LLM πŸ“š. +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 +## ❓ 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** πŸ“‚: Users can establish their **knowledge base** by uploading **markdown documents**. This forms the foundational data that the app will reference for generating answers. +- **`Setup` Knowledge Base** πŸ“‚: Users can establish their knowledge base by uploading markdown documents. These documents are split into chunks and stored in the knowledge base, forming the reference data used to generate answers. -- **`Explore` Knowledge Base** πŸ”: After setting up the knowledge base, users can browse and manage the uploaded documents. This allows users to ensure that the data is ready for queries. +- **`Explore` Knowledge Base** πŸ”: After setting up the knowledge base, users can browse and manage the uploaded documents. Users also have the option to delete documents. -- **RAG `Query`** πŸ’‘: In this tab, users can pose questions that the app will answer by referencing the content within the knowledge base. The RAG (Retrieval-Augmented Generation) model utilizes both the uploaded documents and the model's own knowledge to generate responses. +- **RAG `Query`** πŸ’‘: In this section, users can ask questions that the app will answer by referencing the content within the knowledge base. The RAG primarily uses the uploaded documents along with the LLM's inherent knowledge to generate responses. -Additionally, the app offers advanced settings to tailor the querying experience: +Additionally, the app offers advanced settings for customization based on user needs:

-- **OpenAI `Embedding Model` Settings**: Users select the desired embedding model for document vectorization. Choices affect the precision of semantic search and the cost per token processed. +- **OpenAI `Embedding Model` Settings**: Users select the desired embedding model for document vectorization. Choices affect the precision of Similarity Search and the cost per token processed. -- **OpenAI `LLM` Settings**: This setting allows users to choose the specific OpenAI language model variant for generating answers. It also displays the associated costs for input and output processing per 1,000 tokens. +- **OpenAI `LLM` Settings**: This setting allows users to choose the specific OpenAI language model variant for generating answers. -- **Model `Temperature`**: Adjusting this parameter influences the creativity of the language model’s responses. A higher temperature may yield more varied and creative outputs, while a lower temperature results in more deterministic and conservative text. +- **Model `Temperature`**: Adjusting this parameter influences the creativity of the language model’s responses. -- **Max `Completion Tokens`**: Users can define the maximum length of the generated response by setting the maximum number of tokens (words and characters) the model should produce. +- **Max `Completion Tokens`**: Users can define the maximum length of the generated response by setting the maximum number of tokens the model should produce. -- **Drop All Documents in `Knowledge Base`**: This functionality is crucial for managing the knowledge base. If users need to clear the database, they can do so by typing a confirmatory command. +- **Drop All Documents in `Knowledge Base`** ## πŸ› οΈ System Architecture The following diagram illustrates the flow of data through the system: ```mermaid graph TD - A[User Files] -->|Read & Process| B[Semantic Database Setup] - B -->|Generate Embeddings & FAISS Index| C[Vector Store] - C -->|Utilize OpenAI's Models| D[Semantic Search] - E[User Query] -->|Vectorization| D - D -->|Select Top Documents| F[Top Documents] - F -->|Include Selected Docs in Context| G[Contextualized Documents] - E -->|Determine Expertise using OpenAI| H[Expertise Area] - H -->|Formulate Prompt| I[Prompt with Context] - G --> I - I -->|Query OpenAI LLM| J[LLM Response] - J -->|Generate Answer| K[Answer] - + 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:#7f7f7f,stroke:#fff,stroke-width:2px - style F 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 H fill:#8fa1b3,stroke:#fff,stroke-width:2px - style I fill:#e07b53,stroke:#fff,stroke-width:2px style J fill:#e07b53,stroke:#fff,stroke-width:2px - style K fill:#e07b53,stroke:#fff,stroke-width:2px + style L fill:#e07b53,stroke:#fff,stroke-width:2px ``` ## Project Structure πŸ—οΈ @@ -98,12 +117,12 @@ To begin using the LLM RAG app, follow these simple steps: Set up your virtual environment using either venv or conda: ``` # Using venv - python -m venv env - source env/bin/activate + python -m venv env_llm_rag + source env_llm_rag/bin/activate # Using conda - conda create --name env_name - conda activate env_name + conda create --name env_llm_rag + conda activate env_llm_rag ``` 3. **Install Dependencies:**