pub struct KnowledgeGraph { /* private fields */ }Expand description
Knowledge graph containing entities and their relationships
Implementations§
Source§impl KnowledgeGraph
impl KnowledgeGraph
Sourcepub fn add_document(&mut self, document: Document) -> Result<()>
pub fn add_document(&mut self, document: Document) -> Result<()>
Add a document to the knowledge graph
Sourcepub fn add_entity(&mut self, entity: Entity) -> Result<NodeIndex>
pub fn add_entity(&mut self, entity: Entity) -> Result<NodeIndex>
Add an entity to the knowledge graph
Sourcepub fn add_relationship(&mut self, relationship: Relationship) -> Result<()>
pub fn add_relationship(&mut self, relationship: Relationship) -> Result<()>
Add a relationship between entities
Sourcepub fn get_entity(&self, id: &EntityId) -> Option<&Entity>
pub fn get_entity(&self, id: &EntityId) -> Option<&Entity>
Get an entity by ID
Sourcepub fn get_document(&self, id: &DocumentId) -> Option<&Document>
pub fn get_document(&self, id: &DocumentId) -> Option<&Document>
Get a document by ID
Sourcepub fn get_entity_mut(&mut self, id: &EntityId) -> Option<&mut Entity>
pub fn get_entity_mut(&mut self, id: &EntityId) -> Option<&mut Entity>
Get a mutable reference to an entity by ID
Sourcepub fn get_chunk_mut(&mut self, id: &ChunkId) -> Option<&mut TextChunk>
pub fn get_chunk_mut(&mut self, id: &ChunkId) -> Option<&mut TextChunk>
Get a mutable reference to a chunk by ID
Sourcepub fn entities_mut(&mut self) -> impl Iterator<Item = &mut Entity>
pub fn entities_mut(&mut self) -> impl Iterator<Item = &mut Entity>
Get all entities (mutable)
Sourcepub fn documents_mut(&mut self) -> impl Iterator<Item = &mut Document>
pub fn documents_mut(&mut self) -> impl Iterator<Item = &mut Document>
Get all documents (mutable)
Sourcepub fn chunks_mut(&mut self) -> impl Iterator<Item = &mut TextChunk>
pub fn chunks_mut(&mut self) -> impl Iterator<Item = &mut TextChunk>
Get all chunks (mutable)
Sourcepub fn get_neighbors(
&self,
entity_id: &EntityId,
) -> Vec<(&Entity, &Relationship)>
pub fn get_neighbors( &self, entity_id: &EntityId, ) -> Vec<(&Entity, &Relationship)>
Get neighbors of an entity
Sourcepub fn get_all_relationships(&self) -> Vec<&Relationship>
pub fn get_all_relationships(&self) -> Vec<&Relationship>
Get all relationships in the graph
Sourcepub fn load_from_json(file_path: &str) -> Result<Self>
pub fn load_from_json(file_path: &str) -> Result<Self>
Load knowledge graph from JSON file
Sourcepub fn save_to_json(&self, file_path: &str) -> Result<()>
pub fn save_to_json(&self, file_path: &str) -> Result<()>
Save knowledge graph to JSON file with optimized format for entities and relationships
Sourcepub fn find_entities_by_name(&self, name: &str) -> impl Iterator<Item = &Entity>
pub fn find_entities_by_name(&self, name: &str) -> impl Iterator<Item = &Entity>
Find entities by name (case-insensitive partial match)
Sourcepub fn get_entity_by_id(&self, id: &str) -> Option<&Entity>
pub fn get_entity_by_id(&self, id: &str) -> Option<&Entity>
Get entity by ID (string version for compatibility)
Sourcepub fn get_entity_relationships(
&self,
entity_id: &str,
) -> impl Iterator<Item = &Relationship>
pub fn get_entity_relationships( &self, entity_id: &str, ) -> impl Iterator<Item = &Relationship>
Get entity relationships
Sourcepub fn find_relationship_path(
&self,
entity1: &str,
entity2: &str,
_max_depth: usize,
) -> Vec<String>
pub fn find_relationship_path( &self, entity1: &str, entity2: &str, _max_depth: usize, ) -> Vec<String>
Find relationship path between two entities (simplified BFS)
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Count entities in the graph
Sourcepub fn relationship_count(&self) -> usize
pub fn relationship_count(&self) -> usize
Count relationships in the graph
Sourcepub fn document_count(&self) -> usize
pub fn document_count(&self) -> usize
Count documents in the graph
Sourcepub fn relationships(&self) -> impl Iterator<Item = &Relationship>
pub fn relationships(&self) -> impl Iterator<Item = &Relationship>
Get all relationships as an iterator
Sourcepub fn clear_entities_and_relationships(&mut self)
pub fn clear_entities_and_relationships(&mut self)
Clear all entities and relationships while preserving documents and chunks
This is useful for rebuilding the graph from scratch without reloading documents.
Trait Implementations§
Source§impl Debug for KnowledgeGraph
impl Debug for KnowledgeGraph
Auto Trait Implementations§
impl Freeze for KnowledgeGraph
impl RefUnwindSafe for KnowledgeGraph
impl Send for KnowledgeGraph
impl Sync for KnowledgeGraph
impl Unpin for KnowledgeGraph
impl UnsafeUnpin for KnowledgeGraph
impl UnwindSafe for KnowledgeGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more