Skip to main content

WriteGuard

Struct WriteGuard 

Source
pub struct WriteGuard<'a> { /* private fields */ }
Expand description

RAII guard that publishes a fresh ReadSnapshot on drop.

Implementations§

Source§

impl WriteGuard<'_>

Source

pub fn publish(&mut self)

Publish a snapshot now (eager, before drop). Also called by Drop.

Source

pub fn graph(&mut self) -> &mut KnowledgeGraph

Access the underlying KnowledgeGraph for mutation.

Methods from Deref<Target = KnowledgeGraph>§

Source

pub fn interner(&self) -> &StringInterner

Source

pub fn get_entity(&self, name: &str) -> Option<Entity>

Return a single entity by exact name match.

Source

pub fn graph_stats(&self) -> Value

Return aggregate statistics about the graph.

Source

pub fn search_relations( &self, from: Option<&str>, to: Option<&str>, rtype: Option<&str>, ) -> Vec<Relation>

Search relations by optional filters: from, to, relationType. Any filter that is absent matches everything. A filter value that does not exist in the graph returns empty results.

Source

pub fn find_path(&self, from: &str, to: &str) -> Result<Vec<String>>

BFS shortest-path between two entity names. Returns the sequence of entity names along the path (inclusive of both endpoints).

Source

pub fn compact(&mut self) -> Result<()>

Rewrite the binary log from the current in-memory state. After compaction the log contains only the minimal set of records needed to reconstruct the graph (all creates, no deletes). Crash-safe: writes to a temp file, then atomically renames (C3).

Source

pub fn create_entities(&mut self, entities: &[Entity]) -> Result<Vec<Entity>>

Source

pub fn create_relations( &mut self, relations: &[Relation], ) -> Result<Vec<Relation>>

Source

pub fn add_observations( &mut self, entity_name: &str, contents: &[String], ) -> Result<Vec<String>>

Source

pub fn delete_entities(&mut self, entity_names: &[String]) -> Result<()>

Source

pub fn delete_observations( &mut self, entity_name: &str, observations: &[String], ) -> Result<()>

Source

pub fn delete_relations(&mut self, relations: &[Relation]) -> Result<()>

Source

pub fn read_graph(&self) -> KnowledgeGraphOut

Source

pub fn read_graph_view(&self) -> GraphView<'_>

Borrowing, allocation-light view of the full graph (M6). Serializing it streams interned &str directly instead of materializing a String per name/type/observation.

Source

pub fn search_nodes(&self, query: &str) -> KnowledgeGraphOut

Relevance-ranked substring search returning all matches (no pagination). Equivalent to search_nodes_filtered(query, None, 0, usize::MAX).

Source

pub fn open_nodes(&self, names: &[String]) -> KnowledgeGraphOut

Source

pub fn open_nodes_view(&self, names: &[String]) -> GraphView<'_>

Borrowing view variant of [open_nodes] (M6).

Source

pub fn entity_type_counts(&self) -> Vec<(String, usize)>

Tally distinct entity types and their live-entity counts, ranked by count descending (ties broken by name). One linear pass over the dense slot vec; only the final names are allocated.

Source

pub fn relation_type_counts(&self) -> Vec<(String, usize)>

Tally distinct relation types and their counts, ranked by count desc.

Source

pub fn search_nodes_filtered( &self, query: &str, entity_type: Option<&str>, offset: usize, limit: usize, ) -> KnowledgeGraphOut

Relevance-ranked, optionally type-filtered, paginated node search. Entities come back best-match-first (see SearchIndex::search_ranked). Relations touching any returned entity (either endpoint) are included.

Source

pub fn search_nodes_view( &self, query: &str, entity_type: Option<&str>, offset: usize, limit: usize, ) -> GraphView<'_>

Borrowing view variant of [search_nodes_filtered] (M6).

Source

pub fn read_graph_filtered( &self, entity_type: Option<&str>, offset: usize, limit: usize, ) -> KnowledgeGraphOut

