Skip to main content

GraphStore

Struct GraphStore 

Source
pub struct GraphStore { /* private fields */ }
Expand description

Combined graph and vector store

Implementations§

Source§

impl GraphStore

Source

pub fn open(db_path: &str) -> Result<Self>

Open or create a graph store at the given path

Source

pub fn open_with_config( db_path: &str, index_config: IndexConfig, ) -> Result<Self>

Open or create a graph store with custom index configuration

Source

pub fn in_memory() -> Result<Self>

Open an in-memory graph store (for testing)

Source

pub fn insert_document(&mut self, doc: &Document) -> Result<()>

Insert a document

Source

pub fn get_document(&self, id: Uuid) -> Result<Option<Document>>

Get a document by ID

Source

pub fn get_document_by_path(&self, path: &Path) -> Result<Option<Document>>

Get a document by path

Source

pub fn delete_document(&mut self, id: Uuid) -> Result<()>

Delete a document and its associated chunks/embeddings

Source

pub fn get_all_documents(&self) -> Result<Vec<Document>>

Get all documents

Source

pub fn insert_chunk(&mut self, chunk: &Chunk) -> Result<()>

Insert a chunk

Source

pub fn get_chunks_for_doc(&self, doc_id: Uuid) -> Result<Vec<Chunk>>

Get chunks for a document

Source

pub fn get_chunk(&self, id: Uuid) -> Result<Option<Chunk>>

Get a chunk by ID

Source

pub fn insert_embedding(&mut self, emb: &Embedding) -> Result<()>

Insert an embedding and add it to the HNSW index

Source

pub fn get_embedding_for_chunk( &self, chunk_id: Uuid, ) -> Result<Option<Embedding>>

Get embedding by chunk ID

Source

pub fn get_embedding(&self, id: Uuid) -> Result<Option<Embedding>>

Get embedding by ID

Source

pub fn get_chunk_id_for_embedding( &self, embedding_id: Uuid, ) -> Result<Option<Uuid>>

Get chunk ID for an embedding ID

Source

pub fn get_all_embeddings(&self) -> Result<Vec<Embedding>>

Get all embeddings

Source

pub fn checkpoint_index(&self) -> Result<()>

Checkpoint the HNSW index with current state root

Source

pub fn save_index(&self) -> Result<()>

Save the HNSW index to disk

Source

pub fn add_edge(&mut self, edge: &Edge) -> Result<()>

Add an edge to the graph

Source

pub fn get_edges(&self, node_id: Uuid) -> Result<Vec<Edge>>

Get edges from a node

Source

pub fn edges_to(&self, node_id: Uuid) -> Result<Vec<Edge>>

Get edges to a node

Source

pub fn all_edges(&self) -> Result<Vec<Edge>>

Get all edges

Source

pub fn search(&self, query_vec: &[f32], k: usize) -> Result<Vec<(Uuid, f32)>>

Search for similar embeddings

Source

pub fn search_lexical(&self, query: &str, k: usize) -> Result<Vec<(Uuid, f32)>>

Lexical search using FTS5 Get graph statistics

Source

pub fn get_sorted_chunk_hashes(&self) -> Result<Vec<([u8; 16], [u8; 32])>>

Get all chunk (id, text_hash) pairs sorted by id.

Used for building per-chunk Merkle proofs in proof receipts.

Source

pub fn compute_chunk_tree_root(&self) -> Result<[u8; 32]>

Compute a proper binary Merkle tree root over all chunk text hashes.

Unlike compute_merkle_root() which uses a streaming hasher over all entities, this builds a binary Merkle tree that supports per-chunk inclusion proofs.

Source

pub fn compute_merkle_root(&self) -> Result<[u8; 32]>

Compute Merkle root of the current state

This is strictly semantic and content-addressable. It does NOT include timestamps, UUIDs (except as IDs for relationships), or device-specific metadata.

Source

pub fn get_state_root_by_hash( &self, hash: &[u8; 32], ) -> Result<Option<StateRoot>>

Get a state root by hash

Source

pub fn get_latest_root(&self) -> Result<Option<StateRoot>>

Get the latest state root

Source

pub fn set_latest_root(&mut self, root: &StateRoot) -> Result<()>

Set the latest state root

Source

pub fn apply_diff(&mut self, diff: &CognitiveDiff) -> Result<()>

Apply a cognitive diff to the graph store with conflict resolution.

Per CP-013 §13: Uses Last-Writer-Wins (LWW) with Hybrid Logical Clocks (HLC) for deterministic conflict resolution:

  1. Compare HLC timestamps - later one wins
  2. If timestamps equal, use hash tiebreaker (lexicographically higher wins)
Source

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

Clear only state roots (used when pairing with a new device to force full snapshot push)

Source

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

Clear all data from the graph store (for fresh sync)

Source

pub fn stats(&self) -> Result<GraphStats>

Get statistics about the graph store

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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