pub struct MemoryDatabase { /* private fields */ }Expand description
Database connection manager
Implementations§
Source§impl MemoryDatabase
impl MemoryDatabase
Sourcepub async fn new(db_path: &Path) -> MemoryResult<Self>
pub async fn new(db_path: &Path) -> MemoryResult<Self>
Initialize or open the memory database
Sourcepub async fn validate_vector_tables(&self) -> MemoryResult<()>
pub async fn validate_vector_tables(&self) -> MemoryResult<()>
Validate that sqlite-vec tables are readable. This catches legacy/corrupted vector blobs early so startup can recover.
Sourcepub async fn ensure_vector_tables_healthy(&self) -> MemoryResult<bool>
pub async fn ensure_vector_tables_healthy(&self) -> MemoryResult<bool>
Ensure vector tables are readable and recreate them if corruption is detected. Returns true when a repair was performed.
Sourcepub async fn store_chunk(
&self,
chunk: &MemoryChunk,
embedding: &[f32],
) -> MemoryResult<()>
pub async fn store_chunk( &self, chunk: &MemoryChunk, embedding: &[f32], ) -> MemoryResult<()>
Store a chunk with its embedding
Sourcepub async fn search_similar(
&self,
query_embedding: &[f32],
tier: MemoryTier,
project_id: Option<&str>,
session_id: Option<&str>,
limit: i64,
) -> MemoryResult<Vec<(MemoryChunk, f64)>>
pub async fn search_similar( &self, query_embedding: &[f32], tier: MemoryTier, project_id: Option<&str>, session_id: Option<&str>, limit: i64, ) -> MemoryResult<Vec<(MemoryChunk, f64)>>
Search for similar chunks
Sourcepub async fn get_session_chunks(
&self,
session_id: &str,
) -> MemoryResult<Vec<MemoryChunk>>
pub async fn get_session_chunks( &self, session_id: &str, ) -> MemoryResult<Vec<MemoryChunk>>
Get chunks by session ID
Sourcepub async fn get_project_chunks(
&self,
project_id: &str,
) -> MemoryResult<Vec<MemoryChunk>>
pub async fn get_project_chunks( &self, project_id: &str, ) -> MemoryResult<Vec<MemoryChunk>>
Get chunks by project ID
Sourcepub async fn get_global_chunks(
&self,
limit: i64,
) -> MemoryResult<Vec<MemoryChunk>>
pub async fn get_global_chunks( &self, limit: i64, ) -> MemoryResult<Vec<MemoryChunk>>
Get global chunks
Sourcepub async fn clear_session_memory(&self, session_id: &str) -> MemoryResult<u64>
pub async fn clear_session_memory(&self, session_id: &str) -> MemoryResult<u64>
Clear session memory
Sourcepub async fn clear_project_memory(&self, project_id: &str) -> MemoryResult<u64>
pub async fn clear_project_memory(&self, project_id: &str) -> MemoryResult<u64>
Clear project memory
Sourcepub async fn cleanup_old_sessions(
&self,
retention_days: i64,
) -> MemoryResult<u64>
pub async fn cleanup_old_sessions( &self, retention_days: i64, ) -> MemoryResult<u64>
Clear old session memory based on retention policy
Sourcepub async fn get_or_create_config(
&self,
project_id: &str,
) -> MemoryResult<MemoryConfig>
pub async fn get_or_create_config( &self, project_id: &str, ) -> MemoryResult<MemoryConfig>
Get or create memory config for a project
Sourcepub async fn update_config(
&self,
project_id: &str,
config: &MemoryConfig,
) -> MemoryResult<()>
pub async fn update_config( &self, project_id: &str, config: &MemoryConfig, ) -> MemoryResult<()>
Update memory config for a project
Sourcepub async fn get_stats(&self) -> MemoryResult<MemoryStats>
pub async fn get_stats(&self) -> MemoryResult<MemoryStats>
Get memory statistics
Sourcepub async fn log_cleanup(
&self,
cleanup_type: &str,
tier: MemoryTier,
project_id: Option<&str>,
session_id: Option<&str>,
chunks_deleted: i64,
bytes_reclaimed: i64,
) -> MemoryResult<()>
pub async fn log_cleanup( &self, cleanup_type: &str, tier: MemoryTier, project_id: Option<&str>, session_id: Option<&str>, chunks_deleted: i64, bytes_reclaimed: i64, ) -> MemoryResult<()>
Log cleanup operation
Sourcepub async fn vacuum(&self) -> MemoryResult<()>
pub async fn vacuum(&self) -> MemoryResult<()>
Vacuum the database to reclaim space
pub async fn project_file_index_count( &self, project_id: &str, ) -> MemoryResult<i64>
pub async fn project_has_file_chunks( &self, project_id: &str, ) -> MemoryResult<bool>
pub async fn get_file_index_entry( &self, project_id: &str, path: &str, ) -> MemoryResult<Option<(i64, i64, String)>>
pub async fn upsert_file_index_entry( &self, project_id: &str, path: &str, mtime: i64, size: i64, hash: &str, ) -> MemoryResult<()>
pub async fn delete_file_index_entry( &self, project_id: &str, path: &str, ) -> MemoryResult<()>
pub async fn list_file_index_paths( &self, project_id: &str, ) -> MemoryResult<Vec<String>>
pub async fn delete_project_file_chunks_by_path( &self, project_id: &str, source_path: &str, ) -> MemoryResult<(i64, i64)>
pub async fn upsert_project_index_status( &self, project_id: &str, total_files: i64, processed_files: i64, indexed_files: i64, skipped_files: i64, errors: i64, ) -> MemoryResult<()>
pub async fn get_project_stats( &self, project_id: &str, ) -> MemoryResult<ProjectMemoryStats>
pub async fn clear_project_file_index( &self, project_id: &str, vacuum: bool, ) -> MemoryResult<ClearFileIndexResult>
Auto Trait Implementations§
impl Freeze for MemoryDatabase
impl !RefUnwindSafe for MemoryDatabase
impl Send for MemoryDatabase
impl Sync for MemoryDatabase
impl Unpin for MemoryDatabase
impl UnsafeUnpin for MemoryDatabase
impl !UnwindSafe for MemoryDatabase
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