Skip to main content

RedbStorage

Struct RedbStorage 

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

redb storage engine wrapper.

This struct holds the redb database handle and cached metadata. It implements StorageEngine for use with PulseDB.

§Thread Safety

RedbStorage is Send + Sync. redb handles internal synchronization using MVCC for readers and exclusive locking for writers.

Implementations§

Source§

impl RedbStorage

Source

pub fn open(path: impl AsRef<Path>, config: &Config) -> Result<Self>

Opens or creates a database at the given path.

If the database doesn’t exist, it will be created and initialized with the configuration settings. If it exists, the configuration will be validated against the stored metadata.

§Arguments
  • path - Path to the database file
  • config - Database configuration
§Errors

Returns an error if:

  • The database file is corrupted
  • The database is locked by another process
  • Schema version doesn’t match
  • Embedding dimension doesn’t match (for existing databases)
§Example
use pulsedb::{Config, storage::RedbStorage};

let storage = RedbStorage::open(dir.path().join("test.db"), &Config::default())?;
Source

pub fn embedding_dimension(&self) -> EmbeddingDimension

Returns the embedding dimension configured for this database.

Trait Implementations§

Source§

impl Debug for RedbStorage

Source§

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

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

impl StorageEngine for RedbStorage

Source§

fn metadata(&self) -> &DatabaseMetadata

Returns the database metadata. Read more
Source§

fn close(self: Box<Self>) -> Result<()>

Closes the storage engine, flushing any pending writes. Read more
Source§

fn path(&self) -> Option<&Path>

Returns the path to the database file, if applicable. Read more
Source§

fn save_collective(&self, collective: &Collective) -> Result<()>

Saves a collective to storage. Read more
Source§

fn get_collective(&self, id: CollectiveId) -> Result<Option<Collective>>

Retrieves a collective by ID. Read more
Source§

fn list_collectives(&self) -> Result<Vec<Collective>>

Lists all collectives in the database. Read more
Source§

fn delete_collective(&self, id: CollectiveId) -> Result<bool>

Deletes a collective by ID. Read more
Source§

fn count_experiences_in_collective(&self, id: CollectiveId) -> Result<u64>

Counts experiences belonging to a collective. Read more
Source§

fn delete_experiences_by_collective(&self, id: CollectiveId) -> Result<u64>

Deletes all experiences and related index entries for a collective. Read more
Source§

fn list_experience_ids_in_collective( &self, id: CollectiveId, ) -> Result<Vec<ExperienceId>>

Lists all experience IDs belonging to a collective. Read more
Source§

fn get_recent_experience_ids( &self, collective_id: CollectiveId, limit: usize, ) -> Result<Vec<(ExperienceId, Timestamp)>>

Retrieves the most recent experience IDs in a collective. Read more
Source§

fn save_experience(&self, experience: &Experience) -> Result<()>

Saves an experience and its embedding to storage. Read more
Source§

fn get_experience(&self, id: ExperienceId) -> Result<Option<Experience>>

Retrieves an experience by ID, including its embedding. Read more
Source§

fn update_experience( &self, id: ExperienceId, update: &ExperienceUpdate, ) -> Result<bool>

Updates mutable fields of an experience. Read more
Source§

fn delete_experience(&self, id: ExperienceId) -> Result<bool>

Permanently deletes an experience and its embedding. Read more
Source§

fn reinforce_experience(&self, id: ExperienceId) -> Result<Option<u32>>

Atomically increments the applications counter for an experience. Read more
Source§

fn save_embedding(&self, id: ExperienceId, embedding: &[f32]) -> Result<()>

Saves an embedding vector to storage. Read more
Source§

fn get_embedding(&self, id: ExperienceId) -> Result<Option<Vec<f32>>>

Retrieves an embedding vector by experience ID. Read more
Source§

fn save_relation(&self, relation: &ExperienceRelation) -> Result<()>

Saves a relation and its index entries atomically. Read more
Source§

fn get_relation(&self, id: RelationId) -> Result<Option<ExperienceRelation>>

Retrieves a relation by ID. Read more
Source§

fn delete_relation(&self, id: RelationId) -> Result<bool>

Deletes a relation and its index entries atomically. Read more
Source§

fn get_relation_ids_by_source( &self, experience_id: ExperienceId, ) -> Result<Vec<RelationId>>

