pub struct GraphRAG<M: BaseChatModel> { /* private fields */ }Expand description
GraphRAG: Knowledge Graph-based Retrieval Augmented Generation.
Wraps an LLM for entity/relation extraction and community summarization,
and an in-memory GraphStore for graph operations.
Implementations§
Source§impl<M: BaseChatModel> GraphRAG<M>
impl<M: BaseChatModel> GraphRAG<M>
Sourcepub fn with_config(self, config: GraphRAGConfig) -> Self
pub fn with_config(self, config: GraphRAGConfig) -> Self
Sets a custom configuration.
Sourcepub async fn add_documents(
&self,
docs: &[Document],
) -> Result<(), GraphRAGError>
pub async fn add_documents( &self, docs: &[Document], ) -> Result<(), GraphRAGError>
Adds documents to the knowledge graph by extracting entities and relations from each document via the LLM.
Sourcepub async fn build_communities(&self) -> Result<(), GraphRAGError>
pub async fn build_communities(&self) -> Result<(), GraphRAGError>
Runs hierarchical Leiden community detection and generates one summary per community via the LLM.
Level-0 communities are summarized from their entities and internal relations; each higher level is rolled up from its child-community summaries plus the relations crossing the children. Community ids index the summary vector one-to-one.
Sourcepub async fn query(
&self,
q: &str,
mode: QueryMode,
) -> Result<GraphRAGResult, GraphRAGError>
pub async fn query( &self, q: &str, mode: QueryMode, ) -> Result<GraphRAGResult, GraphRAGError>
Queries the knowledge graph using the specified mode.
Sourcepub async fn entity_count(&self) -> usize
pub async fn entity_count(&self) -> usize
Returns the number of entities in the graph.
Sourcepub async fn relation_count(&self) -> usize
pub async fn relation_count(&self) -> usize
Returns the number of relations in the graph.
Sourcepub async fn community_count(&self) -> usize
pub async fn community_count(&self) -> usize
Returns the number of communities across all hierarchy levels.
Sourcepub async fn communities(&self) -> Vec<Community>
pub async fn communities(&self) -> Vec<Community>
Returns a clone of the detected community hierarchy (empty until
GraphRAG::build_communities has run).
Sourcepub async fn community_summaries(&self) -> Vec<String>
pub async fn community_summaries(&self) -> Vec<String>
Returns one summary per community, indexed by Community::id.