pub struct SqliteIndex { /* private fields */ }Expand description
SQLite-backed sparse index using FTS5 for BM25 search.
Unlike BM25Index (in-memory HashMap), this persists to disk and
delegates BM25 scoring to SQLite’s FTS5 extension.
The Connection is wrapped in a Mutex to satisfy the Send + Sync
bounds required by SparseIndex. Mutex<T> is Sync when T: Send,
and rusqlite::Connection is Send. SQLite in WAL mode supports
concurrent readers via separate connections; this single-connection
design serializes access within one process.
Implementations§
Source§impl SqliteIndex
impl SqliteIndex
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open an in-memory index (for testing).
Sourcepub fn document_count(&self) -> Result<usize>
pub fn document_count(&self) -> Result<usize>
Get document count.
Sourcepub fn chunk_count(&self) -> Result<usize>
pub fn chunk_count(&self) -> Result<usize>
Get chunk count.
Sourcepub fn needs_reindex(&self, path: &str, hash: &[u8; 32]) -> Result<bool>
pub fn needs_reindex(&self, path: &str, hash: &[u8; 32]) -> Result<bool>
Check if a document needs reindexing by fingerprint.
Sourcepub fn insert_document(
&self,
doc_id: &str,
title: Option<&str>,
source: Option<&str>,
content: &str,
chunks: &[(String, String)],
fingerprint: Option<(&str, &[u8; 32])>,
) -> Result<()>
pub fn insert_document( &self, doc_id: &str, title: Option<&str>, source: Option<&str>, content: &str, chunks: &[(String, String)], fingerprint: Option<(&str, &[u8; 32])>, ) -> Result<()>
Batch-insert a document and its chunks within a transaction.
Sourcepub fn remove_document(&self, doc_id: &str) -> Result<()>
pub fn remove_document(&self, doc_id: &str) -> Result<()>
Remove a document and its chunks.
Explicitly deletes chunks first (which fires FTS5 sync triggers), then deletes the document row.
Sourcepub fn list_fingerprints(&self) -> Result<Vec<(String, Vec<u8>)>>
pub fn list_fingerprints(&self) -> Result<Vec<(String, Vec<u8>)>>
List all tracked fingerprints (path → blake3 hash).
Used by incremental indexing to detect deleted or changed files.
Sourcepub fn remove_by_source(&self, source: &str) -> Result<usize>
pub fn remove_by_source(&self, source: &str) -> Result<usize>
Remove all documents (and their chunks) with a given source path.
Used by incremental indexing to remove stale documents before re-inserting.
Sourcepub fn search_fts(&self, query: &str, k: usize) -> Result<Vec<FtsResult>>
pub fn search_fts(&self, query: &str, k: usize) -> Result<Vec<FtsResult>>
FTS5 BM25 search. Returns results ordered by descending relevance.
Trait Implementations§
Source§impl Debug for SqliteIndex
impl Debug for SqliteIndex
Source§impl SparseIndex for SqliteIndex
impl SparseIndex for SqliteIndex
Auto Trait Implementations§
impl !Freeze for SqliteIndex
impl RefUnwindSafe for SqliteIndex
impl Send for SqliteIndex
impl Sync for SqliteIndex
impl Unpin for SqliteIndex
impl UnsafeUnpin for SqliteIndex
impl UnwindSafe for SqliteIndex
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> 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