pub struct SqliteStorage { /* private fields */ }Expand description
SQLite-based storage implementation.
Provides persistent storage for RLM state with full ACID guarantees.
§Examples
use rlm_rs::storage::{SqliteStorage, Storage};
let mut storage = SqliteStorage::open("rlm-state.db").unwrap();
storage.init().unwrap();Implementations§
Source§impl SqliteStorage
impl SqliteStorage
Source§impl SqliteStorage
impl SqliteStorage
Sourcepub fn store_embedding(
&mut self,
chunk_id: i64,
embedding: &[f32],
model_name: Option<&str>,
) -> Result<()>
pub fn store_embedding( &mut self, chunk_id: i64, embedding: &[f32], model_name: Option<&str>, ) -> Result<()>
Sourcepub fn get_embedding_models(&self, buffer_id: i64) -> Result<Vec<String>>
pub fn get_embedding_models(&self, buffer_id: i64) -> Result<Vec<String>>
Gets the distinct model names used for embeddings in a buffer.
Returns the set of model names used to generate embeddings for chunks belonging to the specified buffer.
§Errors
Returns an error if the query fails.
Sourcepub fn get_embedding_model_counts(
&self,
buffer_id: i64,
) -> Result<Vec<(Option<String>, i64)>>
pub fn get_embedding_model_counts( &self, buffer_id: i64, ) -> Result<Vec<(Option<String>, i64)>>
Gets the count of embeddings by model name for a buffer.
Returns a list of (model_name, count) pairs.
§Errors
Returns an error if the query fails.
Sourcepub fn store_embeddings_batch(
&mut self,
embeddings: &[(i64, Vec<f32>)],
model_name: Option<&str>,
) -> Result<()>
pub fn store_embeddings_batch( &mut self, embeddings: &[(i64, Vec<f32>)], model_name: Option<&str>, ) -> Result<()>
Stores embeddings for multiple chunks in a batch.
§Errors
Returns an error if any embedding cannot be stored.
Sourcepub fn delete_embedding(&mut self, chunk_id: i64) -> Result<()>
pub fn delete_embedding(&mut self, chunk_id: i64) -> Result<()>
Sourcepub fn get_all_embeddings(&self) -> Result<Vec<(i64, Vec<f32>)>>
pub fn get_all_embeddings(&self) -> Result<Vec<(i64, Vec<f32>)>>
Returns all chunk embeddings for vector similarity search.
§Errors
Returns an error if the query fails.
Sourcepub fn embedding_count(&self) -> Result<usize>
pub fn embedding_count(&self) -> Result<usize>
Sourcepub fn has_embedding(&self, chunk_id: i64) -> Result<bool>
pub fn has_embedding(&self, chunk_id: i64) -> Result<bool>
Sourcepub fn get_chunks_needing_embedding(
&self,
buffer_id: i64,
current_model: Option<&str>,
) -> Result<Vec<i64>>
pub fn get_chunks_needing_embedding( &self, buffer_id: i64, current_model: Option<&str>, ) -> Result<Vec<i64>>
Gets chunk IDs that need embedding (either no embedding or wrong model).
This is used for incremental embedding updates. Returns chunks that:
- Have no embedding at all, OR
- Have an embedding with a different model name (if
current_modelis provided)
§Arguments
buffer_id- The buffer to check.current_model- Optional model name to check against. If provided, chunks with different models are included.
§Errors
Returns an error if the query fails.
Sourcepub fn get_chunks_without_embedding(&self, buffer_id: i64) -> Result<Vec<i64>>
pub fn get_chunks_without_embedding(&self, buffer_id: i64) -> Result<Vec<i64>>
Gets chunks without any embedding for a buffer.
Simpler version of get_chunks_needing_embedding when model doesn’t matter.
§Errors
Returns an error if the query fails.
Sourcepub fn delete_embeddings_by_model(
&mut self,
buffer_id: i64,
model_name: Option<&str>,
) -> Result<usize>
pub fn delete_embeddings_by_model( &mut self, buffer_id: i64, model_name: Option<&str>, ) -> Result<usize>
Deletes embeddings with a specific model name.
Useful for cleaning up embeddings from old models before re-embedding.
§Arguments
buffer_id- The buffer to clean.model_name- The model name to match (or None to match NULL).
§Returns
The number of embeddings deleted.
§Errors
Returns an error if deletion fails.
Sourcepub fn get_embedding_stats(&self, buffer_id: i64) -> Result<EmbeddingStats>
pub fn get_embedding_stats(&self, buffer_id: i64) -> Result<EmbeddingStats>
Gets embedding statistics for a buffer.
Returns counts of embedded vs total chunks, and model breakdown.
§Errors
Returns an error if the query fails.
Trait Implementations§
Source§impl Storage for SqliteStorage
impl Storage for SqliteStorage
Source§fn init(&mut self) -> Result<()>
fn init(&mut self) -> Result<()>
Source§fn save_context(&mut self, context: &Context) -> Result<()>
fn save_context(&mut self, context: &Context) -> Result<()>
Source§fn get_buffer_by_name(&self, name: &str) -> Result<Option<Buffer>>
fn get_buffer_by_name(&self, name: &str) -> Result<Option<Buffer>>
Source§fn update_buffer(&mut self, buffer: &Buffer) -> Result<()>
fn update_buffer(&mut self, buffer: &Buffer) -> Result<()>
Source§fn add_chunks(&mut self, buffer_id: i64, chunks: &[Chunk]) -> Result<()>
fn add_chunks(&mut self, buffer_id: i64, chunks: &[Chunk]) -> Result<()>
Source§fn get_chunks(&self, buffer_id: i64) -> Result<Vec<Chunk>>
fn get_chunks(&self, buffer_id: i64) -> Result<Vec<Chunk>>
Source§fn get_chunk(&self, id: i64) -> Result<Option<Chunk>>
fn get_chunk(&self, id: i64) -> Result<Option<Chunk>>
Source§fn delete_chunks(&mut self, buffer_id: i64) -> Result<()>
fn delete_chunks(&mut self, buffer_id: i64) -> Result<()>
Source§fn chunk_count(&self, buffer_id: i64) -> Result<usize>
fn chunk_count(&self, buffer_id: i64) -> Result<usize>
Auto Trait Implementations§
impl !Freeze for SqliteStorage
impl !RefUnwindSafe for SqliteStorage
impl Send for SqliteStorage
impl !Sync for SqliteStorage
impl Unpin for SqliteStorage
impl !UnwindSafe for SqliteStorage
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> 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