Skip to main content

SessionIndex

Struct SessionIndex 

Source
pub struct SessionIndex { /* private fields */ }
Expand description

SQLite-based full-text search index for session messages.

Wraps a Connection to a SQLite database with FTS5 support. The index is created lazily on first use and must be explicitly updated when sessions change.

Implementations§

Source§

impl SessionIndex

Source

pub fn new(path: &Path) -> Result<Self, IndexError>

Open or create a SQLite database at the given path.

The database file is created if it does not exist. The schema is NOT automatically initialized — call SessionIndex::init_schema after creation.

§Arguments
  • path — Path to the SQLite database file.
§Errors

Returns an error if the database cannot be opened.

Source

pub fn init_schema(&self) -> Result<(), IndexError>

Initialize the database schema.

Creates the sessions table and the messages_fts FTS5 virtual table if they do not already exist. Safe to call multiple times.

§Errors

Returns an error if the schema cannot be created.

Source

pub fn index_session(&mut self, session: &Session) -> Result<(), IndexError>

Index a session and all its messages.

Upserts the session metadata into the sessions table and inserts all entries into the messages_fts table. Existing entries for the same session are deleted before re-indexing to avoid duplicates.

§Arguments
  • session — The session to index.
§Errors

Returns an error if the index cannot be updated.

Source

pub fn search( &self, query: &str, limit: usize, ) -> Result<Vec<SearchResult>, IndexError>

Perform a full-text search across all indexed messages.

Returns results ranked by relevance (BM25), with the most relevant first. Each result includes a snippet with matching terms highlighted.

§Arguments
  • query — The FTS5 search query. Supports FTS5 syntax (e.g., "exact phrase", term1 OR term2).
  • limit — Maximum number of results to return.
§Errors

Returns an error if the search cannot be executed.

Source

pub fn list_recent(&self, limit: usize) -> Result<Vec<SessionInfo>, IndexError>

List the most recently updated sessions.

Returns sessions ordered by updated_at descending.

§Arguments
  • limit — Maximum number of sessions to return.
§Errors

Returns an error if the query fails.

Source

pub fn get_session_info( &self, session_id: &str, ) -> Result<Option<SessionInfo>, IndexError>

Get metadata for a specific session.

Returns None if the session is not in the index.

§Arguments
  • session_id — The session ID to look up.
§Errors

Returns an error if the query fails.

Source

pub fn db_path(&self) -> &Path

Return the path to the SQLite database file.

Source

pub fn list_all_session_ids(&self) -> Result<Vec<String>, IndexError>

Source

pub fn delete_session(&mut self, session_id: &str) -> Result<(), IndexError>

Source

pub fn checkpoint_truncate(&self) -> Result<(), IndexError>

Checkpoint the write-ahead log and truncate it where SQLite can do so safely.

Source

pub fn vacuum(&self) -> Result<(), IndexError>

Rebuild the database file to reclaim free pages after explicit cleanup.

Source

pub fn record_fork( &mut self, source_session_id: &str, forked_session_id: &str, fork_entry_id: &str, ) -> Result<(), IndexError>

Record a fork relationship in the index.

Inserts a row into the forks table linking the source session to the newly forked session at the specified entry point.

§Arguments
  • source_session_id — The session ID being forked from.
  • forked_session_id — The new session ID created by the fork.
  • fork_entry_id — The entry ID in the source session where the fork occurred.
§Errors

Returns an error if the fork relationship cannot be recorded.

Source

pub fn get_forks(&self, session_id: &str) -> Result<Vec<ForkInfo>, IndexError>

Get all forks originating from a specific session.

Returns fork metadata for all sessions that were forked from the given source session, ordered by fork time descending.

§Arguments
  • session_id — The source session ID to query forks for.
§Errors

Returns an error if the query fails.

Trait Implementations§

Source§

impl Debug for SessionIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.