From: aidotengineer
Graph RAG (Retrieval-Augmented Generation) workflows aim to reduce the complexity associated with traditional graph RAG systems [00:00:07]. This approach combines concepts from property graphs and RDF (Resource Description Framework) to create a hybrid and versatile method for working with knowledge graphs [01:01:04].
Extending Naive RAG with Graph Traversal
In a naive RAG approach, vector search is used to find relevant document chunks, which are then injected into a prompt to add context [01:11:23]. However, in Graph RAG, this vector search is only the starting point [01:11:34]. After identifying initial chunks, the system traverses the graph to expand context by finding related entities such as article nodes, topics relevant to those articles, or other articles with the same topic or mentioning the same organization [01:11:36].
Graph RAG is characterized by its use of various subgraph entry points [01:12:32]. This includes:
- Lexical Graph: Used for vector search with unstructured data [01:12:36].
- Domain Graph: Traversed to find relevant context for the model [01:12:40].
- Other Entry Points: Can include geospatial indices (e.g., finding news articles near a specific location) or image embedding models for image similarity search [01:11:52].
Dgraph as a Foundation for Graph RAG
Dgraph is an open-source project that serves as a hybrid graph database, optimizing for large-scale distributed graph data [04:31:00]. It uses the property graph model for data modeling and querying, while employing RDF for data interchange, working with triples as the smallest unit of record [04:57:00].
Knowledge Graph Definition in Dgraph
A knowledge graph in Dgraph is considered an instance of a property graph [02:55:00].
- Nodes: Can have one or more labels that define their type, similar to tables in a relational database [03:06:00].
- Relationships: Have a single type and direction [03:24:00].
- Properties: Arbitrary key-value pairs can be stored on nodes and relationships [03:30:00].
- Semantics: How entities are connected is encoded in the data model, focusing on representing “things, not strings” [03:36:00]. This ensures a canonical representation of entities [04:15:00].
Modeling Property Graphs as RDF Triples in Dgraph
Dgraph models property graphs as RDF triples (subject, predicate, object) [06:10:00].
- Subject: Always a unique ID for a node, acting as a pointer [06:40:00].
- Predicate: Represents a relationship or a property [06:49:00].
- Object: If the predicate is a relationship, the object is another node ID; if it’s a property, the object is the value of that property [06:53:00].
Dgraph uses an optimization called a “posting list” to group by predicate and list unique node IDs, allowing for efficient graph traversal [07:14:00].
DQL Query Language
DQL (Dgraph Query Language) is inspired by GraphQL [07:41:00].
- Starting Point: Every traversal begins with a well-defined root criteria, often using an index to find initial nodes [08:12:00].
- Selection Set: A nested structure specifies properties to return and represents the graph traversal path [08:26:00].
- Output: Data returned from a DQL query is in JSON format, matching the structure of the selection set [08:49:00].
Example: News Knowledge Graph
To illustrate Graph RAG, a news knowledge graph can be created [09:03:00].
- Entities as Nodes: Organizations, people, topics, authors, images, and even paragraphs (as chunks) can be modeled as nodes [09:16:00].
- Unstructured Data: Unstructured data is chunked (e.g., each paragraph as a chunk) and embedded, with the embedding stored as a node property [09:41:00]. This allows for vector search as an entry point [10:54:00].
- Traversals: From an article, one can traverse to its author, mentioned topics, organizations, geographic areas, and related images [10:15:00]. This enables finding other articles with the same topic or location [10:30:00].
- Querying Examples: Dgraph can be used for:
- Simple article counts [13:10:00].
- Traversing from articles to topics [13:17:00].
- Filtering by publication date and traversing to geographic areas [13:40:00].
- Geographic distance search (e.g., news within a certain radius) [13:57:00].
- Vector similarity search, followed by graph traversal to find related topics, regions, or organizations [14:20:00].
- More complex traversals combining vector search matches with topic overlap to discover indirectly related articles [14:51:00].
Agentic Applications with Graph RAG
Graph RAG workflows provide the foundation for building AI agents [02:30:00].
Model Context Protocol (MCP)
MCP is a way to expose tools to models, enabling them to interact with databases like Dgraph [16:33:00]. Each Dgraph instance serves as an MCP server [16:53:00].
- Read-only instance: Exposes query execution and schema inspection capabilities [17:01:00].
- Full endpoint: Also exposes functionality for mutations (adding data) and schema alterations [17:10:00].
Use cases for Dgraph MCP servers include:
- Agentic Coding Assistants: Tools that leverage schema and retrieved data to autogenerate CRUD endpoints or DQL queries [17:21:00].
- Exploratory Data Analysis: Generating DQL queries to fetch and understand data in the graph, often through interfaces like Claude desktop [17:54:00]. The model generates queries and executes them, verifying results and iterating if needed [20:00:00].
Modus Agent Orchestration Framework
Modus is an open-source framework by Hypermode for building AI agents, focusing on bringing data to models and exposing tools for agentic flows [02:18:00]. It provides abstractions for working with models and data, along with a runtime for managing large numbers of stateful, long-running agents [02:46:00].
Modus uses WebAssembly (Wasm) to target multiple languages for SDKs (e.g., Go, AssemblyScript), compiling logic to Wasm and generating a unified GraphQL API that leverages defined types and function signatures [02:16:00]. This provides a secure and sandboxed environment for AI agents [02:55:00].
Hypermode Agents
Hypermode Agents allow users to create domain-specific agents starting with a prompt and exposing tools via MCP servers [02:35:00]. These agents can interact with various services (e.g., GitHub, Notion) via their respective MCP servers [02:57:00]. For example, an agent can analyze a GitHub repository, generate social media posts, include relevant code snippets, and save the output to a Notion workspace [02:17:00]. Hypermode Agents also offer the ability to “eject to code,” allowing users to access the underlying Modus code to add more complex logic or connections [03:18:00].