langchain.retrievers.time_weighted_retriever.TimeWeightedVectorStoreRetriever

class langchain.retrievers.time_weighted_retriever.TimeWeightedVectorStoreRetriever(*, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, vectorstore: VectorStore, search_kwargs: dict = None, memory_stream: List[Document] = None, decay_rate: float = 0.01, k: int = 4, other_score_keys: List[str] = [], default_salience: Optional[float] = None)[source]

Bases: BaseRetriever

Retriever that combines embedding similarity with recency in retrieving values.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param decay_rate: float = 0.01

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

param 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.

param k: int = 4

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

param memory_stream: List[langchain.schema.document.Document] [Optional]

The memory_stream of documents to search through.

param metadata: Optional[Dict[str, Any]] = None

Optional metadata associated with the retriever. Defaults to None This metadata will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. You can use these to eg identify a specific instance of a retriever with its use case.

param other_score_keys: List[str] = []

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

param search_kwargs: dict [Optional]

Keyword arguments to pass to the vectorstore similarity search.

param tags: Optional[List[str]] = None

Optional list of tags associated with the retriever. Defaults to None These tags will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks. You can use these to eg identify a specific instance of a retriever with its use case.

param vectorstore: langchain.vectorstores.base.VectorStore [Required]

The vectorstore to store documents and determine salience.

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

Add documents to vectorstore.

add_documents(documents: List[Document], **kwargs: Any) List[str][source]

Add documents to vectorstore.

async aget_relevant_documents(query: str, *, callbacks: Callbacks = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) List[Document]

Asynchronously get documents relevant to a query. :param query: string to find relevant documents for :param callbacks: Callback manager or list of callbacks :param tags: Optional list of tags associated with the retriever. Defaults to None

These tags will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks.

Parameters

metadata – Optional metadata associated with the retriever. Defaults to None This metadata will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks.

Returns

List of relevant documents

async ainvoke(input: str, config: Optional[RunnableConfig] = None) List[Document]
get_relevant_documents(query: str, *, callbacks: Callbacks = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) List[Document]

Retrieve documents relevant to a query. :param query: string to find relevant documents for :param callbacks: Callback manager or list of callbacks :param tags: Optional list of tags associated with the retriever. Defaults to None

These tags will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks.

Parameters

metadata – Optional metadata associated with the retriever. Defaults to None This metadata will be associated with each call to this retriever, and passed as arguments to the handlers defined in callbacks.

Returns

List of relevant documents

get_salient_docs(query: str) Dict[int, Tuple[Document, float]][source]

Return documents that are salient to the query.

invoke(input: str, config: Optional[RunnableConfig] = None) List[Document]
to_json() Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() SerializedNotImplemented
property lc_attributes: Dict

Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.

property lc_namespace: List[str]

Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]

property lc_secrets: Dict[str, str]

Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}

property lc_serializable: bool

Return whether or not the class is serializable.

model Config[source]

Bases: object

Configuration for this pydantic object.

arbitrary_types_allowed = True

Examples using TimeWeightedVectorStoreRetriever