Skip to main content

SearchableIndex

Trait SearchableIndex 

Source
pub trait SearchableIndex: Send + Sync {
    // Required methods
    fn chunks(&self) -> &[CodeChunk];
    fn search(
        &self,
        query_text: &str,
        top_k: usize,
        mode: SearchMode,
    ) -> Vec<(usize, f32)>;
    fn search_from_chunk(
        &self,
        chunk_idx: usize,
        query_text: &str,
        top_k: usize,
        mode: SearchMode,
    ) -> Vec<(usize, f32)>;
    fn as_any(&self) -> &dyn Any;
}
Expand description

Engine-agnostic searchable index.

transformer engines, RipvecIndex for the ripvec engine.

Required Methods§

Source

fn chunks(&self) -> &[CodeChunk]

Borrow the indexed chunks.

Source

fn search( &self, query_text: &str, top_k: usize, mode: SearchMode, ) -> Vec<(usize, f32)>

Search by text query.

Returns (chunk_idx, score) pairs ranked descending. Score is normalized to [0, 1] regardless of mode so callers can apply a single threshold consistently.

Source

fn search_from_chunk( &self, chunk_idx: usize, query_text: &str, top_k: usize, mode: SearchMode, ) -> Vec<(usize, f32)>

Search by similarity to an existing chunk’s embedding.

Caller passes the chunk index whose embedding should be used as the query vector. The canonical goto_definition pattern: the LSP layer identifies the chunk at the cursor, then asks the index for structurally similar chunks elsewhere.

If chunk_idx is out of range or the engine cannot provide an embedding for it (keyword-only mode, embedding row not stored), implementations fall back to text-only search via Self::search.

Source

fn as_any(&self) -> &dyn Any

Downcast escape hatch for callers that legitimately need the concrete engine-specific index type.

Used by transformer-engine-only code paths (e.g., legacy run_search with caller-supplied query embedding) that need use [Any::downcast_ref] to attempt the conversion. Returns None-equivalent when the concrete type doesn’t match.

Engine-neutral code should never need this; the three trait methods above are the supported surface.

Implementors§