entity.resources.memory module

class entity.resources.memory.Memory(database, vector_store)[source]

Bases: object

Layer 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

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:

bool

health_check_sync()[source]

Synchronous wrapper for health_check.

Returns:

True if both underlying resources are operational, False otherwise.

Return type:

bool

execute(query, *params)[source]

Execute a raw database query.

Parameters:
  • query (str) – SQL query string to execute.

  • *params (object) – Parameters to bind to the query.

Returns:

Query result from the database.

Return type:

object

Examples

>>> result = memory.execute("SELECT * FROM conversations WHERE user_id = ?", "user123")
add_vector(table, vector)[source]

Add a vector to the vector store.

Parameters:
  • table (str) – Name of the table/collection to store the vector in.

  • vector (object) – Vector data to store (typically embeddings).

Return type:

None

Examples

>>> memory.add_vector("embeddings", [0.1, 0.2, 0.3, ...])
query(query)[source]

Execute a vector store query.

Parameters:

query (str)

Return type:

object

async store(key, value)[source]

Persist value for key asynchronously.

Parameters:
Return type:

None

async load(key, default=None)[source]

Retrieve the stored value for key or default if missing.

Parameters:
  • key (str)

  • default (Any | None)

Return type:

Any