Skip to main content

search

Function search 

Source
pub fn search(
    root: &Path,
    query: &str,
    backends: &[&dyn EmbedBackend],
    tokenizer: &Tokenizer,
    top_k: usize,
    cfg: &SearchConfig,
    profiler: &Profiler,
) -> Result<Vec<SearchResult>>
Expand description

Search a directory for code chunks semantically similar to a query.

Walks the directory, chunks all supported files, embeds everything in parallel batches, and returns the top-k results ranked by similarity.

Accepts multiple backends for hybrid scheduling — the first backend (backends[0]) is used for query embedding.

All tuning parameters (batch size, token limit, chunk sizing) are controlled via SearchConfig.

§Errors

Returns an error if the query cannot be tokenized or embedded.

§Panics

Panics if a per-thread backend clone fails during parallel embedding (should not happen if the backend loaded successfully).