Update README.md
This commit is contained in:
parent
790d07f149
commit
94125c11a7
147
README.md
147
README.md
@ -1,82 +1,76 @@
|
|||||||
README for Test Dorna
|
# Deploying Agentic RAG Systems to Perform Various Tasks Using LLMs
|
||||||
Overview
|
|
||||||
This repository contains an implementation of a Question-Answering (QA) system leveraging Retrieval-Augmented Generation (RAG) and other advanced techniques like Chroma and LangChain. The system uses a combination of pre-trained models and custom indexing to retrieve context from a set of documents and generate context-aware answers to questions. It also includes a web-browsing agent to fetch real-time information from the web.
|
|
||||||
|
|
||||||
Key Features
|
This repository showcases the implementation of a Retrieval-Augmented Generation (RAG) system for answering questions using large language models (LLMs) and document retrieval. The system integrates document indexing, chunking, and similarity search with advanced language models like `llama3.2` to provide context-aware responses. Additionally, it incorporates a web-browsing agent for retrieving live data.
|
||||||
RAG-based Search: Use FAISS or Chroma to index and retrieve document chunks based on cosine similarity.
|
|
||||||
Answer Generation: Combines document retrieval with large language models (LLM) like llama3.2 to generate coherent answers.
|
|
||||||
Web Browsing Tool: An agent that can scrape the web for up-to-date information.
|
|
||||||
Multilingual: Supports multi-language queries (e.g., Persian).
|
|
||||||
Installation
|
|
||||||
Prerequisites
|
|
||||||
Ensure you have the following libraries installed:
|
|
||||||
|
|
||||||
bash
|
## Table of Contents
|
||||||
Copy
|
- [Overview](#overview)
|
||||||
pip install faiss-cpu sentence-transformers ollama numpy
|
- [Installation](#installation)
|
||||||
pip install langchain chromadb sentence-transformers ollama
|
- [Usage](#usage)
|
||||||
pip install -U langchain-community
|
- [Components](#components)
|
||||||
Libraries
|
- [RAG System](#rag-system)
|
||||||
faiss-cpu: Used for efficient similarity search and clustering.
|
- [Answer Generator](#answer-generator)
|
||||||
sentence-transformers: To embed documents and queries for similarity search.
|
- [Web Browsing Agent](#web-browsing-agent)
|
||||||
ollama: A Python package for interacting with Ollama models.
|
- [Chroma-based RAG](#chroma-based-rag)
|
||||||
langchain: For chaining multiple LLMs and tools in complex workflows.
|
- [Results](#results)
|
||||||
chromadb: A vector store used for Chroma-based RAG.
|
- [License](#license)
|
||||||
numpy: For array manipulation.
|
|
||||||
|
## Overview
|
||||||
|
The project is designed to perform tasks like document-based question answering, real-time information retrieval via web scraping, and context-aware response generation. It leverages multiple techniques:
|
||||||
|
- **RAG (Retrieval-Augmented Generation)**: Uses document indexing and retrieval for question answering.
|
||||||
|
- **Web Browsing**: Fetches live data to answer real-time queries.
|
||||||
|
- **Chroma and FAISS**: Index and retrieve relevant document chunks efficiently.
|
||||||
|
|
||||||
|
The system is multilingual and supports Persian language queries.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
To set up the environment, clone the repository and install the required dependencies:
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/yourusername/agentic-rag-system.git
|
||||||
|
cd agentic-rag-system
|
||||||
|
pip install -r requirements.txt
|
||||||
|
The requirements.txt includes dependencies such as:
|
||||||
|
|
||||||
|
faiss-cpu: For efficient similarity search.
|
||||||
|
sentence-transformers: For embedding models.
|
||||||
|
ollama: For LLM interactions.
|
||||||
|
langchain: For chaining models and agents.
|
||||||
|
chromadb: For Chroma-based document retrieval.
|
||||||
|
Install the additional dependencies for web browsing:
|
||||||
|
|
||||||
|
pip install requests beautifulsoup4
|
||||||
Usage
|
Usage
|
||||||
Initialization
|
Run the following command to execute the main script:
|
||||||
RAG System: The RAG system creates an index or loads an existing one. The system works with multiple document sources (defined in DOCUMENT_PATHS) and splits them into chunks for efficient retrieval.
|
|
||||||
Answer Generator: Uses the RAG system to fetch relevant document chunks based on the question and generates a response using the LLM.
|
|
||||||
Web Browsing Tool: Fetches real-time information from the web using a specific URL.
|
|
||||||
Example Flow
|
|
||||||
Document Processing:
|
|
||||||
|
|
||||||
Chunks are created from documents (e.g., .txt files).
|
|
||||||
The system creates or loads an index to facilitate similarity-based search.
|
|
||||||
Query Execution:
|
|
||||||
|
|
||||||
A list of predefined questions is processed.
|
|
||||||
For each query, the system searches for relevant context and generates a response using the LLM.
|
|
||||||
Running the Main Script
|
|
||||||
To run the script, execute the following:
|
|
||||||
|
|
||||||
bash
|
|
||||||
Copy
|
|
||||||
python main.py
|
python main.py
|
||||||
This will process a set of predefined queries, generate responses using the RAG system, and save the results to a file (e.g., response.txt).
|
The script processes predefined queries using the RAG system and generates answers based on documents and/or live web data.
|
||||||
|
```
|
||||||
|
|
||||||
Agent with Web Browsing
|
# Steps Performed:
|
||||||
The system can use a web browsing agent to fetch live web data. The agent uses the requests and BeautifulSoup libraries to scrape web pages and return content up to 5000 characters.
|
Document Processing: The documents are chunked into smaller segments for efficient retrieval.
|
||||||
|
Index Creation or Loading: An FAISS index or Chroma-based vector store is created or loaded for similarity search.
|
||||||
|
Query Answering: A set of queries is processed, and answers are generated using LLMs, based on the retrieved document chunks or web content.
|
||||||
|
Results are saved in an output file (response.txt or agent_results.txt).
|
||||||
|
|
||||||
Example of using the Agent:
|
## Components
|
||||||
python
|
RAG System
|
||||||
Copy
|
The RAG system includes:
|
||||||
from langchain.agents import Tool, initialize_agent, AgentType
|
|
||||||
|
|
||||||
# Define tools
|
Document Chunking: Splitting large documents into smaller chunks to improve retrieval performance.
|
||||||
tools = [
|
Index Creation: Using FAISS (or Chroma) for indexing the document chunks based on their embeddings.
|
||||||
Tool(
|
Similarity Search: Utilizing cosine similarity for retrieving relevant chunks during query processing.
|
||||||
name="Document_Search",
|
Answer Generator
|
||||||
func=document_search_function, # Function for document search
|
The Answer Generator class interacts with the RAG system to fetch the most relevant document chunks based on a given question. It then uses the LLM to generate a context-aware response.
|
||||||
description="For questions about documents"
|
|
||||||
),
|
|
||||||
Tool(
|
|
||||||
name="Web_Browser",
|
|
||||||
func=web_browser_tool, # Web browsing function
|
|
||||||
description="For fetching live web data"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
# Initialize agent
|
Web Browsing Agent
|
||||||
agent = initialize_agent(
|
The Web Browsing Agent fetches real-time information from the web by scraping web pages. The agent can be used to get live data on current events, statistics, and more.
|
||||||
tools=tools,
|
|
||||||
llm=llama_model, # Use your pre-trained LLM here
|
Chroma-based RAG
|
||||||
agent_type=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION,
|
An alternative RAG implementation using Chroma for storing and querying document embeddings is also included. This utilizes LangChain's Chroma integration for efficient vector store management and querying.
|
||||||
memory=memory_buffer, # Optional: To use conversation memory
|
|
||||||
verbose=True
|
## Results
|
||||||
)
|
The system successfully processes predefined questions and generates responses based on the relevant document context. Additionally, the web-browsing agent retrieves live data for real-time questions, providing a comprehensive, multi-source approach to answering queries.
|
||||||
Results
|
|
||||||
Queries will be processed sequentially, and the results will be saved to the specified output file.
|
|
||||||
|
|
||||||
Example output:
|
Example output:
|
||||||
|
|
||||||
@ -86,13 +80,8 @@ Copy
|
|||||||
چرا اینترنت همراه اول گوشی وصل نمیشود؟
|
چرا اینترنت همراه اول گوشی وصل نمیشود؟
|
||||||
|
|
||||||
پاسخ:
|
پاسخ:
|
||||||
برای حل این مشکل، اول باید اطمینان حاصل کنید که شبکه موبایل شما به درستی فعال است...
|
برای حل این مشکل، ابتدا باید بررسی کنید که شبکه موبایل شما در دسترس است و ...
|
||||||
Customization
|
The system demonstrates effective integration of multiple techniques to solve complex QA tasks.
|
||||||
Document Paths: Modify the DOCUMENT_PATHS list to point to your own documents.
|
|
||||||
Embedding Models: You can change the EMBEDDING_MODEL and LLM_MODEL to other pre-trained models.
|
|
||||||
Chunking Parameters: Modify CHUNK_SIZE and OVERLAP to control the document chunking behavior.
|
|
||||||
License
|
|
||||||
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
||||||
|
|
||||||
Acknowledgements
|
## License
|
||||||
This project leverages LangChain, Ollama, FAISS, and Chroma for building efficient and scalable RAG systems.
|
This project is licensed under the MIT License.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user