Type-filtered, paginated view of the whole graph. Unlike [read_graph], relations are restricted to those whose both endpoints fall in the returned entity page, so the slice is internally consistent.

Source

pub fn read_graph_filtered_view( &self, entity_type: Option<&str>, offset: usize, limit: usize, ) -> GraphView<'_>

Borrowing view variant of [read_graph_filtered] (M6).

Source

pub fn neighbors( &self, name: &str, direction: Direction, rtype: Option<&str>, depth: u32, ) -> Result<KnowledgeGraphOut>

Neighborhood expansion around name out to depth hops, following edges in the requested Direction and (optionally) of one relation type. Returns the origin plus reached entities, and every relation (passing the type filter) whose endpoints are both inside that set.

depth == 1 (the common case) is a single linear pass over the flat relation vec; deeper queries build an adjacency map once (O(E)) and BFS.

Source

pub fn describe_entity(&self, name: &str) -> Result<Value>

One-shot context bundle for a single entity: the entity itself, every incident relation, its distinct neighbor names, and its degree. Saves an agent the get_entity + two search_relations round-trips.

Source

pub fn upsert_entities(&mut self, entities: &[Entity]) -> Result<Vec<Value>>

Create-or-merge a batch of entities idempotently. Missing entities are created; existing ones keep their type and gain any new observations (deduplicated). Returns a per-entity outcome. The caller is responsible for flushing — every underlying op is already write-ahead logged.

Source

pub fn export(&self, format: &str) -> Result<String>

Serialize the graph in one of: json (read_graph), mermaid, dot.

Source

pub fn merge_entities(&mut self, source: &str, target: &str) -> Result<Value>

Merge source entity into target entity. All observations from source are moved to target (deduplicated), all relations involving source are redirected to target (deduplicated), and source is then deleted.

The whole merge is atomic: every sub-record is written to the log inside a single TxnBeginTxnCommit transaction before any in-memory mutation. A failed or torn write therefore leaves both memory and the log untouched (an uncommitted transaction is discarded on replay), so the graph can never observe a half-applied merge. Caller flushes.

Source

pub fn extract_subgraph( &self, names: &[String], depth: u32, ) -> Result<KnowledgeGraphOut>

Extract a connected subgraph around one or more seed entity names, expanding out to depth hops along all relations (undirected). Returns the set of reached entities and the relations among them.

Source

pub fn batch_get_entities(&self, names: &[String]) -> Vec<Option<Entity>>

Return full entities for a list of names. Missing names yield None.

Source

pub fn find_all_paths( &self, from: &str, to: &str, max_depth: usize, max_paths: usize, ) -> Result<Vec<Vec<String>>>

Find all simple paths between from and to up to max_depth hops, returning at most max_paths results. Paths are found via DFS with backtracking and include both endpoints.

Source

pub fn snapshot(&self) -> ReadSnapshot

Create a wait-free read snapshot (item 2 in plan). Freezes entity_slots and relations into Arc<[_]> and clones the rest.

Source

pub fn flush_and_sync(&mut self) -> Result<()>

Flush and fsync the log to stable storage.

Trait Implementations§

Source§

impl Deref for WriteGuard<'_>

Source§

type Target = KnowledgeGraph

The resulting type after dereferencing.
Source§

fn deref(&self) -> &KnowledgeGraph

Dereferences the value.
Source§

impl DerefMut for WriteGuard<'_>

Source§

fn deref_mut(&mut self) -> &mut KnowledgeGraph

Mutably dereferences the value.
Source§

impl Drop for WriteGuard<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for WriteGuard<'a>

§

impl<'a> !Send for WriteGuard<'a>

§

impl<'a> !UnwindSafe for WriteGuard<'a>

§

impl<'a> Freeze for WriteGuard<'a>

§

impl<'a> Sync for WriteGuard<'a>

§

impl<'a> Unpin for WriteGuard<'a>

§

impl<'a> UnsafeUnpin for WriteGuard<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more