Agentic RAG with Python
Transform your Temporal Graph into an autonomous Intelligence Agent.
While standard RAG implementations rely on passive vector retrieval, Agentic RAG empowers your LLM to actively "drive" the graph. By providing the LLM with a Python execution environment and a Raphtory graph, it can write its own traversals, calculate metrics on-the-fly, and determine its own retrieval strategy.
Core Philosophy: The LLM with a Steering Wheel
In this architecture, the LLM is not just a consumer of data; it is an analyst with access to the PersistentGraph.
Implementation Guide
To implement Agentic RAG, you expose a Python tool to your LLM (using frameworks like LangChain, LlamaIndex, or Vercel AI SDK).
1. The Python Execution Tool
Your backend should provide a secure environment where the LLM can execute Raphtory code. Here is a simplified pattern:
Performance Tip: Since graphs can be massive, always instruct your LLM (via the System Prompt) to use iterators like itertools.islice rather than collecting the entire graph into memory.
2. Teaching the Agent to Search (FastRP)
You can significantly boost the agent's power by teaching it how to use Raphtory's native embedding algorithms like FastRP for similarity search.
In your Tool's documentation for the LLM, provide this recipe:
Technical Patterns
Dynamic Introspection
Don't just give the LLM the graph. Give it the Metadata. Before the conversation starts, run a "Pre-flight" script to extract:
- Unique node types and edge layers.
- Property keys and sample values.
- The current temporal range of the graph.
Inject this into the System Prompt so the LLM knows exactly which properties it can filter on.
Subgraph Slicing
Instruct the agent to "Zoom in" before analyzing. A common pattern is to have the agent identify a small set of interesting "Seed Nodes" and then create a subgraph of their 2-hop neighborhood for detailed reasoning.
Comparison: Agentic vs. Standard
| Strategy | Standard RAG | Agentic Raphtory RAG |
|---|---|---|
| Logic | Fixed Retrieval Chain | Dynamic Discovery |
| Calculation | Pre-calculated vectors | On-the-fly graph metrics (Centrality, Communities) |
| Multi-hop | Limited/Fixed | Arbitrary depth traversal |
| Temporal | Static snapshot | Time-traveling queries (using .at() or .window()) |
Next Steps
Vectorised Graph API
Learn how to host a managed Vector Search API over your graph.
Semantic Templating
Define how graph objects are converted to natural language.