Skip to main content
You can also check this cookbook in colab here Star us on Github, join our Discord or follow our X This cookbook walks you through the process of performing graph-based Retrieval-Augmented Generation (RAG) using CAMEL, powered by the advanced Mistral models. Specifically, we’ll utilize the Mistral Large 2 model to extract and structure knowledge from a given content source, and store this information in a Neo4j graph database. Subsequently, we can leverage a hybrid approach, combining vector retrieval and knowledge graph retrieval, to query and explore the stored knowledge. Slide 16_9 - 9.png Screenshot 2024-07-25 at 21.14.27.png

📦 Installation

First, install the CAMEL package with all its dependencies:

🔧 Setup

Import the required modules from CAMEL-AI:

🔑 Setting Up API Keys

For secure access to Mistral AI’s services, we’ll prompt for the API key.
Alternatively, if running on Colab, you could save your API keys and tokens as Colab Secrets, and use them across notebooks. To do so, comment out the above manual API key prompt code block(s), and uncomment the following codeblock. ⚠️ Don’t forget granting access to the API key you would be using to the current notebook.

🗄️ Configuring Neo4j Graph Database

Set up your Neo4j instance by providing the URL, username, and password, here is the guidance, check your credentials in the downloaded .txt file. Note that you may need to wait up to 60 seconds if the instance has just been set up.

🧠 Creating the Model

Set up Mistral Large 2 model using the CAMEL ModelFactory:

🤖 Generate a Knowledge Graph Using CAMEL’s Agent

Set up instances for knowledge graph agent:
Provide an example text input that the knowledge graph agent will process:
Create an element from the text and use the knowledge graph agent to extract node and relationship information:
Add the extracted graph elements to the Neo4j database:

🎉 Now you can go to here to check the knowledge graph built with CAMEL’s Knowledge Graph Agent and Mistral AI’s Mistral Large 2 model!

🗃️ Running Graph RAG with CAMEL

Next we will showcase how to run RAG in a hybrid approach, combining vector retrieval and knowledge graph retrieval, to query and explore the stored knowledge. Set up a vector retriever with local storage and embedding model from Mistral AI:
Provide an example user query:
Retrieve related content using the vector retriever, here we take Mistral AI’s news in the website as example content, you can also set the local file path here:
Parse content from the specified URL and create knowledge graph data:
Create an element from the user query:
Match entities from the query in the knowledge graph storage content:
Combine results from the vector search and knowledge graph entity search:
Set up an assistant agent to answer questions based on the retrieved context:

🌟 Highlights

  • Automated Knowledge Extraction: The Knowledge Graph Agent automates the extraction of entities and relationships, making the process efficient and effective.
  • Mistral AI Integration: This cookbook showcases the integration of Mistral AI’s advanced models, particularly the Mistral Large 2, with CAMEL-AI to create a powerful knowledge graph system.
  • Secure and Scalable: Using CAMEL-AI’s robust architecture and Neo4j for graph storage ensures that the solution is both secure and scalable.
By following this cookbook, you can leverage the cutting-edge capabilities of CAMEL AI and Mistral AI to build sophisticated knowledge graphs, facilitating advanced data analysis and retrieval tasks.