Skip to content

memory_collection

Memory collection service module

Attributes

Classes

MemoryCollectionService

MemoryCollectionService(
    sa_session: SASession, neo4j_session: NJSession
)

Bases: BaseService

Memory collection service layer

Attributes

memory_collection_dao instance-attribute
memory_collection_dao = MemoryCollectionDao(
    session=sa_session
)
memory_graph_dao instance-attribute
memory_graph_dao = MemoryGraphDao(session=sa_session)
namespace_service instance-attribute
namespace_service = NamespaceService(
    sa_session=sa_session, neo4j_session=neo4j_session
)

Functions

build_vectordb_config staticmethod
build_vectordb_config(
    vectordb_name: str,
    name: Optional[str] = None,
    description: Optional[str] = None,
    config: Optional[str] = None,
) -> Dict[str, Any]

Build the configuration for a VectorDB based on the provided parameters.

Parameters:

  • vectordb_name (str) –

    The name of the VectorDB.

  • name (str, default: None ) –

    The name of the collection. Defaults to None.

  • description (str, default: None ) –

    The description of the collection. Defaults to None.

  • config (str, default: None ) –

    The configuration string in JSON format. Defaults to None.

Returns:

  • dict ( Dict[str, Any] ) –

    The derived configuration for the VectorDB.

create_memory_collection
create_memory_collection(
    namespace: str,
    name: str,
    collection_type: MemoryCollectionType,
    vectordb_name: str,
    description: Optional[str] = None,
    config: Optional[str] = None,
    managed: bool = False,
    read_only: bool = True,
    enabled: bool = True,
    db_transact: bool = True,
) -> MemoryCollection

Create a memory collection within a namespace.

Parameters:

  • namespace_pkid (str) –

    The primary key ID of the namespace.

  • name (str) –

    The name of the memory collection.

  • collection_type (MemoryCollectionType) –

    The type of memory collection.

  • vectordb_name (str) –

    The name of the VectorDB instance to use.

  • description (str, default: None ) –

    The description of the memory collection. Defaults to None.

  • config (str, default: None ) –

    The configuration of the memory collection. Defaults to None.

  • managed (bool, default: False ) –

    Flag indicating whether the memory collection is managed. Defaults to False.

  • read_only (bool, default: True ) –

    Flag indicating whether the memory collection is read-only. Defaults to True.

  • enabled (bool, default: True ) –

    Flag indicating whether the memory collection is enabled. Defaults to True.

  • db_transact (bool, default: True ) –

    Flag indicating whether to commit the transaction. Defaults to True.

Returns:

  • MemoryCollection

    orm.MemoryCollection: The newly created memory collection.

Raises:

export_graph_all
export_graph_all() -> None

Export all memory collections to the graph database.

export_memory_collection
export_memory_collection(
    namespace: str, memory_collection_pkid: str
) -> List[Memory]
generate_graph
generate_graph(
    namespace: str, memory_collection: str
) -> None

Export the provided memory collection to the graph database.

Parameters:

  • collection_pkid (str) –

    The primary key ID of the memory collection.

Returns:

  • None

    None

get_all_memory_collections
get_all_memory_collections(
    include_deleted: bool = False,
    include_disabled: bool = False,
) -> List[MemoryCollection]

Retrieves all memory collections in a namespace.

Since there is no namespace filtering, consider this a privileged service call.

Parameters:

  • include_deleted (bool, default: False ) –

    Whether to include deleted memory collections. Defaults to False.

  • include_disabled (bool, default: False ) –

    Whether to include disabled memory collections. Defaults to False.

Returns:

  • List[MemoryCollection]

    orm.MemoryCollection: The retrieved memory collections.

Raises:

  • ServiceError

    If an error occurs while retrieving the memory collections.

get_memory_collection
get_memory_collection(
    namespace: str,
    memory_collection: str,
    error_deleted: bool = True,
    error_disabled: bool = True,
) -> MemoryCollection

Retrieves a memory collection based on the provided primary key.

Parameters:

  • memory_collection_pkid (str) –

    The primary key of the memory collection.

Returns:

Raises:

  • ServiceError

    If an error occurs while retrieving the memory collection.

