Retrievers#

pydantic model langchain.retrievers.ChatGPTPluginRetriever[source]#
field aiosession: Optional[aiohttp.client.ClientSession] = None#
field bearer_token: str [Required]#
field filter: Optional[dict] = None#
field top_k: int = 3#
field url: str [Required]#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

pydantic model langchain.retrievers.ContextualCompressionRetriever[source]#

Retriever that wraps a base retriever and compresses the results.

field base_compressor: langchain.retrievers.document_compressors.base.BaseDocumentCompressor [Required]#

Compressor for compressing retrieved documents.

field base_retriever: langchain.schema.BaseRetriever [Required]#

Base Retriever to use for getting relevant documents.

async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

Sequence of relevant documents

class langchain.retrievers.DataberryRetriever(datastore_url: str, top_k: Optional[int] = None, api_key: Optional[str] = None)[source]#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

api_key: Optional[str]#
datastore_url: str#
get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

top_k: Optional[int]#
class langchain.retrievers.ElasticSearchBM25Retriever(client: Any, index_name: str)[source]#

Wrapper around Elasticsearch using BM25 as a retrieval method.

To connect to an Elasticsearch instance that requires login credentials, including Elastic Cloud, use the Elasticsearch URL format https://username:password@es_host:9243. For example, to connect to Elastic Cloud, create the Elasticsearch URL with the required authentication details and pass it to the ElasticVectorSearch constructor as the named parameter elasticsearch_url.

You can obtain your Elastic Cloud URL and login credentials by logging in to the Elastic Cloud console at https://cloud.elastic.co, selecting your deployment, and navigating to the “Deployments” page.

To obtain your Elastic Cloud password for the default “elastic” user:

  1. Log in to the Elastic Cloud console at https://cloud.elastic.co

  2. Go to “Security” > “Users”

  3. Locate the “elastic” user and click “Edit”

  4. Click “Reset password”

  5. Follow the prompts to reset the password

The format for Elastic Cloud URLs is https://username:password@cluster_id.region_id.gcp.cloud.es.io:9243.

add_texts(texts: Iterable[str], refresh_indices: bool = True) List[str][source]#

Run more texts through the embeddings and add to the retriver.

Parameters
  • texts – Iterable of strings to add to the retriever.

  • refresh_indices – bool to refresh ElasticSearch indices

Returns

List of ids from adding the texts into the retriever.

async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

classmethod create(elasticsearch_url: str, index_name: str, k1: float = 2.0, b: float = 0.75) langchain.retrievers.elastic_search_bm25.ElasticSearchBM25Retriever[source]#
get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

class langchain.retrievers.MetalRetriever(client: Any, params: Optional[dict] = None)[source]#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

pydantic model langchain.retrievers.PineconeHybridSearchRetriever[source]#
field alpha: float = 0.5#
field embeddings: langchain.embeddings.base.Embeddings [Required]#
field index: Any = None#
field sparse_encoder: Any = None#
field top_k: int = 4#
add_texts(texts: List[str], ids: Optional[List[str]] = None) None[source]#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

pydantic model langchain.retrievers.RemoteLangChainRetriever[source]#
field headers: Optional[dict] = None#
field input_key: str = 'message'#
field metadata_key: str = 'metadata'#
field page_content_key: str = 'page_content'#
field response_key: str = 'response'#
field url: str [Required]#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

pydantic model langchain.retrievers.SVMRetriever[source]#
field embeddings: langchain.embeddings.base.Embeddings [Required]#
field index: Any = None#
field k: int = 4#
field relevancy_threshold: Optional[float] = None#
field texts: List[str] [Required]#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

classmethod from_texts(texts: List[str], embeddings: langchain.embeddings.base.Embeddings, **kwargs: Any) langchain.retrievers.svm.SVMRetriever[source]#
get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

pydantic model langchain.retrievers.TFIDFRetriever[source]#
field docs: List[langchain.schema.Document] [Required]#
field k: int = 4#
field tfidf_array: Any = None#
field vectorizer: Any = None#
async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

classmethod from_texts(texts: List[str], tfidf_params: Optional[Dict[str, Any]] = None, **kwargs: Any) langchain.retrievers.tfidf.TFIDFRetriever[source]#
get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

pydantic model langchain.retrievers.TimeWeightedVectorStoreRetriever[source]#

Retriever combining embededing similarity with recency.

field decay_rate: float = 0.01#

The exponential decay factor used as (1.0-decay_rate)**(hrs_passed).

field default_salience: Optional[float] = None#

The salience to assign memories not retrieved from the vector store.

None assigns no salience to documents not fetched from the vector store.

field k: int = 4#

The maximum number of documents to retrieve in a given call.

field memory_stream: List[langchain.schema.Document] [Optional]#

The memory_stream of documents to search through.

field other_score_keys: List[str] = []#

Other keys in the metadata to factor into the score, e.g. ‘importance’.

field search_kwargs: dict [Optional]#

Keyword arguments to pass to the vectorstore similarity search.

field vectorstore: langchain.vectorstores.base.VectorStore [Required]#

The vectorstore to store documents and determine salience.

async aadd_documents(documents: List[langchain.schema.Document], **kwargs: Any) List[str][source]#

Add documents to vectorstore.

add_documents(documents: List[langchain.schema.Document], **kwargs: Any) List[str][source]#

Add documents to vectorstore.

async aget_relevant_documents(query: str) List[langchain.schema.Document][source]#

Return documents that are relevant to the query.

get_relevant_documents(query: str) List[langchain.schema.Document][source]#

Return documents that are relevant to the query.

get_salient_docs(query: str) Dict[int, Tuple[langchain.schema.Document, float]][source]#

Return documents that are salient to the query.

class langchain.retrievers.WeaviateHybridSearchRetriever(client: Any, index_name: str, text_key: str, alpha: float = 0.5, k: int = 4, attributes: Optional[List[str]] = None)[source]#
class Config[source]#

Configuration for this pydantic object.

arbitrary_types_allowed = True#
extra = 'forbid'#
add_documents(docs: List[langchain.schema.Document]) List[str][source]#

Upload documents to Weaviate.

async aget_relevant_documents(query: str, where_filter: Optional[Dict[str, object]] = None) List[langchain.schema.Document][source]#

Get documents relevant for a query.

Parameters

query – string to find relevant documents for

Returns

List of relevant documents

get_relevant_documents(query: str, where_filter: Optional[Dict[str, object]] = None) List[langchain.schema.Document][source]#

Look up similar documents in Weaviate.