Skip to content

create_memory

create_memory(
    space_id: SpaceId,
    name: StrategyName,
    content: CreateMemoryContent,
    actor_id: ActorId,
    *,
    config_overrides: Optional[OpenSearchMemoryClientConfig] = None,
    session_id: Optional[SessionId] = None,
    metadata: Optional[MetadataMap] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateMemoryOutput

Writes a memory that you have already formed, without extracting it from events. The service embeds the text as given and stores it as a memory of the named strategy. To have the service extract memories from conversation turns, use CreateEvent instead.

The operation returns before the memory is searchable. The returned memoryId is final, but until the memory is indexed, GetMemory, UpdateMemory, and DeleteMemory return ResourceNotFoundException for it.

If the request would exceed the service's rate for embedding requests, it fails with ThrottlingException. Retry with exponential backoff.

If the space uses a customer managed AWS KMS key, the call can also fail because of the key. It fails with AccessDeniedException if you aren't allowed to use the key, and with ThrottlingException if AWS KMS throttles the request. It fails with ValidationException if the key is disabled, pending deletion, or deleted.

Parameters:

  • space_id (SpaceId) –

    The ID of the space that owns the memory, for example sp-02864597b164.

  • name (StrategyName) –

    The name of the strategy that the memory belongs to. The space must already declare the strategy, and the memory's type comes from that strategy. The name must be 1 to 64 characters: letters, digits, periods, hyphens, and underscores, starting with a letter or digit.

  • content (CreateMemoryContent) –

    The memory text, stored and embedded as provided.

  • actor_id (ActorId) –

    The actor (end user or agent) that owns the memory.

  • session_id (Optional[SessionId], default: None ) –

    The session that the memory belongs to. If you omit it, the service generates a session ID and returns it.

  • metadata (Optional[MetadataMap], default: None ) –

    Metadata tags to store with the memory. Keys that begin with x-amz-, the key documentS3Source, and other keys that the service uses internally are reserved: a request that sets one fails with ValidationException, and the message names the key.

    A space can use at most 50 distinct metadata keys across all of its events and memories. A request that would add a key beyond that fails with ValidationException. Reuse an existing key instead.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier that makes the request idempotent. Within 2 hours of the first request, a retry with the same token returns the same memoryId instead of creating a second memory. Reusing the token with a different name, content, metadata, actorId, or sessionId fails with ConflictException. If you omit sessionId, a retry with the same token gets the same session. If you omit the token, each call creates a new memory.

Raises:

  • AccessDeniedException –

    You don't have sufficient access to perform this operation. To use this operation, you must have AWS Identity and Access Management (IAM) permissions for the operation, and on the resource it acts on. If the space uses a customer managed AWS Key Management Service (AWS KMS) key, you must also have permission to use the key.

  • ConflictException –

    The request conflicts with the current state of the resource. For example, the space is being created, updated, or deleted, a space with the same name already exists, or you reused a client token with different parameters. Wait for the space to finish being created, updated, or deleted, or use a different name or client token, and then retry.

  • InternalServerException –

    The service couldn't process the request because of an internal error. Retry the request.

  • ResourceNotFoundException –

    The specified resource doesn't exist. Check the IDs in the request.

  • ThrottlingException –

    The service throttled the request. Retry the request with exponential backoff.

  • ValidationException –

    The request isn't valid. The reason, message, and fieldList members describe the problem. Fix the request, and then try again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_opensearchmemory/_services/open_search_memory.py
def create_memory(
    self,
    space_id: "capo_opensearchmemory.types.space_id.SpaceId",
    name: "capo_opensearchmemory.types.strategy_name.StrategyName",
    content: "capo_opensearchmemory.types.create_memory_content.CreateMemoryContent",
    actor_id: "capo_opensearchmemory.types.actor_id.ActorId",
    *,
    config_overrides: Optional[OpenSearchMemoryClientConfig] = None,
    session_id: Optional["capo_opensearchmemory.types.session_id.SessionId"] = None,
    metadata: Optional[
        "capo_opensearchmemory.types.metadata_map.MetadataMap"
    ] = None,
    client_token: Optional[
        "capo_opensearchmemory.types.client_token.ClientToken"
    ] = None,
) -> "capo_opensearchmemory.types.create_memory_output.CreateMemoryOutput":
    """<p>Writes a memory that you have already formed, without extracting it from events. The service embeds the text as given and stores it as a memory of the named strategy. To have the service extract memories from conversation turns, use <code>CreateEvent</code> instead.</p> <p>The operation returns before the memory is searchable. The returned <code>memoryId</code> is final, but until the memory is indexed, <code>GetMemory</code>, <code>UpdateMemory</code>, and <code>DeleteMemory</code> return <code>ResourceNotFoundException</code> for it.</p> <p>If the request would exceed the service's rate for embedding requests, it fails with <code>ThrottlingException</code>. Retry with exponential backoff.</p> <p>If the space uses a customer managed AWS KMS key, the call can also fail because of the key. It fails with <code>AccessDeniedException</code> if you aren't allowed to use the key, and with <code>ThrottlingException</code> if AWS KMS throttles the request. It fails with <code>ValidationException</code> if the key is disabled, pending deletion, or deleted.</p>

    Args:
        space_id: <p>The ID of the space that owns the memory, for example <code>sp-02864597b164</code>.</p>
        name: <p>The name of the strategy that the memory belongs to. The space must already declare the strategy, and the memory's type comes from that strategy. The name must be 1 to 64 characters: letters, digits, periods, hyphens, and underscores, starting with a letter or digit.</p>
        content: <p>The memory text, stored and embedded as provided.</p>
        actor_id: <p>The actor (end user or agent) that owns the memory.</p>
        session_id: <p>The session that the memory belongs to. If you omit it, the service generates a session ID and returns it.</p>
        metadata: <p>Metadata tags to store with the memory. Keys that begin with <code>x-amz-</code>, the key <code>documentS3Source</code>, and other keys that the service uses internally are reserved: a request that sets one fails with <code>ValidationException</code>, and the message names the key.</p> <p>A space can use at most 50 distinct metadata keys across all of its events and memories. A request that would add a key beyond that fails with <code>ValidationException</code>. Reuse an existing key instead.</p>
        client_token: <p>A unique, case-sensitive identifier that makes the request idempotent. Within 2 hours of the first request, a retry with the same token returns the same <code>memoryId</code> instead of creating a second memory. Reusing the token with a different <code>name</code>, <code>content</code>, <code>metadata</code>, <code>actorId</code>, or <code>sessionId</code> fails with <code>ConflictException</code>. If you omit <code>sessionId</code>, a retry with the same token gets the same session. If you omit the token, each call creates a new memory.</p>

    Raises:
        capo_opensearchmemory.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this operation. To use this operation, you must have AWS Identity and Access Management (IAM) permissions for the operation, and on the resource it acts on. If the space uses a customer managed AWS Key Management Service (AWS KMS) key, you must also have permission to use the key.</p>
        capo_opensearchmemory.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. For example, the space is being created, updated, or deleted, a space with the same name already exists, or you reused a client token with different parameters. Wait for the space to finish being created, updated, or deleted, or use a different name or client token, and then retry.</p>
        capo_opensearchmemory.errors.internal_server_exception.InternalServerException: <p>The service couldn't process the request because of an internal error. Retry the request.</p>
        capo_opensearchmemory.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource doesn't exist. Check the IDs in the request.</p>
        capo_opensearchmemory.errors.throttling_exception.ThrottlingException: <p>The service throttled the request. Retry the request with exponential backoff.</p>
        capo_opensearchmemory.errors.validation_exception.ValidationException: <p>The request isn't valid. The <code>reason</code>, <code>message</code>, and <code>fieldList</code> members describe the problem. Fix the request, and then try again.</p>
        capo_opensearchmemory.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_opensearchmemory.types.create_memory_input.CreateMemoryInput]",
    ) -> OperationResponse[
        "capo_opensearchmemory.types.create_memory_output.CreateMemoryOutput"
    ]:
        import capo_opensearchmemory._operations.open_search_memory.create_memory

        output, http_response = (
            capo_opensearchmemory._operations.open_search_memory.create_memory.create_memory(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_opensearchmemory.types.create_memory_input.CreateMemoryInput",
    ) -> dict[str, Any]:
        import capo_opensearchmemory.types.create_memory_input

        return capo_opensearchmemory.types.create_memory_input.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateMemory", redact_input=_redact_input),
    )
    input_: capo_opensearchmemory.types.create_memory_input.CreateMemoryInput = {
        "space_id": space_id,
        "name": name,
        "content": content,
        "actor_id": actor_id,
    }
    if session_id is not None:
        input_["session_id"] = session_id
    if metadata is not None:
        input_["metadata"] = metadata
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output