CorpusIndexRetriever#
- class scikitplot.mcp.CorpusIndexRetriever(embedder, index, *, match_mode='hybrid', strict=False, filter=None, documents=None)[source]#
Text-level retriever over a corpus
RetrievalIndex: hybrid by default.- Parameters:
- embedderEmbedder or None
Embeds the query for the dense leg — the same model that embedded the corpus.
Noneonly withmatch_mode='keyword'.- indexRetrievalIndex
A built corpus index. Its own configuration (fusion constant, weights, backend) is kept; only
match_modeandtop_kare set per query.- match_mode{‘hybrid’, ‘keyword’, ‘semantic’}, optional
Which evidence paths the corpus runs. Default
'hybrid': BM25 and dense, fused by rank inside the corpus.- strictbool, optional
Re-raise failures instead of reporting them as a failed leg.
- documentsiterable or None, optional
The documents
indexwas built from, forget(thedocs://chunk/{doc_id}resource); the factory passes them. They are served as given, so pass no others.Noneserves no document by id.- filterFilter, mapping or None, optional
A corpus filter expression (
Filter, or its JSON form) applied to every query: the server’s scope. It is checked here byvalidate_filterand passed toindex.search(filter=...), where the corpus AND-s it with the index’s ownSecurityFilter; a query can only narrow it.None(the default) searches the whole index. The same scope applies toget. The scope is server configuration: responses do not echo it.
- Raises:
- ValueError
If
match_modeis not one of the offered modes, or no embedder is given for a mode that needs one, orfilteris malformed.- TypeError
If
filteris neither a filter expression nor a mapping.- RuntimeError
If a
filteris given andscikitplot.corpusis not installed.
- Parameters:
Notes
User. Dense search blurs identifiers and error strings; keyword search misses paraphrase. Hybrid runs both and fuses them by rank, which is why a query such as
roc_auc_scoreand one such as “area under the ROC curve” both find the right page.Developer. The server’s Corpus+Annoy backend built an index that already holds a BM25 leg (
RetrievalIndex.buildalways constructs it) and then used only the vector seam, so the MCP surface could never serve hybrid retrieval although every piece existed (finding CX-04). Fusion is not re-implemented here: corpus owns retrieval semantics, and its per-leg account is carried intoRetrievalOutcome, so a hybrid query whose dense leg could not run is reporteddegradedrather than passed off as a complete result.- get(doc_id)[source]#
Return one indexed document by id, for the MCP resource route.
- Parameters:
- doc_idstr
The document’s stable id.
- Returns:
- RetrievedChunk or None
Nonewhen nodocumentswere given, the id is unknown, the document has no text, or it is outside the scope: the retriever’sfilteror the index’ssecurity_filterdoes not admit it. Of several documents with the id, the first in scope is returned. An out-of-scope document is indistinguishable from a missing one, so the route reveals nothing about what the scope hides.
- Parameters:
doc_id (str)
- Return type:
RetrievedChunk | None