pub struct KnowledgeObject { /* private fields */ }Expand description
The atomic unit of the Knowledge Fabric.
A Knowledge Object co-locates content, relationships, embeddings, temporal metadata, and provenance into a single, content-addressed entity. This co-location enables the fused query execution pipeline that delivers 30–50× latency improvements over disaggregated architectures.
§Invariants
oid == BLAKE3(canonical_bytes(payload, edges, embeddings))— the OID is always consistent with the object’s content.temporal.system_timeis monotonically increasing for successive versions of the same logical entity.- Edges form a DAG for
DerivedFromandSucceedskinds (no cycles). - Embedding dimensions match the declared space dimensionality.
§Thread Safety
KnowledgeObject is Send + Sync (all fields are owned or Arc-wrapped).
Concurrent mutation should go through the MVCC layer — objects themselves
are treated as immutable values (copy-on-write semantics via content addressing).
Implementations§
Source§impl KnowledgeObject
impl KnowledgeObject
Sourcepub fn kind(&self) -> &ObjectKind
pub fn kind(&self) -> &ObjectKind
The object’s classification.
Sourcepub fn payload_mut(&mut self) -> &mut SochValue
pub fn payload_mut(&mut self) -> &mut SochValue
Mutable access to the payload (will invalidate OID — call recompute_oid() after).
Sourcepub fn edges_of_kind(&self, kind: &EdgeKind) -> Vec<&Edge>
pub fn edges_of_kind(&self, kind: &EdgeKind) -> Vec<&Edge>
Edges filtered by kind.
Sourcepub fn edges_valid_at(&self, time: u64) -> Vec<&Edge>
pub fn edges_valid_at(&self, time: u64) -> Vec<&Edge>
Edges valid at a given time.
Sourcepub fn embedding(&self, space: &str) -> Option<&EmbeddingSpace>
pub fn embedding(&self, space: &str) -> Option<&EmbeddingSpace>
Get an embedding by space name.
Sourcepub fn embeddings(&self) -> &HashMap<String, EmbeddingSpace>
pub fn embeddings(&self) -> &HashMap<String, EmbeddingSpace>
All embedding spaces.
Sourcepub fn primary_embedding(&self) -> Option<&[f32]>
pub fn primary_embedding(&self) -> Option<&[f32]>
The default/primary embedding vector (in the “semantic” space).
Sourcepub fn temporal(&self) -> &BitemporalCoord
pub fn temporal(&self) -> &BitemporalCoord
The bitemporal coordinate.
Sourcepub fn set_temporal(&mut self, coord: BitemporalCoord)
pub fn set_temporal(&mut self, coord: BitemporalCoord)
Set the bitemporal coordinate (e.g., to assign HLC system_time on write).
Note: This does NOT change the OID. Temporal coordinates are metadata, not part of the content-addressed identity.
Sourcepub fn provenance(&self) -> &Provenance
pub fn provenance(&self) -> &Provenance
The derivation provenance.
Tags for categorical filtering.
Sourcepub fn known_at(&self, system_time: u64) -> bool
pub fn known_at(&self, system_time: u64) -> bool
Was this object known to the system at the given system time?
Sourcepub fn visible_at(&self, system_time: u64, valid_time: u64) -> bool
pub fn visible_at(&self, system_time: u64, valid_time: u64) -> bool
Combined bitemporal visibility check.
Sourcepub fn is_current(&self) -> bool
pub fn is_current(&self) -> bool
Is this the current version (valid_to == MAX)?
Sourcepub fn attribute(&self, key: &str) -> Option<&SochValue>
pub fn attribute(&self, key: &str) -> Option<&SochValue>
Get a named attribute from the payload (assumes payload is SochValue::Object).
Sourcepub fn text_attribute(&self, key: &str) -> Option<&str>
pub fn text_attribute(&self, key: &str) -> Option<&str>
Get a text attribute.
Sourcepub fn int_attribute(&self, key: &str) -> Option<i64>
pub fn int_attribute(&self, key: &str) -> Option<i64>
Get an integer attribute.
Sourcepub fn recompute_oid(&mut self)
pub fn recompute_oid(&mut self)
Recompute the OID from the current content. Must be called after any mutation to maintain the content-addressing invariant.
Sourcepub fn verify_oid(&self) -> bool
pub fn verify_oid(&self) -> bool
Verify that the stored OID matches the current content.
Source§impl KnowledgeObject
impl KnowledgeObject
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, KnowledgeObjectError>
pub fn to_bytes(&self) -> Result<Vec<u8>, KnowledgeObjectError>
Serialize this Knowledge Object to compact binary format. Uses serde_json for reliable HashMap serialization.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, KnowledgeObjectError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, KnowledgeObjectError>
Deserialize a Knowledge Object from binary format.
Sourcepub fn estimated_size(&self) -> usize
pub fn estimated_size(&self) -> usize
Estimated memory footprint of this object (for memory budgeting).
Sourcepub fn to_compressed_bytes(
&self,
mode: CompressionMode,
) -> Result<Vec<u8>, KnowledgeObjectError>
pub fn to_compressed_bytes( &self, mode: CompressionMode, ) -> Result<Vec<u8>, KnowledgeObjectError>
Serialize with per-object compression.
Wire format: [tag: u8] [original_len: u32 LE] [payload...]
- Tag 0 (
None): payload is raw JSON (original_len == payload.len()). - Tag 1 (
Lz4): payload is LZ4-block-compressed JSON. - Tag 2 (
Zstd): payload is ZSTD-compressed JSON.
Falls back to uncompressed if compressed output >= original size.
Sourcepub fn from_compressed_bytes(bytes: &[u8]) -> Result<Self, KnowledgeObjectError>
pub fn from_compressed_bytes(bytes: &[u8]) -> Result<Self, KnowledgeObjectError>
Deserialize from compressed wire format (auto-detects compression).
The 1-byte tag determines the decompression algorithm.
Sourcepub fn compression_ratio(
&self,
mode: CompressionMode,
) -> Result<f64, KnowledgeObjectError>
pub fn compression_ratio( &self, mode: CompressionMode, ) -> Result<f64, KnowledgeObjectError>
Returns the compression ratio for a given mode (compressed_size / original_size). Values < 1.0 indicate space savings.
Trait Implementations§
Source§impl Clone for KnowledgeObject
impl Clone for KnowledgeObject
Source§fn clone(&self) -> KnowledgeObject
fn clone(&self) -> KnowledgeObject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KnowledgeObject
impl Debug for KnowledgeObject
Source§impl<'de> Deserialize<'de> for KnowledgeObject
impl<'de> Deserialize<'de> for KnowledgeObject
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for KnowledgeObject
impl Display for KnowledgeObject
impl Eq for KnowledgeObject
Source§impl Hash for KnowledgeObject
impl Hash for KnowledgeObject
Source§impl PartialEq for KnowledgeObject
impl PartialEq for KnowledgeObject
Auto Trait Implementations§
impl Freeze for KnowledgeObject
impl RefUnwindSafe for KnowledgeObject
impl Send for KnowledgeObject
impl Sync for KnowledgeObject
impl Unpin for KnowledgeObject
impl UnsafeUnpin for KnowledgeObject
impl UnwindSafe for KnowledgeObject
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.