pub enum ScriptedReranker {
Fifo {
results: Mutex<Vec<Result<Vec<RerankResult>, ProviderError>>>,
calls: Mutex<Vec<(String, usize, usize)>>,
},
Match {
resolver: Box<dyn Fn(&str, &[String], usize) -> Result<Vec<RerankResult>, ProviderError> + Send + Sync>,
calls: Mutex<Vec<(String, usize, usize)>>,
},
}Expand description
Scripted reranker, parity-shaped with ScriptedNliClassifier:
ScriptedReranker::new(FIFO): each call pops the next scripted result set in order. When the script is exhausted the reranker returnsOk(vec![])(the legitimate “provider found nothing” shape) so the fail-closed contract of the rerank stage is exercisable without an explicit error — mirroring a real provider that responded with zero results rather than a transport failure.ScriptedReranker::matching(Match): each call dispatches to the supplied closure. Use when survivor ordering is not deterministic (HashMaporder) and the test keys scores on the document text, or to honour thetop_kargument for truncation assertions.
Both modes record every (query, document_count, top_k) triple so tests
can assert on the exact calls the use case made.
Variants§
Implementations§
Source§impl ScriptedReranker
impl ScriptedReranker
pub fn new(results: Vec<Result<Vec<RerankResult>, ProviderError>>) -> Self
pub fn matching<F>(resolver: F) -> Selfwhere
F: Fn(&str, &[String], usize) -> Result<Vec<RerankResult>, ProviderError> + Send + Sync + 'static,
Trait Implementations§
Source§impl RerankProvider for ScriptedReranker
impl RerankProvider for ScriptedReranker
Source§async fn rerank(
&self,
query: &str,
documents: &[String],
top_k: usize,
) -> Result<Vec<RerankResult>, ProviderError>
async fn rerank( &self, query: &str, documents: &[String], top_k: usize, ) -> Result<Vec<RerankResult>, ProviderError>
Re-score
documents against query and return the top-top_k hits
ordered by descending relevance score. Each hit preserves the original
document index so the caller can map back to its source fact.Auto Trait Implementations§
impl !Freeze for ScriptedReranker
impl !RefUnwindSafe for ScriptedReranker
impl !UnwindSafe for ScriptedReranker
impl Send for ScriptedReranker
impl Sync for ScriptedReranker
impl Unpin for ScriptedReranker
impl UnsafeUnpin for ScriptedReranker
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
Mutably borrows from an owned value. Read more