DualRetriever

Struct DualRetriever 

Source
pub struct DualRetriever<L: LLMProvider, E: EmbeddingProvider, V: VectorBackend, S: StorageBackend> { /* private fields */ }
Expand description

Dual retriever: fast search + LLM reasoning.

TigerStyle: Generic over LLM and storage for sim/production flexibility.

§Example

use umi_memory::retrieval::{DualRetriever, SearchOptions};
use umi_memory::llm::SimLLMProvider;
use umi_memory::embedding::SimEmbeddingProvider;
use umi_memory::storage::{SimStorageBackend, SimVectorBackend};
use umi_memory::dst::SimConfig;

#[tokio::main]
async fn main() {
    let llm = SimLLMProvider::with_seed(42);
    let embedder = SimEmbeddingProvider::with_seed(42);
    let vector = SimVectorBackend::new(42);
    let storage = SimStorageBackend::new(SimConfig::with_seed(42));
    let retriever = DualRetriever::new(llm, embedder, vector, storage);

    // Deep search with query rewriting + vector search
    let result = retriever
        .search("Who works at Acme?", SearchOptions::default())
        .await
        .unwrap();
}

Implementations§

Source§

impl<L: LLMProvider, E: EmbeddingProvider, V: VectorBackend, S: StorageBackend> DualRetriever<L, E, V, S>

Source

pub fn new(llm: L, embedder: E, vector: V, storage: S) -> Self

Create a new dual retriever.

Source

pub async fn search( &self, query: &str, options: SearchOptions, ) -> Result<SearchResult, RetrievalError>

Search with dual retrieval strategy.

§Arguments
  • query - Search query
  • options - Search options (limit, deep_search, time_range)
§Returns

SearchResult with entities, query info, and metadata.

§Errors

Returns RetrievalError if query is empty, too long, or limit is invalid.

§Graceful Degradation

If LLM fails during query rewriting, falls back to fast search only.

Source

pub async fn rewrite_query(&self, query: &str) -> Vec<String>

Rewrite query into search variations using LLM.

§Arguments
  • query - Original search query
§Returns

Vector of query variations (always includes original).

§Graceful Degradation

Returns only the original query if LLM fails.

Source

pub fn merge_rrf(&self, result_lists: &[&Vec<Entity>]) -> Vec<Entity>

Merge results using Reciprocal Rank Fusion.

RRF score: sum(1 / (k + rank)) for each list the document appears in. Documents appearing in multiple lists get higher scores.

§Arguments
  • result_lists - Slice of entity vectors to merge
§Returns

Merged and deduplicated entities, sorted by RRF score.

Source

pub fn llm(&self) -> &L

Get a reference to the underlying LLM provider.

Source

pub fn storage(&self) -> &S

Get a reference to the underlying storage backend.

Trait Implementations§

Source§

impl<L: Debug + LLMProvider, E: Debug + EmbeddingProvider, V: Debug + VectorBackend, S: Debug + StorageBackend> Debug for DualRetriever<L, E, V, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<L, E, V, S> Freeze for DualRetriever<L, E, V, S>
where L: Freeze, E: Freeze, V: Freeze, S: Freeze,

§

impl<L, E, V, S> RefUnwindSafe for DualRetriever<L, E, V, S>

§

impl<L, E, V, S> Send for DualRetriever<L, E, V, S>

§

impl<L, E, V, S> Sync for DualRetriever<L, E, V, S>

§

impl<L, E, V, S> Unpin for DualRetriever<L, E, V, S>
where L: Unpin, E: Unpin, V: Unpin, S: Unpin,

§

impl<L, E, V, S> UnwindSafe for DualRetriever<L, E, V, S>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more