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
impl RedbStorage
Sourcepub fn open(path: impl AsRef<Path>, config: &Config) -> Result<Self>
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 fileconfig- 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())?;Sourcepub fn embedding_dimension(&self) -> EmbeddingDimension
pub fn embedding_dimension(&self) -> EmbeddingDimension
Returns the embedding dimension configured for this database.
Trait Implementations§
Source§impl Debug for RedbStorage
impl Debug for RedbStorage
Source§impl StorageEngine for RedbStorage
impl StorageEngine for RedbStorage
Source§fn metadata(&self) -> &DatabaseMetadata
fn metadata(&self) -> &DatabaseMetadata
Returns the database metadata. Read more
Source§fn close(self: Box<Self>) -> Result<()>
fn close(self: Box<Self>) -> Result<()>
Closes the storage engine, flushing any pending writes. Read more
Source§fn path(&self) -> Option<&Path>
fn path(&self) -> Option<&Path>
Returns the path to the database file, if applicable. Read more
Source§fn save_collective(&self, collective: &Collective) -> Result<()>
fn save_collective(&self, collective: &Collective) -> Result<()>
Saves a collective to storage. Read more
Source§fn get_collective(&self, id: CollectiveId) -> Result<Option<Collective>>
fn get_collective(&self, id: CollectiveId) -> Result<Option<Collective>>
Retrieves a collective by ID. Read more
Source§fn list_collectives(&self) -> Result<Vec<Collective>>
fn list_collectives(&self) -> Result<Vec<Collective>>
Lists all collectives in the database. Read more
Source§fn delete_collective(&self, id: CollectiveId) -> Result<bool>
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>
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>
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>>
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)>>
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<()>
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>>
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>
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>
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>>
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<()>
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>>>
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<()>
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>>
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>
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>>
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>>
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>
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>
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<()>
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>>
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>
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>>
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>
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<()>
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>>
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>
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>>
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>
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>>
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>>
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>>
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 poll_watch_events(
&self,
since_seq: u64,
limit: usize,
) -> Result<(Vec<WatchEventRecord>, u64)>
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 moreSource§fn poll_sync_events(
&self,
since_seq: u64,
limit: usize,
) -> Result<Vec<(u64, WatchEventRecord)>>
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
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<()>
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>>
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>>
fn list_sync_cursors(&self) -> Result<Vec<SyncCursor>>
Available on crate feature
sync only.Lists all saved sync cursors. Read more
Auto Trait Implementations§
impl Freeze for RedbStorage
impl !RefUnwindSafe for RedbStorage
impl Send for RedbStorage
impl Sync for RedbStorage
impl Unpin for RedbStorage
impl UnsafeUnpin for RedbStorage
impl !UnwindSafe for RedbStorage
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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