In this sample, we will build a chat interface that interacts with an intelligent agent built using the AutoGen AgentChat API and the GraphRAG framework.
The app.py script sets up a chat interface that communicates with an AutoGen assistant agent. When a chat starts, it:
GraphRAG (Graph-based Retrieval-Augmented Generation) is a framework designed to enhance AI systems by providing robust tools for information retrieval and reasoning. It leverages graph structures to organize and query data efficiently, enabling both global and local search capabilities.
Global Search: Global search involves querying the entire indexed dataset to retrieve relevant information. It is ideal for broad queries where the required information might be scattered across multiple documents or nodes in the graph.
Local Search: Local search focuses on a specific subset of the data, such as a particular node or neighborhood in the graph. This approach is used for queries that are contextually tied to a specific segment of the data.
By combining these search strategies, GraphRAG ensures comprehensive and context-sensitive responses from the AI assistant.
To set up the project, follow these steps:
pip install -r requirements.txt
Navigate to this directory and run graphrag init to initialize the GraphRAG configuration. This command will create a settings.yaml file in the current directory.
(Optional) Download the plain text version of "The Adventures of Sherlock Holmes" from Project Gutenberg and save it to input/sherlock_book.txt.
Note: The app will automatically download this file if it doesn't exist when you run it, so this step is optional.
Set the OPENAI_API_KEY environment variable with your OpenAI API key:
export OPENAI_API_KEY='your-api-key-here'
Alternatively, you can update the .env file with the API Key that will be used by GraphRAG:
GRAPHRAG_API_KEY=your_openai_api_key_here
Adjust your GraphRAG configuration in the settings.yaml file with your LLM and embedding configuration. Ensure that the API keys and other necessary details are correctly set.
Create a model_config.yaml file with the Assistant model configuration. Use the model_config_template.yaml file as a reference. Make sure to remove the comments in the template file.
Run the graphrag prompt-tune command to tune the prompts. This step adjusts the prompts to better fit the context of the downloaded text.
After tuning, run the graphrag index command to index the data. This process will create the necessary data structures for performing searches. The indexing may take some time, at least 10 minutes on most machines, depending on the connection to the model API.
The outputs will be located in the output/ directory.
Run the sample by executing the following command:
python app.py
The application will:
OPENAI_API_KEY environment variableinput/ directoryThe agent will automatically select the appropriate search tool (in this case, local search for specific entity information) and provide a detailed response based on the indexed data.
You can modify the hardcoded query in app.py line 79 to test different types of questions: