Skip to content

update_memory async

update_memory(
    space_id: SpaceId,
    memory_id: MemoryId,
    *,
    config_overrides: Optional[AsyncOpenSearchMemoryClientConfig] = None,
    content: Optional[MemoryUpdateContent] = None,
    metadata: Optional[MetadataMap] = None,
    metadata_mode: Optional[MetadataMode] = None,
    actor_id: Optional[ActorId] = None,
    strategy_name: Optional[StrategyName] = None,
) -> UpdateMemoryOutput

Updates a memory in place. Supply only the fields to change. Omitted fields keep their stored values. A request must supply content or metadata, or it fails with ValidationException. Supplying content re-embeds the memory. A change to metadata alone doesn't.

The memory keeps its memoryId across updates. Shortly after an update, searches stop returning the previous content.

memoryType can't be changed. To change it, delete the memory and create a new one.

A memory past its expiry (set from the space's memoryExpiryDays when the memory is written) reads as not found: the operation fails with ResourceNotFoundException and changes nothing. An update does not move the expiry.

Concurrent updates to one memory are last-writer-wins. There is no version check. To avoid lost updates, serialize your updates to a memory.

If you supply content and 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.

  • memory_id (MemoryId) –

    The ID of the memory to update.

  • content (Optional[MemoryUpdateContent], default: None ) –

    Replacement memory text. Supplying it re-embeds the memory. Omit to leave the text unchanged.

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

    The metadata tags to apply. By default this map replaces the stored metadata, and any key not present is removed. Set metadataMode to MERGE to keep the keys you don't supply. Limits apply to the resulting metadata, not to the request. Keys that begin with x-amz- and the key documentS3Source are reserved: a request that sets one fails with ValidationException.

    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.

  • metadata_mode (Optional[MetadataMode], default: None ) –

    How metadata combines with what is stored. The default is REPLACE.

  • actor_id (Optional[ActorId], default: None ) –

    The ID of the actor that the memory must belong to. Omit it to skip this check. If it doesn't match the stored memory, the call fails with ResourceNotFoundException, as if the memory did not exist.

  • strategy_name (Optional[StrategyName], default: None ) –

    The name of the strategy that the memory must belong to. Omit it to skip this check. If it doesn't match the stored memory, the call fails with ResourceNotFoundException, as if the memory did not exist.

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/async_open_search_memory.py
async def update_memory(
    self,
    space_id: "capo_opensearchmemory.types.space_id.SpaceId",
    memory_id: "capo_opensearchmemory.types.memory_id.MemoryId",
    *,
    config_overrides: Optional[AsyncOpenSearchMemoryClientConfig] = None,
    content: Optional[
        "capo_opensearchmemory.types.memory_update_content.MemoryUpdateContent"
    ] = None,
    metadata: Optional[
        "capo_opensearchmemory.types.metadata_map.MetadataMap"
    ] = None,
    metadata_mode: Optional[
        "capo_opensearchmemory.types.metadata_mode.MetadataMode"
    ] = None,
    actor_id: Optional["capo_opensearchmemory.types.actor_id.ActorId"] = None,
    strategy_name: Optional[
        "capo_opensearchmemory.types.strategy_name.StrategyName"
    ] = None,
) -> "capo_opensearchmemory.types.update_memory_output.UpdateMemoryOutput":
    """<p>Updates a memory in place. Supply only the fields to change. Omitted fields keep their stored values. A request must supply <code>content</code> or <code>metadata</code>, or it fails with <code>ValidationException</code>. Supplying <code>content</code> re-embeds the memory. A change to metadata alone doesn't.</p> <p>The memory keeps its <code>memoryId</code> across updates. Shortly after an update, searches stop returning the previous content.</p> <p> <code>memoryType</code> can't be changed. To change it, delete the memory and create a new one.</p> <p>A memory past its expiry (set from the space's <code>memoryExpiryDays</code> when the memory is written) reads as not found: the operation fails with <code>ResourceNotFoundException</code> and changes nothing. An update does not move the expiry.</p> <p>Concurrent updates to one memory are last-writer-wins. There is no version check. To avoid lost updates, serialize your updates to a memory.</p> <p>If you supply <code>content</code> and 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>
        memory_id: <p>The ID of the memory to update.</p>
        content: <p>Replacement memory text. Supplying it re-embeds the memory. Omit to leave the text unchanged.</p>
        metadata: <p>The metadata tags to apply. By default this map replaces the stored metadata, and any key not present is removed. Set <code>metadataMode</code> to <code>MERGE</code> to keep the keys you don't supply. Limits apply to the resulting metadata, not to the request. Keys that begin with <code>x-amz-</code> and the key <code>documentS3Source</code> are reserved: a request that sets one fails with <code>ValidationException</code>.</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>
        metadata_mode: <p>How <code>metadata</code> combines with what is stored. The default is <code>REPLACE</code>.</p>
        actor_id: <p>The ID of the actor that the memory must belong to. Omit it to skip this check. If it doesn't match the stored memory, the call fails with <code>ResourceNotFoundException</code>, as if the memory did not exist.</p>
        strategy_name: <p>The name of the strategy that the memory must belong to. Omit it to skip this check. If it doesn't match the stored memory, the call fails with <code>ResourceNotFoundException</code>, as if the memory did not exist.</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.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_opensearchmemory.types.update_memory_input.UpdateMemoryInput]",
    ) -> AsyncOperationResponse[
        "capo_opensearchmemory.types.update_memory_output.UpdateMemoryOutput"
    ]:
        import capo_opensearchmemory._operations.open_search_memory.update_memory

        (
            output,
            http_response,
        ) = await capo_opensearchmemory._operations.open_search_memory.update_memory.async_update_memory(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

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

        return capo_opensearchmemory.types.update_memory_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_opensearchmemory.types.update_memory_output.UpdateMemoryOutput",
    ) -> dict[str, Any]:
        import capo_opensearchmemory.types.update_memory_output

        return capo_opensearchmemory.types.update_memory_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "UpdateMemory", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_opensearchmemory.types.update_memory_input.UpdateMemoryInput = {
        "space_id": space_id,
        "memory_id": memory_id,
    }
    if content is not None:
        input_["content"] = content
    if metadata is not None:
        input_["metadata"] = metadata
    if metadata_mode is not None:
        input_["metadata_mode"] = metadata_mode
    if actor_id is not None:
        input_["actor_id"] = actor_id
    if strategy_name is not None:
        input_["strategy_name"] = strategy_name

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output