Skip to main content

khive_storage/
sparse.rs

1//! Sparse vector storage and lexical-semantic search capability.
2
3use async_trait::async_trait;
4use uuid::Uuid;
5
6use khive_types::SubstrateKind;
7
8use crate::types::{
9    BatchWriteSummary, SparseRecord, SparseSearchHit, SparseSearchRequest, SparseVector,
10    StorageResult,
11};
12
13/// Sparse vector storage and lexical-semantic search capability.
14#[async_trait]
15pub trait SparseStore: Send + Sync + 'static {
16    /// Insert a single sparse vector for a subject.
17    async fn insert_sparse(
18        &self,
19        subject_id: Uuid,
20        kind: SubstrateKind,
21        namespace: &str,
22        field: &str,
23        vector: SparseVector,
24    ) -> StorageResult<()>;
25
26    /// Insert a batch of sparse vector records.
27    async fn insert_batch(&self, records: Vec<SparseRecord>) -> StorageResult<BatchWriteSummary>;
28
29    /// Delete the sparse vector for a subject.
30    async fn delete(&self, subject_id: Uuid) -> StorageResult<bool>;
31
32    /// Search over sparse vectors using a sparse query.
33    async fn search_sparse(
34        &self,
35        request: SparseSearchRequest,
36    ) -> StorageResult<Vec<SparseSearchHit>>;
37
38    /// Count total sparse vector entries.
39    async fn count(&self) -> StorageResult<u64>;
40}