pub struct SemanticDocumentGraph { /* private fields */ }Expand description
Graph of document relationships based on semantic similarity and explicit annotations (citations, cluster membership).
Implementations§
Source§impl SemanticDocumentGraph
impl SemanticDocumentGraph
Sourcepub fn new(similarity_threshold: f64) -> Self
pub fn new(similarity_threshold: f64) -> Self
Create a new graph with the given cosine-similarity threshold for automatic linking.
Sourcepub fn add_node(
&mut self,
doc_id: &str,
embedding: Vec<f64>,
metadata: HashMap<String, String>,
)
pub fn add_node( &mut self, doc_id: &str, embedding: Vec<f64>, metadata: HashMap<String, String>, )
Add a document node. If a node with the same doc_id already exists
it is silently replaced (edges are not touched).
Sourcepub fn remove_node(&mut self, doc_id: &str) -> bool
pub fn remove_node(&mut self, doc_id: &str) -> bool
Remove a node and all edges incident to it. Returns true if the node
existed.
Sourcepub fn add_edge(
&mut self,
source: &str,
target: &str,
kind: EdgeKind,
weight: f64,
) -> Result<(), String>
pub fn add_edge( &mut self, source: &str, target: &str, kind: EdgeKind, weight: f64, ) -> Result<(), String>
Add an explicit edge between two existing nodes. Returns an error if either endpoint does not exist.
Sourcepub fn auto_link_similar(&mut self)
pub fn auto_link_similar(&mut self)
Compute pairwise cosine similarity for all node pairs and add Similar
edges for every pair whose similarity meets or exceeds the threshold.
Existing Similar edges are not removed first — call this on a
fresh graph or manually prune duplicates if needed.
Sourcepub fn neighbors(&self, doc_id: &str) -> Vec<(&DocGraphNode, f64)>
pub fn neighbors(&self, doc_id: &str) -> Vec<(&DocGraphNode, f64)>
Return neighbour nodes with their edge weights.
Sourcepub fn shortest_path(&self, from: &str, to: &str) -> Option<Vec<String>>
pub fn shortest_path(&self, from: &str, to: &str) -> Option<Vec<String>>
BFS shortest path (by hop count) from from to to. Returns the
sequence of doc-ids including both endpoints, or None if no path
exists.
Sourcepub fn connected_components(&self) -> Vec<Vec<String>>
pub fn connected_components(&self) -> Vec<Vec<String>>
Return the connected components of the (undirected) graph.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges.
Sourcepub fn degree(&self, doc_id: &str) -> usize
pub fn degree(&self, doc_id: &str) -> usize
Degree (number of incident edges) for a given node. Returns 0 if the node does not exist.
Sourcepub fn stats(&self) -> DocumentGraphStats
pub fn stats(&self) -> DocumentGraphStats
Aggregate statistics.
Auto Trait Implementations§
impl Freeze for SemanticDocumentGraph
impl RefUnwindSafe for SemanticDocumentGraph
impl Send for SemanticDocumentGraph
impl Sync for SemanticDocumentGraph
impl Unpin for SemanticDocumentGraph
impl UnsafeUnpin for SemanticDocumentGraph
impl UnwindSafe for SemanticDocumentGraph
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.