entity.resources.memory module
- class entity.resources.memory.Memory(database, vector_store)[source]
Bases:
objectLayer 3 canonical resource providing persistent memory capabilities.
Memory is one of the four canonical resources guaranteed to be available to every workflow. It provides both structured (database) and semantic (vector) storage with automatic user isolation and cross-process synchronization.
This class follows the 4-layer architecture: - Layer 3: Canonical Agent Resources (Memory) - Depends on Layer 2: Resource Interfaces (DatabaseResource, VectorStoreResource)
- Parameters:
database (DatabaseResource | None)
vector_store (VectorStoreResource | None)
- database
The underlying database resource for structured data.
- vector_store
The underlying vector store for semantic search.
Examples
>>> from entity.resources import Memory, DatabaseResource, VectorStoreResource >>> from entity.infrastructure import DuckDBInfrastructure >>> >>> duckdb = DuckDBInfrastructure("./agent_memory.duckdb") >>> db_resource = DatabaseResource(duckdb) >>> vector_resource = VectorStoreResource(duckdb) >>> memory = Memory(db_resource, vector_resource)
- __init__(database, vector_store)[source]
Initialize Memory with database and vector store resources.
- Parameters:
database (DatabaseResource | None) – Database resource for structured data storage.
vector_store (VectorStoreResource | None) – Vector store resource for semantic search.
- Raises:
ResourceInitializationError – If database or vector_store is None.
- Return type:
None
- health_check()[source]
Check if both database and vector store are healthy.
- Returns:
True if both underlying resources are operational, False otherwise.
- Return type:
- health_check_sync()[source]
Synchronous wrapper for health_check.
- Returns:
True if both underlying resources are operational, False otherwise.
- Return type:
- execute(query, *params)[source]
Execute a raw database query.
- Parameters:
- Returns:
Query result from the database.
- Return type:
Examples
>>> result = memory.execute("SELECT * FROM conversations WHERE user_id = ?", "user123")
- add_vector(table, vector)[source]
Add a vector to the vector store.
- Parameters:
- Return type:
None
Examples
>>> memory.add_vector("embeddings", [0.1, 0.2, 0.3, ...])