LangChainCorpusRetriever#

class scikitplot.corpus.LangChainCorpusRetriever(index, embedding_fn=None, config=None)[source]#

LangChain-compatible retriever backed by SimilarityIndex.

Parameters:
indexSimilarityIndex

A built similarity index.

embedding_fnCallable[[str], list[float]] or None, optional

Function to embed query text. Required for SEMANTIC mode.

configSearchConfig or None, optional

Default search configuration.

Parameters:
  • index (Any)

  • embedding_fn (Any)

  • config (Any)

See also

scikitplot.corpus._similarity.SimilarityIndex

The underlying search engine.

Notes

User note: Plug into any LangChain chain:

retriever = LangChainCorpusRetriever(index, embedding_fn)
chain = RetrievalQA.from_chain_type(
    llm=llm,
    retriever=retriever,
)

This class implements the BaseRetriever interface if langchain_core is installed, otherwise it provides a compatible get_relevant_documents method.

get_relevant_documents(query)[source]#

Retrieve documents relevant to query.

Parameters:
querystr

Natural language query.

Returns:
list[langchain_core.documents.Document] or list[dict]

LangChain-compatible documents.

Parameters:

query (str)

Return type:

list[Any]

invoke(query)[source]#

Retrieve documents relevant to query.

Parameters:
querystr

Natural language query.

Returns:
list[langchain_core.documents.Document] or list[dict]

LangChain-compatible documents.

Parameters:

query (str)

Return type:

list[Any]