Skip to main content

KnowledgeObject

Struct KnowledgeObject 

Source
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

  1. oid == BLAKE3(canonical_bytes(payload, edges, embeddings)) — the OID is always consistent with the object’s content.
  2. temporal.system_time is monotonically increasing for successive versions of the same logical entity.
  3. Edges form a DAG for DerivedFrom and Succeeds kinds (no cycles).
  4. 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

Source

pub fn oid(&self) -> ObjectId

The content-addressed object identity.

Source

pub fn kind(&self) -> &ObjectKind

The object’s classification.

Source

pub fn payload(&self) -> &SochValue

The data payload.

Source

pub fn payload_mut(&mut self) -> &mut SochValue

Mutable access to the payload (will invalidate OID — call recompute_oid() after).

Source

pub fn edges(&self) -> &[Edge]

All outgoing edges.

Source

pub fn edges_of_kind(&self, kind: &EdgeKind) -> Vec<&Edge>

Edges filtered by kind.

Source

pub fn edges_valid_at(&self, time: u64) -> Vec<&Edge>

Edges valid at a given time.

Source

pub fn embedding(&self, space: &str) -> Option<&EmbeddingSpace>

Get an embedding by space name.

Source

pub fn embeddings(&self) -> &HashMap<String, EmbeddingSpace>

All embedding spaces.

Source

pub fn primary_embedding(&self) -> Option<&[f32]>

The default/primary embedding vector (in the “semantic” space).

Source

pub fn temporal(&self) -> &BitemporalCoord

The bitemporal coordinate.

Source

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.

Source

pub fn provenance(&self) -> &Provenance

The derivation provenance.

Source

pub fn namespace(&self) -> Option<&str>

The namespace (for multi-tenant isolation).

Source

pub fn tags(&self) -> &[String]

Tags for categorical filtering.

Source

pub fn has_tag(&self, tag: &str) -> bool

Check if this object has a specific tag.

Source

pub fn valid_at(&self, valid_time: u64) -> bool

Is this object valid at the given valid time?

Source

pub fn known_at(&self, system_time: u64) -> bool

Was this object known to the system at the given system time?

Source

pub fn visible_at(&self, system_time: u64, valid_time: u64) -> bool

Combined bitemporal visibility check.

Source

pub fn is_current(&self) -> bool

Is this the current version (valid_to == MAX)?

Source

pub fn attribute(&self, key: &str) -> Option<&SochValue>

Get a named attribute from the payload (assumes payload is SochValue::Object).

Source

pub fn text_attribute(&self, key: &str) -> Option<&str>

Get a text attribute.

Source

pub fn int_attribute(&self, key: &str) -> Option<i64>

Get an integer attribute.

Source

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.

Source

pub fn verify_oid(&self) -> bool

Verify that the stored OID matches the current content.

Source§

impl KnowledgeObject

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, KnowledgeObjectError>

Serialize this Knowledge Object to compact binary format. Uses serde_json for reliable HashMap serialization.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, KnowledgeObjectError>

Deserialize a Knowledge Object from binary format.

Source

pub fn estimated_size(&self) -> usize

Estimated memory footprint of this object (for memory budgeting).

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> KnowledgeObject

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KnowledgeObject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for KnowledgeObject

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for KnowledgeObject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for KnowledgeObject

Source§

impl Hash for KnowledgeObject

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for KnowledgeObject

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for KnowledgeObject

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.