Skip to main content

Module text_search

Module text_search 

Source
Expand description

Retrieval-augmented generation over any text search.

Port of .NET’s TextSearchProvider (Microsoft.Agents.AI) and Go’s agent/textsearch (v0.2.0). TextSearchProvider is a ContextProvider wrapping a search function you supply — a vector store query, a web search, a keyword index — and puts its results in front of the model in one of two ways (TextSearchBehavior):

  • Before each run (the default): the run’s input text is searched and the formatted results are added as a user message ahead of it.
  • On demand: the model gets a Search tool and calls it when it wants to.

With TextSearchProvider::with_recent_message_memory, the search input also carries the last few messages of the conversation, kept in the session’s state, so a follow-up such as “and the second one?” is searched with the question it follows.

use agent_framework_core::text_search::{TextSearchProvider, TextSearchResult};

let provider = TextSearchProvider::new(|query: String| async move {
    // Look `query` up in your index.
    Ok(vec![TextSearchResult::new("Returns are accepted within 30 days.")
        .with_source("Returns policy", "https://example.com/returns")])
});

§Divergences

  • No message filters. Upstream filters the search and storage input so history and other providers’ messages are not searched or remembered. A Rust provider only ever receives the run’s own input and response, so there is nothing to filter out.
  • Logging. Result counts and failures go to tracing; the query and formatted results are logged (at trace) only after TextSearchProvider::with_sensitive_logging, in place of upstream’s redactor.

Structs§

TextSearchProvider
A ContextProvider that adds text-search results to a run. See the module docs.
TextSearchResult
One search hit.

Enums§

TextSearchBehavior
When a TextSearchProvider searches.

Constants§

DEFAULT_TEXT_SEARCH_STATE_KEY
The default session-state key for recent-message memory.