hard_delete_memory_collection
hard_delete_memory_collection(
    namespace: str,
    memory_collection: str,
    delete_vectors: bool = True,
    dry_run: bool = True,
    db_transact: bool = True,
) -> None
list_memory_collections
list_memory_collections(
    namespace: str, include_deleted: bool = False
) -> List[MemoryCollection]

Retrieve a list of memory collections for a given namespace.

Parameters:

  • namespace_pkid (str) –

    The primary key of the namespace.

  • include_deleted (bool, default: False ) –

    Flag to include deleted memory collections. Defaults to False.

Returns:

  • List[MemoryCollection]

    List[orm.MemoryCollection]: A list of memory collections.

Raises:

  • ServiceError

    If an error occurs while retrieving the memory collections.

rebuild_memory_collection
rebuild_memory_collection(
    namespace: str, memory_collection: str
) -> MemoryCollection

Rebuilds the memory collection by re-vectorizing all memories from the RDBMS.

Parameters:

  • collection_pkid (str) –

    The primary key ID of the memory collection.

Returns:

Raises:

  • ServiceError

    If the memory collection is not found, soft-deleted, or disabled.

  • ServiceError

    If there is a general service error during the operation.

rebuild_memory_collections
rebuild_memory_collections(
    namespace: str,
    queue: str | None = None,
    tags: List[str] | None = None,
    task_id: str | None = None,
) -> None

Rebuilds all memory collections by re-vectorizing all memories from the RDBMS.

This method will disable agents temporarily as their memory collections are rebuilt.

soft_delete_memory_collection
soft_delete_memory_collection(
    namespace: str,
    memory_collection: str,
    db_transact: bool = True,
) -> None
truncate_memory_collection
truncate_memory_collection(
    namespace: str,
    memory_collection: str,
    db_transact: bool = True,
) -> None

Hard delete all memories in the collection (truncate).

Parameters:

  • memory_collection_pkid (str) –

    The primary key of the memory collection.

Raises:

  • ServiceError

    If an error occurs during the truncation process.

undelete_memory_collection
undelete_memory_collection(
    namespace: str,
    memory_collection: str,
    db_transact: bool = True,
) -> None
update_memory_collection
update_memory_collection(
    namespace: str,
    memory_collection: str,
    name: str | None = None,
    description: str | None = None,
    collection_type: MemoryCollectionType | None = None,
    vectordb_name: str | None = None,
    config: str | None = None,
    managed: bool | None = None,
    read_only: bool | None = None,
    enabled: bool | None = None,
    db_transact: bool = True,
) -> MemoryCollection

Update a memory collection with the specified attributes.

Parameters:

  • memory_collection_pkid (str) –

    The primary key ID of the memory collection to update.

  • name (str, default: None ) –

    The new name of the memory collection. Defaults to None.

  • collection_type (MemoryCollectionType, default: None ) –

    The new collection type of the memory collection. Defaults to None.

  • vectordb_name (str, default: None ) –

    The new name of the VectorDB associated with the memory collection. Defaults to None.

  • description (str, default: None ) –

    The new description of the memory collection. Defaults to None.

  • config (str, default: None ) –

    The new configuration of the memory collection. Defaults to None.

  • read_only (bool, default: None ) –

    The new read-only status of the memory collection. Defaults to True.

  • enabled (bool, default: None ) –

    The new enabled status of the memory collection. Defaults to True.

Returns:

  • MemoryCollection

    orm.MemoryCollection: The updated memory collection object.

Raises:

  • ServiceError

    If an error occurs during the update operation.

vector_store_factory
vector_store_factory(
    namespace: str, collection: str
) -> VectorStore

Factory function to create a vector store based on the given memory collection.

Parameters:

  • collection_ref (MemoryCollection) –

    The memory collection to create the vector store for.

Returns:

  • VectorStore ( VectorStore ) –

    The created vector store.

Raises:

  • ServiceError

    If the memory collection is soft-deleted or disabled.

  • ServiceError

    If the vector store referenced in the memory collection is not found in the application settings.

  • ServiceError

    If the vectordb type is not supported.

Functions