use memvid_core::MemoryCard;
pub trait MemoryGraph {
type Error: Into<rig::vector_store::VectorStoreError>;
fn memory_card_count(&self) -> Result<usize, Self::Error>;
fn all_memory_cards(&self) -> Result<Vec<MemoryCard>, Self::Error>;
fn entity_memories(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error>;
fn current_memory(&self, entity: &str, slot: &str) -> Result<Option<MemoryCard>, Self::Error>;
fn entity_preferences(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error>;
fn memory_timeline(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error>;
fn cards_for_query(&self, query: &str) -> Result<Vec<MemoryCard>, Self::Error> {
let needle = query.to_lowercase();
let all = self.all_memory_cards()?;
Ok(all
.into_iter()
.filter(|card| {
let entity = card.entity.to_lowercase();
!entity.is_empty() && crate::cards_context::contains_word(&needle, &entity)
})
.collect())
}
}
impl MemoryGraph for crate::MemvidStore {
type Error = crate::MemvidError;
fn memory_card_count(&self) -> Result<usize, Self::Error> {
Self::memory_card_count(self)
}
fn all_memory_cards(&self) -> Result<Vec<MemoryCard>, Self::Error> {
Self::all_memory_cards(self)
}
fn entity_memories(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error> {
Self::entity_memories(self, entity)
}
fn current_memory(&self, entity: &str, slot: &str) -> Result<Option<MemoryCard>, Self::Error> {
Self::current_memory(self, entity, slot)
}
fn entity_preferences(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error> {
Self::entity_preferences(self, entity)
}
fn memory_timeline(&self, entity: &str) -> Result<Vec<MemoryCard>, Self::Error> {
Self::memory_timeline(self, entity)
}
fn cards_for_query(&self, query: &str) -> Result<Vec<MemoryCard>, Self::Error> {
Self::cards_for_query(self, query)
}
}