pub struct GraphStore { /* private fields */ }Expand description
Combined graph and vector store
Implementations§
Source§impl GraphStore
impl GraphStore
Sourcepub fn open_with_config(
db_path: &str,
index_config: IndexConfig,
) -> Result<Self>
pub fn open_with_config( db_path: &str, index_config: IndexConfig, ) -> Result<Self>
Open or create a graph store with custom index configuration
Sourcepub fn insert_document(&mut self, doc: &Document) -> Result<()>
pub fn insert_document(&mut self, doc: &Document) -> Result<()>
Insert a document
Sourcepub fn get_document_by_path(&self, path: &Path) -> Result<Option<Document>>
pub fn get_document_by_path(&self, path: &Path) -> Result<Option<Document>>
Get a document by path
Sourcepub fn delete_document(&mut self, id: Uuid) -> Result<()>
pub fn delete_document(&mut self, id: Uuid) -> Result<()>
Delete a document and its associated chunks/embeddings
Sourcepub fn get_all_documents(&self) -> Result<Vec<Document>>
pub fn get_all_documents(&self) -> Result<Vec<Document>>
Get all documents
Sourcepub fn insert_chunk(&mut self, chunk: &Chunk) -> Result<()>
pub fn insert_chunk(&mut self, chunk: &Chunk) -> Result<()>
Insert a chunk
Sourcepub fn insert_embedding(&mut self, emb: &Embedding) -> Result<()>
pub fn insert_embedding(&mut self, emb: &Embedding) -> Result<()>
Insert an embedding and add it to the HNSW index
Sourcepub fn get_embedding_for_chunk(
&self,
chunk_id: Uuid,
) -> Result<Option<Embedding>>
pub fn get_embedding_for_chunk( &self, chunk_id: Uuid, ) -> Result<Option<Embedding>>
Get embedding by chunk ID
Sourcepub fn get_chunk_id_for_embedding(
&self,
embedding_id: Uuid,
) -> Result<Option<Uuid>>
pub fn get_chunk_id_for_embedding( &self, embedding_id: Uuid, ) -> Result<Option<Uuid>>
Get chunk ID for an embedding ID
Sourcepub fn get_all_embeddings(&self) -> Result<Vec<Embedding>>
pub fn get_all_embeddings(&self) -> Result<Vec<Embedding>>
Get all embeddings
Sourcepub fn checkpoint_index(&self) -> Result<()>
pub fn checkpoint_index(&self) -> Result<()>
Checkpoint the HNSW index with current state root
Sourcepub fn save_index(&self) -> Result<()>
pub fn save_index(&self) -> Result<()>
Save the HNSW index to disk
Sourcepub fn search(&self, query_vec: &[f32], k: usize) -> Result<Vec<(Uuid, f32)>>
pub fn search(&self, query_vec: &[f32], k: usize) -> Result<Vec<(Uuid, f32)>>
Search for similar embeddings
Sourcepub fn search_lexical(&self, query: &str, k: usize) -> Result<Vec<(Uuid, f32)>>
pub fn search_lexical(&self, query: &str, k: usize) -> Result<Vec<(Uuid, f32)>>
Lexical search using FTS5 Get graph statistics
Sourcepub fn get_sorted_chunk_hashes(&self) -> Result<Vec<([u8; 16], [u8; 32])>>
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.
Sourcepub fn compute_chunk_tree_root(&self) -> Result<[u8; 32]>
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.
Sourcepub fn compute_merkle_root(&self) -> Result<[u8; 32]>
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.
Sourcepub fn get_state_root_by_hash(
&self,
hash: &[u8; 32],
) -> Result<Option<StateRoot>>
pub fn get_state_root_by_hash( &self, hash: &[u8; 32], ) -> Result<Option<StateRoot>>
Get a state root by hash
Sourcepub fn get_latest_root(&self) -> Result<Option<StateRoot>>
pub fn get_latest_root(&self) -> Result<Option<StateRoot>>
Get the latest state root
Sourcepub fn set_latest_root(&mut self, root: &StateRoot) -> Result<()>
pub fn set_latest_root(&mut self, root: &StateRoot) -> Result<()>
Set the latest state root
Sourcepub fn apply_diff(&mut self, diff: &CognitiveDiff) -> Result<()>
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:
- Compare HLC timestamps - later one wins
- If timestamps equal, use hash tiebreaker (lexicographically higher wins)
Sourcepub fn clear_state_roots(&mut self) -> Result<()>
pub fn clear_state_roots(&mut self) -> Result<()>
Clear only state roots (used when pairing with a new device to force full snapshot push)
Sourcepub fn stats(&self) -> Result<GraphStats>
pub fn stats(&self) -> Result<GraphStats>
Get statistics about the graph store