Finds all relation IDs where the given experience is the source. Read more
Source§

fn get_relation_ids_by_target( &self, experience_id: ExperienceId, ) -> Result<Vec<RelationId>>

Finds all relation IDs where the given experience is the target. Read more
Source§

fn delete_relations_for_experience( &self, experience_id: ExperienceId, ) -> Result<u64>

Deletes all relations where the given experience is source or target. Read more
Source§

fn relation_exists( &self, source_id: ExperienceId, target_id: ExperienceId, relation_type: RelationType, ) -> Result<bool>

Checks if a relation with the same (source, target, type) already exists. Read more
Source§

fn save_insight(&self, insight: &DerivedInsight) -> Result<()>

Saves a derived insight and its index entries atomically. Read more
Source§

fn get_insight(&self, id: InsightId) -> Result<Option<DerivedInsight>>

Retrieves a derived insight by ID. Read more
Source§

fn delete_insight(&self, id: InsightId) -> Result<bool>

Deletes a derived insight and its index entries atomically. Read more
Source§

fn list_insight_ids_in_collective( &self, id: CollectiveId, ) -> Result<Vec<InsightId>>

Lists all insight IDs belonging to a collective. Read more
Source§

fn delete_insights_by_collective(&self, id: CollectiveId) -> Result<u64>

Deletes all insights belonging to a collective. Read more
Source§

fn save_activity(&self, activity: &Activity) -> Result<()>

Saves an agent activity to storage (upsert). Read more
Source§

fn get_activity( &self, agent_id: &str, collective_id: CollectiveId, ) -> Result<Option<Activity>>

Retrieves an agent activity by agent ID and collective. Read more
Source§

fn delete_activity( &self, agent_id: &str, collective_id: CollectiveId, ) -> Result<bool>

Deletes an agent activity. Read more
Source§

fn list_activities_in_collective( &self, collective_id: CollectiveId, ) -> Result<Vec<Activity>>

Lists all activities in a collective. Read more
Source§

fn delete_activities_by_collective( &self, collective_id: CollectiveId, ) -> Result<u64>

Deletes all activities belonging to a collective. Read more
Source§

fn list_experience_ids_paginated( &self, collective_id: CollectiveId, limit: usize, offset: usize, ) -> Result<Vec<ExperienceId>>

Lists experience IDs in a collective with pagination. Read more
Source§

fn list_relations_in_collective( &self, collective_id: CollectiveId, limit: usize, offset: usize, ) -> Result<Vec<ExperienceRelation>>

Lists all relations in a collective with pagination. Read more
Source§

fn list_insight_ids_paginated( &self, collective_id: CollectiveId, limit: usize, offset: usize, ) -> Result<Vec<InsightId>>

Lists insight IDs in a collective with pagination.
Source§

fn get_wal_sequence(&self) -> Result<u64>

Returns the current WAL sequence number. Read more
Source§

fn poll_watch_events( &self, since_seq: u64, limit: usize, ) -> Result<(Vec<WatchEventRecord>, u64)>

Retrieves watch events with sequence numbers greater than since_seq. Read more
Source§

fn poll_sync_events( &self, since_seq: u64, limit: usize, ) -> Result<Vec<(u64, WatchEventRecord)>>

Available on crate feature sync only.
Retrieves ALL watch events (all entity types) with their sequence numbers. Read more
Source§

fn instance_id(&self) -> InstanceId

Available on crate feature sync only.
Returns the persistent instance ID for this database. Read more
Source§

fn save_sync_cursor(&self, cursor: &SyncCursor) -> Result<()>

Available on crate feature sync only.
Saves a sync cursor for a peer instance. Read more
Source§

fn load_sync_cursor( &self, instance_id: &InstanceId, ) -> Result<Option<SyncCursor>>

Available on crate feature sync only.
Loads the sync cursor for a specific peer instance. Read more
Source§

fn list_sync_cursors(&self) -> Result<Vec<SyncCursor>>

Available on crate feature sync only.
Lists all saved sync cursors. Read more
Source§

fn compact_wal_events(&self, up_to_seq: u64) -> Result<u64>

Available on crate feature sync only.
Compacts the WAL by deleting events with sequence <= up_to_seq. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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