pub struct SemanticFactStore { /* private fields */ }Expand description
Storage for semantic facts with indexing
Implementations§
Source§impl SemanticFactStore
impl SemanticFactStore
Sourcepub fn databases(&self) -> Vec<(&str, &Arc<DB>)>
pub fn databases(&self) -> Vec<(&str, &Arc<DB>)>
Get references to all RocksDB databases for backup
Sourcepub fn store_batch(
&self,
user_id: &str,
facts: &[SemanticFact],
) -> Result<usize>
pub fn store_batch( &self, user_id: &str, facts: &[SemanticFact], ) -> Result<usize>
Store multiple facts in a batch
Sourcepub fn get(&self, user_id: &str, fact_id: &str) -> Result<Option<SemanticFact>>
pub fn get(&self, user_id: &str, fact_id: &str) -> Result<Option<SemanticFact>>
Get a fact by ID
Sourcepub fn update(&self, user_id: &str, fact: &SemanticFact) -> Result<()>
pub fn update(&self, user_id: &str, fact: &SemanticFact) -> Result<()>
Update an existing fact (for reinforcement)
Sourcepub fn list(&self, user_id: &str, limit: usize) -> Result<Vec<SemanticFact>>
pub fn list(&self, user_id: &str, limit: usize) -> Result<Vec<SemanticFact>>
List all facts for a user
Sourcepub fn find_by_entity(
&self,
user_id: &str,
entity: &str,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn find_by_entity( &self, user_id: &str, entity: &str, limit: usize, ) -> Result<Vec<SemanticFact>>
Find facts by related entity
Sourcepub fn find_by_type(
&self,
user_id: &str,
fact_type: FactType,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn find_by_type( &self, user_id: &str, fact_type: FactType, limit: usize, ) -> Result<Vec<SemanticFact>>
Find facts by type
Sourcepub fn search(
&self,
user_id: &str,
query: &str,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn search( &self, user_id: &str, query: &str, limit: usize, ) -> Result<Vec<SemanticFact>>
Search facts by keyword in fact content
Sourcepub fn latest_fact_created_at(&self, user_id: &str) -> Option<i64>
pub fn latest_fact_created_at(&self, user_id: &str) -> Option<i64>
Find the creation timestamp of the most recent fact for a user.
Used at startup to initialize the fact extraction watermark when no persisted watermark exists. Returns None if user has no facts.
Sourcepub fn find_decaying_facts(
&self,
user_id: &str,
max_age_days: i64,
) -> Result<Vec<SemanticFact>>
pub fn find_decaying_facts( &self, user_id: &str, max_age_days: i64, ) -> Result<Vec<SemanticFact>>
Find facts that should decay (no reinforcement for too long)
Sourcepub fn find_similar(
&self,
user_id: &str,
fact_content: &str,
fact_entities: &[String],
new_embedding: Option<&[f32]>,
) -> Result<Option<SemanticFact>>
pub fn find_similar( &self, user_id: &str, fact_content: &str, fact_entities: &[String], new_embedding: Option<&[f32]>, ) -> Result<Option<SemanticFact>>
Check if a similar fact already exists (hybrid dedup)
Multi-gate pipeline when embedding is provided:
- Entity gate: at least 1 shared entity, OR both have zero entities
- Polarity gate: same negation polarity (prevents merging contradictions)
- Cosine gate: embedding similarity >= FACT_DEDUP_COSINE_THRESHOLD
- Jaccard floor: word overlap >= FACT_DEDUP_JACCARD_FLOOR
Falls back to pure Jaccard (0.70) if no embedding is provided.
Sourcepub fn store_embedding(
&self,
user_id: &str,
fact_id: &str,
embedding: &[f32],
) -> Result<()>
pub fn store_embedding( &self, user_id: &str, fact_id: &str, embedding: &[f32], ) -> Result<()>
Store pre-computed embedding vector for a fact
Key format: facts_embedding:{user_id}:{fact_id} → bincode Vec
Sourcepub fn get_embedding(
&self,
user_id: &str,
fact_id: &str,
) -> Result<Option<Vec<f32>>>
pub fn get_embedding( &self, user_id: &str, fact_id: &str, ) -> Result<Option<Vec<f32>>>
Get pre-computed embedding vector for a fact
Auto Trait Implementations§
impl Freeze for SemanticFactStore
impl RefUnwindSafe for SemanticFactStore
impl Send for SemanticFactStore
impl Sync for SemanticFactStore
impl Unpin for SemanticFactStore
impl UnsafeUnpin for SemanticFactStore
impl UnwindSafe for SemanticFactStore
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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>
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