use async_trait::async_trait;
use crate::error::Result;
use crate::index::vector_trait::VectorScope;
use crate::memory::MemoryId;
use crate::partition::PartitionPath;
use crate::summary::SummaryId;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct LexicalIndexCapabilities {
pub bm25: bool,
pub phrase_queries: bool,
pub prefix_queries: bool,
}
impl Default for LexicalIndexCapabilities {
fn default() -> Self {
Self {
bm25: true,
phrase_queries: true,
prefix_queries: true,
}
}
}
#[async_trait]
pub trait LexicalIndex: Send + Sync + std::fmt::Debug + 'static {
async fn upsert_memory(
&self,
id: &MemoryId,
partition_path: &PartitionPath,
content: &str,
) -> Result<()>;
async fn upsert_summary(&self, id: &SummaryId, parent_path: &str, content: &str) -> Result<()>;
async fn delete_memory(&self, id: &MemoryId) -> Result<()>;
async fn delete_summary(&self, id: &SummaryId) -> Result<()>;
async fn search_memory(
&self,
query: &str,
k: u32,
scope: VectorScope,
) -> Result<Vec<(MemoryId, f32)>>;
async fn search_summary(
&self,
query: &str,
k: u32,
parent_path_prefix: &str,
) -> Result<Vec<(SummaryId, f32)>>;
fn id(&self) -> &str;
fn capabilities(&self) -> LexicalIndexCapabilities;
}