pub struct SimpleEntityGraph {
pub entities: BTreeMap<String, EntityData>,
pub entity_mentions: BTreeMap<String, Vec<Uuid>>,
/* private fields */
}Expand description
Enhanced entity graph using petgraph for efficient relationship operations
Fields§
§entities: BTreeMap<String, EntityData>Entity metadata storage - uses BTreeMap for deterministic JSON serialization
entity_mentions: BTreeMap<String, Vec<Uuid>>Entity mentions tracking - uses BTreeMap for deterministic JSON serialization
Implementations§
Source§impl SimpleEntityGraph
impl SimpleEntityGraph
Sourcepub fn new() -> SimpleEntityGraph
pub fn new() -> SimpleEntityGraph
Creates a new empty entity graph
Sourcepub fn remove_entity(&mut self, name: &str) -> bool
pub fn remove_entity(&mut self, name: &str) -> bool
Remove a single entity and all its incident edges. Returns true if the entity existed and was removed.
DiGraph::remove_node moves the LAST node into the vacated slot,
which invalidates the previous-last NodeIndex. We patch both
index maps for the swapped node so subsequent lookups stay correct.
Sourcepub fn has_entity(&self, name: &str) -> bool
pub fn has_entity(&self, name: &str) -> bool
Check if entity exists in the graph
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Get the number of entities in the graph
Sourcepub fn update_entity_timestamp(&mut self, name: &str, timestamp: DateTime<Utc>)
pub fn update_entity_timestamp(&mut self, name: &str, timestamp: DateTime<Utc>)
Update entity timestamp without changing other properties
Sourcepub fn add_or_update_entity(
&mut self,
name: String,
entity_type: EntityType,
timestamp: DateTime<Utc>,
description: &str,
)
pub fn add_or_update_entity( &mut self, name: String, entity_type: EntityType, timestamp: DateTime<Utc>, description: &str, )
Add or update entity - maintains same API as original SimpleEntityGraph
Sourcepub fn mention_entity(
&mut self,
name: &str,
update_id: Uuid,
timestamp: DateTime<Utc>,
)
pub fn mention_entity( &mut self, name: &str, update_id: Uuid, timestamp: DateTime<Utc>, )
Mention entity - updates importance and tracking
Sourcepub fn add_relationship(&mut self, relationship: EntityRelationship)
pub fn add_relationship(&mut self, relationship: EntityRelationship)
Add relationship - now uses petgraph for efficient storage
Sourcepub fn merge_from(&mut self, other: &SimpleEntityGraph)
pub fn merge_from(&mut self, other: &SimpleEntityGraph)
Merge all entities and relationships from another graph into this one.
Entities are added with add_or_update_entity (so counts accumulate for
entities that appear in multiple sessions). Edges are copied as-is.
Find related entities - now O(degree) instead of O(n)! Uses BTreeSet for automatic sorting, avoiding explicit sort() call Supports case-insensitive lookup with fallback
Find related entities by specific relation type - also now O(degree) instead of O(n) Uses BTreeSet for automatic sorting, avoiding explicit sort() call Supports case-insensitive lookup with fallback
Sourcepub fn get_entities_by_type(&self, entity_type: &EntityType) -> Vec<&EntityData>
pub fn get_entities_by_type(&self, entity_type: &EntityType) -> Vec<&EntityData>
Get entities by type - unchanged from original
Sourcepub fn get_most_important_entities(&self, limit: usize) -> Vec<&EntityData>
pub fn get_most_important_entities(&self, limit: usize) -> Vec<&EntityData>
Get most important entities - unchanged from original
Sourcepub fn get_recently_mentioned_entities(&self, limit: usize) -> Vec<&EntityData>
pub fn get_recently_mentioned_entities(&self, limit: usize) -> Vec<&EntityData>
Get recently mentioned entities - unchanged from original
Sourcepub fn search_entities(&self, query: &str) -> Vec<&EntityData>
pub fn search_entities(&self, query: &str) -> Vec<&EntityData>
Search entities by name or description (case-insensitive)
Sourcepub fn get_entity_context(&self, entity_name: &str) -> Option<String>
pub fn get_entity_context(&self, entity_name: &str) -> Option<String>
Get entity context with improved relationship lookup
Sourcepub fn get_entity_relationships(
&self,
entity_name: &str,
) -> Vec<(String, RelationType, String)>
pub fn get_entity_relationships( &self, entity_name: &str, ) -> Vec<(String, RelationType, String)>
Get entity relationships - now uses efficient petgraph edge iteration Returns (entity_name, relation_type, context) tuples
Sourcepub fn trace_entity_relationships(
&self,
start_entity: &str,
max_depth: usize,
) -> Vec<(String, String, String)>
pub fn trace_entity_relationships( &self, start_entity: &str, max_depth: usize, ) -> Vec<(String, String, String)>
Trace entity relationships using efficient BFS
Sourcepub fn get_entity_network(
&self,
center_entity: &str,
max_depth: usize,
) -> EntityNetwork
pub fn get_entity_network( &self, center_entity: &str, max_depth: usize, ) -> EntityNetwork
Get entity network using efficient graph traversal
Sourcepub fn analyze_entity_importance(&self) -> Vec<EntityAnalysis>
pub fn analyze_entity_importance(&self) -> Vec<EntityAnalysis>
Analyze entity importance with graph metrics
Sourcepub fn find_shortest_path(&self, from: &str, to: &str) -> Option<Vec<String>>
pub fn find_shortest_path(&self, from: &str, to: &str) -> Option<Vec<String>>
New petgraph-specific methods
Find shortest path between two entities using A* algorithm Returns the complete path including start and end nodes
Sourcepub fn get_graph_stats(&self) -> GraphStats
pub fn get_graph_stats(&self) -> GraphStats
Get graph statistics
Sourcepub fn find_communities(&self) -> Vec<Vec<String>>
pub fn find_communities(&self) -> Vec<Vec<String>>
Find strongly connected components
Sourcepub fn get_all_relationships(&self) -> Vec<EntityRelationship>
pub fn get_all_relationships(&self) -> Vec<EntityRelationship>
Get all relationships in the graph as EntityRelationship structs Used for migration to SurrealDB native graph format
Sourcepub fn get_all_entities(&self) -> Vec<EntityData>
pub fn get_all_entities(&self) -> Vec<EntityData>
Get all entities as a vector (convenience method for migration)
Trait Implementations§
Source§impl Clone for SimpleEntityGraph
impl Clone for SimpleEntityGraph
Source§fn clone(&self) -> SimpleEntityGraph
fn clone(&self) -> SimpleEntityGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SimpleEntityGraph
impl Debug for SimpleEntityGraph
Source§impl Default for SimpleEntityGraph
impl Default for SimpleEntityGraph
Source§fn default() -> SimpleEntityGraph
fn default() -> SimpleEntityGraph
Source§impl<'de> Deserialize<'de> for SimpleEntityGraph
impl<'de> Deserialize<'de> for SimpleEntityGraph
Source§fn deserialize<D>(
deserializer: D,
) -> Result<SimpleEntityGraph, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<SimpleEntityGraph, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Serialize for SimpleEntityGraph
impl Serialize for SimpleEntityGraph
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for SimpleEntityGraph
impl RefUnwindSafe for SimpleEntityGraph
impl Send for SimpleEntityGraph
impl Sync for SimpleEntityGraph
impl Unpin for SimpleEntityGraph
impl UnsafeUnpin for SimpleEntityGraph
impl UnwindSafe for SimpleEntityGraph
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request