Retrieve Memory
Retrieve stored data from the 0G decentralized storage network.Overview
The Memory system provides efficient retrieval of both ephemeral and persistent data. Data is automatically cached for better performance and supports various retrieval patterns for different use cases.Methods
recall()
Retrieve data from persistent storage.key
(str): The unique identifier for the stored data
Any
- The stored data, or None
if not found
get_ephemeral()
Retrieve data from ephemeral (temporary) storage.key
(str): The key for the ephemeral data
Any
- The stored data, or None
if not found
get_messages()
Retrieve current conversation messages.List[ChatMessage]
- List of messages in the current conversation
Examples
Conversation Retrieval
recall_conversation()
Retrieve a previously saved conversation.conversation_id
(str): The ID of the conversation to retrieve
List[ChatMessage]
- List of messages in the conversation
Example:
get_conversation_context()
Get conversation context as formatted string.str
- Formatted conversation context
Example:
Advanced Retrieval Patterns
Hierarchical Data Retrieval
Fallback Retrieval
Versioned Retrieval
Error Handling and Validation
Performance Optimization
Bulk Retrieval
Lazy Loading
Memory Statistics
Get information about memory usage:Best Practices
- Check for None: Always check if retrieved data is
None
- Use Type Hints: Specify expected return types for better code clarity
- Implement Caching: Cache frequently accessed data locally
- Handle Errors: Always handle potential storage errors gracefully
- Validate Data: Validate retrieved data before using it
- Use Batch Operations: Retrieve multiple items concurrently when possible