RetrievalConfig#
- class scikitplot.corpus.RetrievalConfig(top_k=10, match_mode='semantic', semantic_threshold=0.0, keyword_threshold=0.0, hybrid_alpha=0.5, rrf_k=60, use_normalized_text=True, case_sensitive=False, backend='auto', index_kwargs=<factory>, annoy_n_trees=10, annoy_metric='angular', annoy_search_k=-1, annoy_impl='auto', annoy_dtype=None, annoy_index_dtype=None, allow_fallback=True)[source]#
Configuration for similarity search.
- Parameters:
- top_kint
Maximum results to return.
- match_modestr
One of
"strict","keyword","semantic","hybrid".- semantic_thresholdfloat
Minimum cosine similarity for SEMANTIC results.
- keyword_thresholdfloat
Minimum keyword overlap for KEYWORD results.
- hybrid_alphafloat
Dense share in HYBRID mode, shorthand for the two leg weights
{lexical: 1 - alpha, dense: alpha}ofFusionPolicy(R2-1):0returns the lexical leg alone and1the dense leg alone, exactly. Default 0.5.- rrf_kint
Reciprocal rank fusion constant, an
intof at least 1. Default 60 (standard).- use_normalized_textbool
Use
normalized_textfor matching when available.- case_sensitivebool
Case-sensitive matching in STRICT mode.
- backendstr or VectorIndexBackend subclass
Dense ANN backend selector for SEMANTIC/HYBRID modes. Built-in string names include
"auto","annoy","faiss","voyager"and"bruteforce". A customVectorIndexBackendsubclass may be supplied directly for an application-local backend without adding backend-specific fields to this dataclass.- index_kwargsmapping, optional
Generic constructor keyword arguments for the selected vector-index backend. Prefer this for new backend-specific tuning, for example
index_kwargs={"n_trees": 20, "metric": "angular"}with Annoy. Existingannoy_*fields remain supported for compatibility.- annoy_n_treesint
Annoy tree count (accuracy/size trade-off) when the Annoy backend is used. Higher is more accurate and larger. Default 10.
- annoy_metricstr
Annoy distance metric. Default
"angular"(cosine-like); scores are always reported as cosine similarity regardless of metric.- annoy_search_kint
Annoy query-time node budget.
-1(default) lets Annoy choose.- annoy_implstr
Which Annoy index class to use:
"auto"(default; a class that accepts every requested option, the high-levelscikitplot.annoy.Indexfirst, else the Cythonscikitplot.annoy._annoy.Index),"highlevel", or"cython".- annoy_dtypestr or None
Embedding precision for the Cython Annoy class (e.g.
"float32","float64");annoy_impl="auto"picks that class when it is set. The high-level class cannot honour it (seeallow_fallback). DefaultNone.- annoy_index_dtypestr or None
Item-id integer width for the Cython Annoy class (e.g.
"int32","uint64") for very large corpora. DefaultNone.- allow_fallbackbool
What happens when the dense backend cannot run as configured (R2-5): under
backend="auto"an installed backend that fails to load is skipped, and an Annoy option the running binding cannot honour is dropped, both reported on the dense leg (requested_backend,fallback_reason) and inRetrievalIndex.backend_provenance(True, default);Falseraises at build instead.
- Parameters:
top_k (int)
match_mode (str)
semantic_threshold (float)
keyword_threshold (float)
hybrid_alpha (float)
rrf_k (int)
use_normalized_text (bool)
case_sensitive (bool)
backend (Any)
annoy_n_trees (int)
annoy_metric (str)
annoy_search_k (int)
annoy_impl (str)
annoy_dtype (str | None)
annoy_index_dtype (str | None)
allow_fallback (bool)
Notes
User note: For RAG pipelines,
match_mode="hybrid"with default settings provides a good balance. For exact citation matching, usematch_mode="strict". To force a specific ANN library, set e.g.backend="annoy"and tuneannoy_n_trees.
Gallery examples#
Build and Search a Real Hamlet Corpus with FluentCorpus
Build and Search a Real Hamlet Corpus with FluentCorpus
Build and Search a Real Hamlet Corpus with FluentCorpus