This project demonstrates the use of Retrieval-Augmented Generation (RAG) with AutoGen and ChromaDB for enhanced question-answering capabilities.
The main script rag_01.py
sets up a RAG system using AutoGen's agents and ChromaDB as the vector database. It allows for querying information from stored documents, combining the power of large language models with the ability to retrieve relevant context from a knowledge base.
- The script uses a configuration file
OAI_CONFIG_LIST.json
to specify the models and their API endpoints. - Environment variables are loaded from a
.env
file.
- A persistent ChromaDB client is initialized with a specified path.
- A collection named "autogen-yt" is created or retrieved.
- OpenAI's text-embedding-ada-002 model is used for generating embeddings.
- ChromaVectorDB is initialized with the ChromaDB path and the OpenAI embedding function.
Two main agents are created:
a. AssistantAgent:
- Named "assistant"
- Acts as a helpful AI assistant
- Uses the specified LLM configuration
b. RetrieveUserProxyAgent:
- Named "ragproxyagent"
- Handles retrieval of relevant information
- Configured with specific retrieval settings
The RetrieveUserProxyAgent is set up with the following key configurations:
- Task: Question-Answering (qa)
- Document sources: GitHub README and local docs folder
- Chunk token size: 2000
- Vector database: ChromaVectorDB instance
- Collection name: "autogen-yt"
- Embedding function: OpenAI's text-embedding-ada-002
- Context max tokens: 10000
- A sample question is defined: "What are the design goals of autogen studio? Can you go in depth with them?"
- The chat is initiated between the ragproxyagent and the assistant.
- The result is processed to display either the updated context or the final answer.
- The script initializes the necessary components: ChromaDB, embedding function, and vector database.
- Two agents are created: an AssistantAgent for general interaction and a RetrieveUserProxyAgent for handling RAG operations.
- The RetrieveUserProxyAgent is configured to use specific documents as its knowledge base.
- When a query is submitted, the RetrieveUserProxyAgent retrieves relevant information from the vector database.
- This information is then used to augment the context provided to the AssistantAgent.
- The AssistantAgent generates a response based on the augmented context and its own knowledge.
- The final answer or updated context is displayed as the output.
To use this system:
- Ensure all required dependencies are installed.
- Set up the
OAI_CONFIG_LIST.json
with your model configurations. - Create a
.env
file with necessary API keys (e.g., OPENAI_API_KEY). - Run the
rag_01.py
script. - The script will execute the sample query and display the result.
To ask different questions, modify the qa_problem
variable in the script.
This setup demonstrates a basic RAG system. For production use, consider implementing error handling, optimizing retrieval settings, and expanding the knowledge base as needed.