RetrievalExecutionPlan#
- class scikitplot.corpus.RetrievalExecutionPlan(retrieval=None, transform=None, keep_original=True, max_queries=8, fusion=None, rerank=None, rerank_depth=None, compress=None, top_k=None, budgets=(), deadline_seconds=None, on_error='degrade', clock=None)[source]#
Run retrieval through typed, bounded stages.
- Parameters:
- retrievalobject or None, default=None
Passed to
index.searchasconfig(aRetrievalConfig);Noneuses the index’s own.- transformcallable or None, default=None
transform(query) -> sequence of str: rewrites, sub-queries or variants. Empty strings are refused, exact duplicates are run once.- keep_originalbool, default=True
Run the original query first, whatever
transformreturns.- max_queriesint, default=8
Queries
retrieveruns at most; further ones are dropped and thetransformstage reportsdegraded.- fusionFusionPolicy or None, default=None
Fuses the queries’ rankings (the leg of query
iis named"q{i}");NoneisFusionPolicy(). Not used with one query. A policy withtop_k=0is refused; one that weighs every query 0 makesfusereportdegraded.- rerankcallable or None, default=None
rerank(query, hits) -> sequence of float, one finite score per hit, higher is better; ties keep the fused order.- rerank_depthint or None, default=None
Hits passed to
rerank;Nonepasses all. When set,top_kmust be set too and be at mostrerank_depth, so no returned hit is ranked by two scales.- compresscallable or None, default=None
compress(query, hits) -> sequence, one entry per hit, each a sequence of(start, end)character ranges ofhit.doc.text, ordered and non-overlapping; an empty entry keeps nothing of that hit (seeCharBudgetCompressor).- top_kint or None, default=None
Hits returned;
Nonereturns every hitretrievefound.- budgetsmapping of str to StageBudget, default=()
{"retrieve": StageBudget(...)}: the one stage that makes several calls. The other stages make one call each, which a budget checked before calls cannot bound; they are refused here.- deadline_secondsfloat or None, default=None
Seconds after the plan starts beyond which no stage or query starts (
fuse, an in-process computation, always runs).- on_error{“degrade”, “raise”}, default=”degrade”
What an exception from a component (or from
index.search) does:"degrade"reports the stagefailedand keeps the previous stage’s output;"raise"propagates it.- clockcallable or None, default=None
clock() -> seconds;Noneistime.perf_counter.
- Raises:
- TypeError, ValueError
For a field of the wrong type or out of range.
- Parameters:
retrieval (Any)
keep_original (bool)
max_queries (int)
fusion (FusionPolicy | None)
rerank (Callable[[str, Sequence[PlannedHit]], Sequence[float]] | None)
rerank_depth (int | None)
compress (Callable[[str, Sequence[PlannedHit]], Sequence[Any]] | None)
top_k (int | None)
budgets (Mapping[str, StageBudget] | tuple[tuple[str, StageBudget], ...])
deadline_seconds (float | None)
on_error (str)
See also
scikitplot.corpus.RetrievalIndex.searchWhat
retrievecalls.scikitplot.corpus.FusionPolicyHow the queries’ rankings are fused.
scikitplot.corpus.evaluate_retrievalMeasures
plan.bind(index).
Notes
User. An empty plan,
RetrievalExecutionPlan().run(index, q), returns the hits ofindex.search(q)in the same order, and its status.Developer. A stage with nothing to do is
skipped(fusewith one query,rerankwith no hits), notsuccess, so a report never claims work that was not done.Examples
>>> plan = RetrievalExecutionPlan( ... top_k=3, budgets={"retrieve": StageBudget(max_calls=4)} ... ) >>> plan.budget("retrieve") StageBudget(max_calls=4, max_seconds=None)
- bind(index, **kwargs)[source]#
Return
query -> self.run(index, query, **kwargs).- Parameters:
- indexobject
Anything with
search.- **kwargs
Passed to
runon every call.
- Returns:
- callable
For
evaluate_retrieval.
- Parameters:
- Return type:
- budget(stage)[source]#
Return the budget of
stage, orNone.- Parameters:
- Return type:
StageBudget | None
- budgets: Mapping[str, StageBudget] | tuple[tuple[str, StageBudget], ...] = ()#
- fusion: FusionPolicy | None = None#
- run(index, query, *, query_embedding=None, embed_query=None, filter=None)[source]#
Run the plan for
query.- Parameters:
- indexobject
Anything with
search(query, **kwargs)returning an iterable of hits (RetrievalIndex). Each hit carries an identity (hit.doc.doc_id,hit.doc_idorhit.node_id) and a realscore; a query whose hits do not fails. Bare(id, score)pairs are not hits.- querystr
The query.
- query_embeddingarray-like or None, default=None
Embedding of
queryitself, passed with it toindex.search.- embed_querycallable or None, default=None
embed_query(text) -> embeddingfor the queries the transform produced (and forquerywhenquery_embeddingisNone). Without it, those queries are searched with no embedding, and a dense leg reports why it could not run.- filterFilter, mapping or None, default=None
Passed to every
index.searchcall.
- Returns:
- ExecutionResult
- Raises:
- TypeError
If
queryis not astrorindexhas nosearch; withon_error="raise", a component’s output of the wrong type.- ValueError
If
queryis empty; withon_error="raise", a component’s output out of range.- Exception
With
on_error="raise", whatever a component orindex.searchraised.
- Parameters:
- Return type: