pub struct VersionedEngram {
pub chunk_store: VersionedChunkStore,
pub corrections: VersionedCorrectionStore,
pub manifest: VersionedManifest,
/* private fields */
}Expand description
A fully versioned engram with optimistic locking
This is the top-level structure that coordinates all versioned components. It provides high-level read/write operations with ACID-like properties.
Fields§
§chunk_store: VersionedChunkStoreVersioned chunk store (NOT the VSA codebook - that’s in embeddenator-vsa)
corrections: VersionedCorrectionStoreVersioned corrections
manifest: VersionedManifestVersioned manifest
Implementations§
Source§impl VersionedEngram
impl VersionedEngram
Sourcepub fn new(_dimensionality: usize) -> Self
pub fn new(_dimensionality: usize) -> Self
Create a new versioned engram with default dimensionality
§Arguments
dimensionality- Reserved for future use. The actual dimensionality is determined bySparseVec::new()which uses the system’s configured default. This parameter is preserved in the API for future VSA codebook integration when the dimensionality becomes configurable.
Sourcepub fn with_root(root: Arc<SparseVec>) -> Self
pub fn with_root(root: Arc<SparseVec>) -> Self
Create a versioned engram with an existing root vector
Sourcepub fn root_version(&self) -> u64
pub fn root_version(&self) -> u64
Get the current root version
Sourcepub fn update_root(
&self,
new_root: Arc<SparseVec>,
expected_version: u64,
) -> VersionedResult<u64>
pub fn update_root( &self, new_root: Arc<SparseVec>, expected_version: u64, ) -> VersionedResult<u64>
Update the root vector with Compare-And-Swap (CAS)
This is the core operation for optimistic locking on the root. It attempts to update the root only if the current version matches the expected version.
Sourcepub fn bundle_chunk(&self, chunk_vec: &SparseVec) -> Result<u64, String>
pub fn bundle_chunk(&self, chunk_vec: &SparseVec) -> Result<u64, String>
Bundle a chunk into the root with automatic retry
This operation superimposes a new chunk vector into the root using the VSA bundle operation (XOR for binary vectors). The bundling is performed with optimistic locking and automatic retry on version conflicts.
§Algorithm
- Read current root and its version
- Create new root by bundling:
new_root = current_root ⊕ chunk_vec - Attempt CAS update with optimistic locking
- Retry with exponential backoff if version conflict detected
§Arguments
chunk_vec- The chunk vector to bundle into the root
§Returns
Ok(new_version)- The new root version after successful bundleErr(e)- Error after max retries exceeded or other failure
Sourcepub fn begin_transaction(&self) -> Transaction
pub fn begin_transaction(&self) -> Transaction
Begin a new transaction
Sourcepub fn commit_transaction(&self, tx: Transaction) -> Result<(), String>
pub fn commit_transaction(&self, tx: Transaction) -> Result<(), String>
Commit a transaction
Sourcepub fn abort_transaction(&self, tx: Transaction)
pub fn abort_transaction(&self, tx: Transaction)
Abort a transaction
Sourcepub fn transaction_stats(&self) -> TransactionStats
pub fn transaction_stats(&self) -> TransactionStats
Get transaction statistics
Sourcepub fn stats(&self) -> EngramStats
pub fn stats(&self) -> EngramStats
Get comprehensive engram statistics
Trait Implementations§
Source§impl Clone for VersionedEngram
impl Clone for VersionedEngram
Auto Trait Implementations§
impl !Freeze for VersionedEngram
impl RefUnwindSafe for VersionedEngram
impl Send for VersionedEngram
impl Sync for VersionedEngram
impl Unpin for VersionedEngram
impl UnwindSafe for VersionedEngram
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> 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 more