pub struct CodeRetriever { /* private fields */ }Expand description
Budget-aware code retriever with automatic query classification.
Wraps a CodeStore and an LLM provider (for embedding) and exposes a single
high-level CodeRetriever::retrieve method.
§Examples
use std::sync::Arc;
use zeph_index::retriever::{CodeRetriever, RetrievalConfig, format_as_context};
use zeph_index::store::CodeStore;
let retriever = CodeRetriever::new(store, provider, RetrievalConfig::default());
let result = retriever.retrieve("explain how authentication works", 8_000).await?;
let xml = format_as_context(&result);
println!("{xml}");Implementations§
Source§impl CodeRetriever
impl CodeRetriever
Sourcepub fn new(
store: CodeStore,
provider: Arc<AnyProvider>,
config: RetrievalConfig,
) -> Self
pub fn new( store: CodeStore, provider: Arc<AnyProvider>, config: RetrievalConfig, ) -> Self
Create a new CodeRetriever.
store must have its Qdrant collection already created (see
CodeStore::ensure_collection).
Sourcepub async fn retrieve(
&self,
query: &str,
available_tokens: usize,
) -> Result<RetrievedCode>
pub async fn retrieve( &self, query: &str, available_tokens: usize, ) -> Result<RetrievedCode>
Retrieve relevant code chunks for a free-text query.
Classifies query via classify_query, then:
- For
RetrievalStrategy::Grepqueries — returns an emptyRetrievedCodeso the agent falls back to its shellgreporsymbol_definitiontools. - For
RetrievalStrategy::Semantic/RetrievalStrategy::Hybrid— embeds the query, searches Qdrant, applies the score threshold, and packs results withinavailable_tokens * budget_ratio.
§Errors
Returns an error if the embedding call or Qdrant search fails.
Sourcepub async fn retrieve_filtered(
&self,
query: &str,
available_tokens: usize,
language: &str,
) -> Result<RetrievedCode>
pub async fn retrieve_filtered( &self, query: &str, available_tokens: usize, language: &str, ) -> Result<RetrievedCode>
Retrieve relevant code, restricting results to a single language.
Behaves like CodeRetriever::retrieve but adds a Qdrant payload filter so
only chunks whose language field matches language are returned.
Useful when the user or agent has already established the relevant language (e.g. “show me the Python error handling” should not return Rust results).
§Arguments
language— the language identifier as returned bycrate::languages::Lang::id(e.g."rust","python").
§Errors
Returns an error if embedding or Qdrant search fails.
Auto Trait Implementations§
impl !RefUnwindSafe for CodeRetriever
impl !UnwindSafe for CodeRetriever
impl Freeze for CodeRetriever
impl Send for CodeRetriever
impl Sync for CodeRetriever
impl Unpin for CodeRetriever
impl UnsafeUnpin for CodeRetriever
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request