BaseMemory()Abstract base class for memory in Chains.
Memory refers to state in Chains. Memory can be used to store information about past executions of a Chain and inject that information into the inputs of future executions of the Chain. For example, for conversational Chains Memory can be used to store conversations and automatically add them to future model prompts so that the model has the necessary context to respond coherently to the latest input.
Example:
class SimpleMemory(BaseMemory):
memories: dict[str, Any] = dict()
@property
def memory_variables(self) -> list[str]:
return list(self.memories.keys())
def load_memory_variables(self, inputs: dict[str, Any]) -> dict[str, str]:
return self.memories
def save_context(
self, inputs: dict[str, Any], outputs: dict[str, str]
) -> None:
pass
def clear(self) -> None:
passThe string keys this memory class will add to chain inputs.
Return key-value pairs given the text input to the chain.
Async return key-value pairs given the text input to the chain.
Save the context of this chain run to memory.
Async save the context of this chain run to memory.
Clear memory contents.
Async clear memory contents.