39.1. MemoryStoreο
39.1.1. Core Memory Managementο
Mock memory module for documentation build.
This module provides mock objects for the memories.core.memory module to allow documentation to be built without requiring all dependencies.
39.1.2. MemoryStore Classο
39.1.3. Memory Tiersο
39.1.3.1. Hot Memoryο
39.1.3.2. Warm Memoryο
- class memories.core.warm.WarmMemory[source]ο
Bases:
objectWarm memory layer using DuckDB for storage.
- __init__(storage_path=None)[source]ο
Initialize warm memory.
- Parameters:
storage_path (str) β Optional path to store DuckDB files
- async store(data, metadata=None, tags=None, db_name=None, table_name=None)[source]ο
Store data in warm memory with metadata and tags.
- Parameters:
data (Any) β Data to store
metadata (Dict[str, Any] | None) β Optional metadata about the data
tags (List[str] | None) β Optional tags for categorizing the data
db_name (str | None) β Optional name of the database file to store in (without .duckdb extension)
table_name (str | None) β Optional name for the table to create. If None, a name will be generated.
- Returns:
success: True if storage was successful, False otherwise
data_id: The unique ID of the stored data
table_name: The name of the table where data is stored
- Return type:
Dict containing success status and table information
- async retrieve(query=None, tags=None, db_name=None, table_name=None)[source]ο
Retrieve data from warm memory.
- Parameters:
- Returns:
Retrieved data or None if not found
- Return type:
- get_connection(db_name=None)[source]ο
Get a connection to a specific database file.
- Parameters:
db_name (str | None) β Name of the database file (without .duckdb extension). If None, returns the default connection.
- Returns:
DuckDB connection
- Return type:
DuckDBPyConnection
- async import_from_parquet(parquet_file, metadata=None, tags=None, db_name=None, table_name=None)[source]ο
Import data from a parquet file into warm memory.
- Parameters:
parquet_file (str) β Path to the parquet file
metadata (Dict[str, Any] | None) β Optional metadata about the data
tags (List[str] | None) β Optional tags for categorizing the data
db_name (str | None) β Optional name of the database file to store in (without .duckdb extension)
table_name (str | None) β Optional name for the table to create. If None, a name will be generated.
- Returns:
success: True if import was successful, False otherwise
data_id: The unique ID of the stored data
table_name: The name of the table where data is stored
- Return type:
Dict containing success status and table information
- async import_from_duckdb(source_db_file, tables=None, metadata=None, tags=None, db_name=None)[source]ο
Import tables from another DuckDB database using direct table copying.
- Parameters:
source_db_file (str) β Path to the source DuckDB database file
tables (List[str] | None) β Optional list of table names to import. If None, imports all tables.
metadata (Dict[str, Any] | None) β Optional metadata about the data
tags (List[str] | None) β Optional tags for categorizing the data
db_name (str | None) β Optional name of the database file to store in (without .duckdb extension)
- Returns:
success: True if import was successful, False otherwise
imported_tables: List of imported table names
data_ids: Dict mapping table names to data IDs
- Return type:
Dict containing success status and table information
- async import_from_csv(csv_file, metadata=None, tags=None, db_name=None, table_name=None)[source]ο
Import data from a CSV file into warm memory.
- Parameters:
csv_file (str) β Path to the CSV file
metadata (Dict[str, Any] | None) β Optional metadata about the data
tags (List[str] | None) β Optional tags for categorizing the data
db_name (str | None) β Optional name of the database file to store in (without .duckdb extension)
table_name (str | None) β Optional name for the table to create. If None, a name will be generated.
- Returns:
success: True if import was successful, False otherwise
data_id: The unique ID of the stored data
table_name: The name of the table where data is stored
- Return type:
Dict containing success status and table information
39.1.3.3. Cold Memoryο
- class memories.core.cold.ColdMemory[source]ο
Bases:
objectCold memory layer using DuckDB for persistent storage.
- async register_external_file(file_path)[source]ο
Register an external file in the cold storage metadata.
- Parameters:
file_path (str) β
- Return type:
None
- async get_all_schemas()[source]ο
Get all file paths from cold storage metadata and extract their schemas.
- async get_schema(data_id)[source]ο
Get schema information for stored data.
- Parameters:
data_id (str) β ID of the data to get schema for
- Returns:
- columns: List of column names
dtypes: Dictionary mapping column names to their data types
type: Type of schema (e.g., βtableβ, βfileβ, βdataframeβ)
source: Source of the schema (e.g., βduckdbβ, βparquetβ, βjsonβ)
Returns None if data not found or schema cannot be determined
- Return type:
Dictionary containing
39.1.3.4. Glacier Memoryο
- class memories.core.glacier.GlacierMemory[source]ο
Bases:
objectBase class for Glacier Memory.
- async retrieve(query)[source]ο
Retrieve data from a glacier source.
- Parameters:
query (Dict[str, Any]) β Query dictionary containing: - source: Name of the source (βosmβ, βovertureβ, etc.) - Other source-specific parameters
- Returns:
Retrieved data or None if not found
- Return type:
Optional[Dict[str, Any]]
- Raises:
ValueError β If source is not supported or query is invalid
39.1.4. Example Usageο
from memories import MemoryStore, Config
# Initialize configuration
config = Config(
storage_path="./data",
hot_memory_size=50, # MB
warm_memory_size=200, # MB
cold_memory_size=1000 # MB
)
# Create memory store
memory_store = MemoryStore(config)
# Store data
data = {
"timestamp": "2025-02-17T12:00:00",
"location": {"lat": 40.7128, "lon": -74.0060},
"measurements": {"temperature": 25.5, "humidity": 60}
}
memory_store.store(data)
# Retrieve data
result = memory_store.retrieve(
query={"location.lat": {"$gt": 40}},
time_range=("2025-02-17T00:00:00", "2025-02-17T23:59:59")
)
39.1.5. Configuration Optionsο
The MemoryStore can be configured with various options:
storage_path: Base path for storing memory datahot_memory_size: Size limit for hot memory in MBwarm_memory_size: Size limit for warm memory in MBcold_memory_size: Size limit for cold memory in MBenable_compression: Enable data compression (default: True)compression_level: Compression level (1-9, default: 6)enable_encryption: Enable data encryption (default: False)encryption_key: Encryption key for secure storage