|
| 1 | +# RAG Chatbot |
| 2 | + |
| 3 | +This directory contains the RAG (Retrieval-Augmented Generation) Chatbot example for the Atomic Agents project. This example demonstrates how to build an intelligent chatbot that uses document retrieval to provide context-aware responses using the Atomic Agents framework. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +1. Document Chunking: Automatically splits documents into manageable chunks with configurable overlap |
| 8 | +2. Vector Storage: Uses ChromaDB for efficient storage and retrieval of document chunks |
| 9 | +3. Semantic Search: Generates and executes semantic search queries to find relevant context |
| 10 | +4. Context-Aware Responses: Provides detailed answers based on retrieved document chunks |
| 11 | +5. Interactive UI: Rich console interface with progress indicators and formatted output |
| 12 | + |
| 13 | +## Getting Started |
| 14 | + |
| 15 | +To get started with the RAG Chatbot: |
| 16 | + |
| 17 | +1. **Clone the main Atomic Agents repository:** |
| 18 | + ```bash |
| 19 | + git clone https://github.com/BrainBlend-AI/atomic-agents |
| 20 | + ``` |
| 21 | + |
| 22 | +2. **Navigate to the RAG Chatbot directory:** |
| 23 | + ```bash |
| 24 | + cd atomic-agents/atomic-examples/rag-chatbot |
| 25 | + ``` |
| 26 | + |
| 27 | +3. **Install the dependencies using Poetry:** |
| 28 | + ```bash |
| 29 | + poetry install |
| 30 | + ``` |
| 31 | + |
| 32 | +4. **Set up environment variables:** |
| 33 | + Create a `.env` file in the `rag-chatbot` directory with the following content: |
| 34 | + ```env |
| 35 | + OPENAI_API_KEY=your_openai_api_key |
| 36 | + ``` |
| 37 | + Replace `your_openai_api_key` with your actual OpenAI API key. |
| 38 | + |
| 39 | +5. **Run the RAG Chatbot:** |
| 40 | + ```bash |
| 41 | + poetry run python rag_chatbot/main.py |
| 42 | + ``` |
| 43 | + |
| 44 | +## Components |
| 45 | + |
| 46 | +### 1. Query Agent (`agents/query_agent.py`) |
| 47 | +Generates semantic search queries based on user questions to find relevant document chunks. |
| 48 | + |
| 49 | +### 2. QA Agent (`agents/qa_agent.py`) |
| 50 | +Analyzes retrieved chunks and generates comprehensive answers to user questions. |
| 51 | + |
| 52 | +### 3. ChromaDB Service (`services/chroma_db.py`) |
| 53 | +Manages the vector database for storing and retrieving document chunks. |
| 54 | + |
| 55 | +### 4. Context Provider (`context_providers.py`) |
| 56 | +Provides retrieved document chunks as context to the agents. |
| 57 | + |
| 58 | +### 5. Main Script (`main.py`) |
| 59 | +Orchestrates the entire process, from document processing to user interaction. |
| 60 | + |
| 61 | +## How It Works |
| 62 | + |
| 63 | +1. The system initializes by: |
| 64 | + - Downloading a sample document (State of the Union address) |
| 65 | + - Splitting it into chunks with configurable overlap |
| 66 | + - Storing chunks in ChromaDB with vector embeddings |
| 67 | + |
| 68 | +2. For each user question: |
| 69 | + - The Query Agent generates an optimized semantic search query |
| 70 | + - Relevant chunks are retrieved from ChromaDB |
| 71 | + - The QA Agent analyzes the chunks and generates a detailed answer |
| 72 | + - The system displays the thought process and final answer |
| 73 | + |
| 74 | +## Customization |
| 75 | + |
| 76 | +You can customize the RAG Chatbot by: |
| 77 | +- Modifying chunk size and overlap in `config.py` |
| 78 | +- Adjusting the number of chunks to retrieve for each query |
| 79 | +- Using different documents as the knowledge base |
| 80 | +- Customizing the system prompts for both agents |
| 81 | + |
| 82 | +## Example Usage |
| 83 | + |
| 84 | +The chatbot can answer questions about the loaded document, such as: |
| 85 | +- "What were the main points about the economy?" |
| 86 | +- "What did the president say about healthcare?" |
| 87 | +- "How did he address foreign policy?" |
| 88 | + |
| 89 | +## Contributing |
| 90 | + |
| 91 | +Contributions are welcome! Please fork the repository and submit a pull request with your enhancements or bug fixes. |
| 92 | + |
| 93 | +## License |
| 94 | + |
| 95 | +This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details. |
0 commit comments