pub struct PendingRerankRequest { /* private fields */ }Expand description
The fluent, chainable way to build and run a rerank request.
Get one of these from Registry::rerank, add
one or more with_document calls, then
generate.
§Example
use llmprism::Registry;
let registry = Registry::from_env();
let response = registry
.rerank("voyageai", "rerank-2.5", "What's the capital of France?")?
.with_document("Paris is the capital of France.")
.with_document("Berlin is the capital of Germany.")
.generate()
.await?;
// Sorted most-relevant first -- `results[0]` is the best match.
println!("best match was document {}", response.results[0].index);Implementations§
Source§impl PendingRerankRequest
impl PendingRerankRequest
Sourcepub fn new(
provider: Arc<dyn Provider>,
model: impl Into<String>,
query: impl Into<String>,
) -> Self
pub fn new( provider: Arc<dyn Provider>, model: impl Into<String>, query: impl Into<String>, ) -> Self
Starts a new builder for provider, targeting model with the given
query. You’ll normally get one of these from
Registry::rerank rather than calling
this directly.
Sourcepub fn with_document(self, document: impl Into<String>) -> Self
pub fn with_document(self, document: impl Into<String>) -> Self
Adds one document to score. Call this more than once to rerank several documents in a single request.
Sourcepub fn with_documents(
self,
documents: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_documents( self, documents: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Adds several documents to score at once.
Sourcepub fn with_top_k(self, top_k: u32) -> Self
pub fn with_top_k(self, top_k: u32) -> Self
Keeps only the top_k most relevant documents in the response,
instead of every document just sorted.
Sourcepub fn with_return_documents(self, return_documents: bool) -> Self
pub fn with_return_documents(self, return_documents: bool) -> Self
Asks the provider to echo each document’s own text back in the
response. See RerankRequest::return_documents for why you’d
bother, given you already have the text locally.
Sourcepub fn to_request(&self) -> RerankRequest
pub fn to_request(&self) -> RerankRequest
Freezes the builder’s current state into a RerankRequest without
sending it.
Sourcepub async fn generate(self) -> Result<RerankResponse, Error>
pub async fn generate(self) -> Result<RerankResponse, Error>
Sends the request and returns every document, scored and sorted by relevance (most relevant first).