EnhancedGraphRAG<T>
Models & Types · AiDotNet.RetrievalAugmentedGeneration.Graph
Enhanced Graph-based RAG that integrates with KnowledgeGraph and supports
Local, Global (Leiden community summaries), and DRIFT retrieval modes.
For Beginners
EnhancedGraphRAG combines three retrieval strategies:
Local Search: Best for specific factual questions.
- Find entities in the graph matching the query
- Traverse their neighborhood (1-2 hops)
- Collect related entities and their connections as context
Global Search: Best for broad thematic questions (“What are all the research areas?”).
- Pre-compute community summaries via Leiden algorithm
- Search community summaries for relevant communities
- Return community descriptions as context
DRIFT Search: Best for complex queries needing both breadth and depth.
- Start with Global search to identify relevant communities
- From top communities, pick key entities
- Run Local search from those entities to refine context
- Repeat refinement for N iterations
How It Works
Unlike the existing GraphRAG,
this class works directly with the KnowledgeGraph class (which delegates to IGraphStore),
rather than maintaining its own internal dictionary. It also adds Leiden-based community summarization
for global and DRIFT search modes.
Constructors
| Constructor | Summary |
|---|---|
EnhancedGraphRAG(KnowledgeGraph<T> graph, GraphRAGOptions options) |
Creates a new EnhancedGraphRAG instance. |
Properties
| Property | Summary |
|---|---|
LeidenResult CommunityStructure { get; } |
Gets the Leiden community detection result, if community detection has been run. |
Methods
| Method | Summary |
|---|---|
IEnumerable<GraphNode<T>> RetrieveNodes(string query, int topK) |
Retrieves relevant graph nodes for a given query. |
List<string> Retrieve(string query, int topK) |
Retrieves context from the knowledge graph for a given query. |
void BuildCommunityIndex() |
Builds the community index for Global and DRIFT search modes. |