agents.memory_v2.time_weighted_retriever¶
Time-weighted retriever for Memory V2 system.
Based on LangChain’s time-weighted retriever patterns for long-term memory agents. Combines semantic similarity with recency weighting for optimal memory retrieval.
Reference: https://python.langchain.com/docs/versions/migrating_memory/long_term_memory_agent/
Classes¶
Session for managing retrieval with context and history. |
|
Configuration for time-weighted retrieval. |
|
Time-weighted retriever combining semantic similarity with recency. |
Functions¶
|
Create retriever optimized for memory retrieval. |
|
Factory function to create configured time-weighted retriever. |
|
Prepare timestamped documents for time-weighted retrieval. |
Module Contents¶
- class agents.memory_v2.time_weighted_retriever.MemoryRetrievalSession(retriever, session_id=None, user_id=None)¶
Session for managing retrieval with context and history.
Initialize retrieval session.
- Parameters:
retriever (TimeWeightedRetriever)
session_id (str | None)
user_id (str | None)
- class agents.memory_v2.time_weighted_retriever.TimeWeightConfig(/, **data)¶
Bases:
pydantic.BaseModel
Configuration for time-weighted retrieval.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class agents.memory_v2.time_weighted_retriever.TimeWeightedRetriever(vectorstore, config=None, **kwargs)¶
Bases:
langchain_core.retrievers.BaseRetriever
Time-weighted retriever combining semantic similarity with recency.
Initialize time-weighted retriever.
- Parameters:
vectorstore (langchain_core.vectorstores.VectorStore)
config (TimeWeightConfig)
- class Config¶
Pydantic config.
- get_relevant_documents_with_scores(query)¶
Get documents with their calculated scores for debugging.
- update_config(**config_updates)¶
Update retriever configuration.
- agents.memory_v2.time_weighted_retriever.create_memory_focused_retriever(vectorstore)¶
Create retriever optimized for memory retrieval.
- Parameters:
vectorstore (langchain_core.vectorstores.VectorStore) – Vector store with memory documents
- Returns:
Memory-optimized TimeWeightedRetriever
- Return type:
- agents.memory_v2.time_weighted_retriever.create_time_weighted_retriever(vectorstore, decay_rate=0.01, recency_weight=0.3, k=5)¶
Factory function to create configured time-weighted retriever.
- Parameters:
- Returns:
Configured TimeWeightedRetriever
- Return type:
- agents.memory_v2.time_weighted_retriever.prepare_documents_for_time_retrieval(documents)¶
Prepare timestamped documents for time-weighted retrieval.
- Parameters:
documents (list[agents.memory_v2.message_document_converter.TimestampedDocument]) – List of timestamped documents
- Returns:
List of documents ready for vector store ingestion
- Return type:
list[langchain_core.documents.Document]