Graph RAG-Tool Fusion Algorithm
- The paper presents a novel algorithm that integrates semantic vector search with graph-based dependency propagation to enhance toolchain retrieval in RAG systems.
- It employs a structured tool knowledge graph with explicit dependency labels to model direct and indirect inter-tool relationships for precise reasoning.
- Empirical evaluations on benchmark datasets demonstrate significant mAP@10 improvements, validating the approach's robust scalability and accuracy.
A Graph RAG-Tool Fusion algorithm integrates semantic vector search with structured dependency propagation over a tool knowledge graph, enabling retrieval-augmented generation (RAG) agents to select toolchains that accurately reflect complex requirements and inter-tool dependencies. This paradigm advances over naïve vector search approaches by directly encoding tool relationships as a graph and algorithmically traversing both semantic and dependency spaces for retrieval, as defined in recent research on FastInsight (An et al., 26 Jan 2026) and "Graph RAG-Tool Fusion" (Lumer et al., 11 Feb 2025).
1. Formalization of the Tool Knowledge Graph
The tool knowledge graph is represented as , where is the set of tools (nodes) and is the set of directed, labeled edges. The label set captures dependency types, including "tool_directly_depends", "tool_indirectly_depends", "param_directly_depends", and "param_indirectly_depends". Each node encodes metadata: a textual description , a dense vector embedding , and a flag marking core tools.
Edges model concrete structural or parameter dependencies, such that for , tool depends on 0 by dependency of type 1. This formalism enables precise graph-based reasoning over tool selection and invocation.
2. Algorithmic Structure and Retrieval-Scoring Formulations
Graph RAG-Tool Fusion decomposes retrieval into interleaved vector-based search and graph-based dependency propagation:
- Vector Search: Given a user query 2, compute query embedding 3 and define the cosine-similarity score:
4
Retrieve the top-5 tools 6.
- Dependency Propagation: For each of the 7 seeds 8, traverse its dependencies in 9 up to depth 0. For each node 1 encountered,
2
where 3 is the shortest directed path from 4 to 5 (capped at 6), and 7 is an optional depth-decay. All nodes are then ranked primarily by 8, breaking ties by proximity in the graph and initial seed rank.
This construct yields a retrieval set that reflects both the direct semantic fit and the transitive dependencies among candidate tools, ensuring holistic coverage for complex tool-calling LLM workflows.
3. End-to-End Algorithm and Pseudocode
The canonical retrieval cycle comprises the following main steps (Lumer et al., 11 Feb 2025):
| Step | Operation | Description |
|---|---|---|
| 1 | Vector retrieval | Compute 9 over 0 and select top-1 2 |
| 2 | Graph traversal | For each 3, DFS over 4 up to depth 5; collect all reachable 6 not already in the result set |
| 3 | Score propagation | Assign 7 as above for all 8 discovered |
| 4 | Ordering & truncation | Sort all 9 by 0, then by increasing distance and original rank; output top 1 |
Pseudocode formalizes this as: (1) embed query and retrieve vector matches; (2) initialize graph score list; (3) for each seed tool, propagate through the dependency graph; (4) order by propagated score with distance/rank tie-breaking; (5) truncate to 2 results.
4. Empirical Evaluation and Benchmarks
Performance is substantiated on ToolLinkOS, a benchmark of 573 fictional tools (average 6.3 dependencies per tool) and 1,569 user queries. Main findings:
- On ToolLinkOS (3): naïve RAG achieves mAP@10 = 0.210, while Graph RAG-Tool Fusion with 4 and initial-vector reranking yields mAP@10 = 0.927—an absolute gain of 71.7%.
- On ToolSandbox (33 tools, 1,032 queries): naïve RAG mAP@10 = 0.440; Graph RAG-Tool Fusion with reranking achieves 0.661 (+22.1% absolute).
- Ablation shows reranking the top-5 adds 7–14% absolute mAP@10 over non-reranked variants, by prioritizing correct seed selection and mitigating truncation errors.
These results demonstrate superior recall and precision, especially for queries involving tools with complex, nested dependencies, relative to baseline vector-only RAG.
5. Complexity and Scalability Analysis
Let 6 (total tools), 7 (seed count), 8 (dependency depth cutoff), and 9 (average node out-degree). Main complexity factors:
- Vector search costs 0 (or 1 per query with HNSW-like indices).
- Graph traversal for dependencies is 2.
- Sorting and truncation for up to 3 elements is 4.
Practical deployments exploit sublinear vector search and bounded dependency expansions (average 6.3 dependencies/tool), enabling efficient scaling to large toolbases. A plausible implication is that further increases in toolbase size (with bounded average degree) show only modest increases in end-to-end retrieval latency.
6. Implementation Considerations
- Embeddings and vector DB: Deployed using Azure OpenAI text-embedding-ada-002, with HNSW approximate vector search (HNSW parameters 5, hybrid weight 6 default).
- Graph Storage: Neo4j DB with typed adjacency lists and structured edge metadata, ensuring efficient multi-type traversal.
- Parameter Settings: Default 7 seeds; expansion limited to full direct/indirect dependencies unless otherwise specified; final output list size 8 for mAP@10 reporting.
- Query Reranking: Optional GPT-4O LLM reranker applied to top candidate seeds; prompts conform to Pydantic-type tool schemas.
- Robustness: Tool and schema co-design (manual+LLM) assures consistency and name collision avoidance; tools encoded as JSON nodes with explicit dependency tuples.
- Scalability: Empirical results report strong scaling to thousands of tools, with bounded graph-expansion overhead due to low average degree.
7. Extensions and Connections to Corpus Graph Retrieval
The fusion methodology in Graph RAG-Tool Fusion maps directly to recent advances in corpus-graph RAG, particularly the introduction of two fusion operators in FastInsight (An et al., 26 Jan 2026):
- GRanker (Graph Model-based Search): Injects neighborhood context into node rankings using Laplacian smoothing over latent cross-encoder representations, addressing the "topology-blindness" of standard model-based search.
- STeX (Semantic-Topological eXpansion): Expands the retrieval frontier by jointly scoring candidates on both semantic vector and structural graph criteria, remedying semantics-blindness in pure graph traversal.
A formal extension to full Graph RAG–Tool Fusion incorporates an external tool invocation operator (9), integrating outputs as "pseudo-nodes" into the graph and re-running GRanker/STeX over this enriched subgraph. This enables adaptive, context-driven tool selection with temporary augmentation by LLM-generated or externally queried content, fusing semantic, structural, and tool-external evidence in the retrieval loop (An et al., 26 Jan 2026).
Summary Table: Main Empirical Results
| Dataset | Naïve RAG mAP@10 | Graph RAG-Tool Fusion mAP@10 | Absolute Gain |
|---|---|---|---|
| ToolLinkOS | 0.210 | 0.856 (+rerank: 0.927) | +64.6% (+71.7%) |
| ToolSandbox | 0.440 | 0.521 (+rerank: 0.661) | +8.1% (+22.1%) |
The Graph RAG-Tool Fusion algorithm achieves tight integration of vector search and graph traversal, enabling structure-aware toolchain retrieval far superior to baseline RAG methods and facilitating effective, scalable, and context-sensitive tool orchestration (Lumer et al., 11 Feb 2025).