Skip to content

search_events

search_events(
    space_id: SpaceId,
    actor_id: ActorId,
    query: SearchQuery,
    *,
    config_overrides: Optional[OpenSearchMemoryClientConfig] = None,
    session_ids: Optional[SessionIdList] = None,
    sort: Optional[SearchSort] = None,
    max_results: Optional[MaxResults] = None,
    next_token: Optional[PaginationToken] = None,
) -> SearchEventsOutput

Searches a space's events by relevance. It works like SearchMemories without the memory type and strategy selector. The query is a subset of the OpenSearch Query DSL. The service validates it, limits the search to the actor in actorId and the sessions in sessionIds, and returns ranked results. Each result is the matching chunk of an event, not the whole event. You can page through only a limited number of results. A request past that limit fails with ValidationException (reason invalidNextToken), and the message gives the limit.

If the results are larger than 5 MiB, the request fails with ValidationException (reason queryBodyTooLarge). Lower maxResults.

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 space whose events to search. Use actorId and sessionIds to narrow the search within it.

  • actor_id (ActorId) –

    The actor whose events to search (exact match). Required: every search covers exactly one actor, and an event stored without an actor is never returned. Narrow the search further with sessionIds, combined by AND. This is the only way to filter by actor: a query that references system_metadata.actor_id fails with ValidationException (reason nonFilterableField).

  • session_ids (Optional[SessionIdList], default: None ) –

    Returns only events from one of these sessions (exact match). Combined with actorId by AND. Omit for no session filter. An empty list fails validation. An event stored without a session never matches a session filter. This is the only way to filter by session: a query that references system_metadata.session_id fails with ValidationException (reason nonFilterableField).

  • query (SearchQuery) –

    The query: a subset of the OpenSearch Query DSL (see SearchQuery), validated by the same rules as on SearchMemories. Query event text as text and embeddings as vector. A search covers both conversation turns and chunks of documents submitted as a blob. You can't use actor and session fields here. Use the top-level actorId and sessionIds.

    To search only the content of particular events, filter on event_ids with term or terms, for example with the sourceEventIds that a SearchMemories result returns. A terms clause on event_ids can list up to 10 event IDs. More IDs fail with ValidationException (reason queryBodyTooLarge). You can use event_ids only in term, terms, and exists queries.

  • sort (Optional[SearchSort], default: None ) –

    The sort order (see SearchSort). Omit to return the most relevant events first.

  • max_results (Optional[MaxResults], default: None ) –

    The maximum number of events to return, from 1 to 100. The default is 20.

  • next_token (Optional[PaginationToken], default: None ) –

    The token for the next set of results. Use the value returned in the previous response in the next request to retrieve the next set of results.

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.

  • 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 search_events(
    self,
    space_id: "capo_opensearchmemory.types.space_id.SpaceId",
    actor_id: "capo_opensearchmemory.types.actor_id.ActorId",
    query: "capo_opensearchmemory.types.search_query.SearchQuery",
    *,
    config_overrides: Optional[OpenSearchMemoryClientConfig] = None,
    session_ids: Optional[
        "capo_opensearchmemory.types.session_id_list.SessionIdList"
    ] = None,
    sort: Optional["capo_opensearchmemory.types.search_sort.SearchSort"] = None,
    max_results: Optional[
        "capo_opensearchmemory.types.max_results.MaxResults"
    ] = None,
    next_token: Optional[
        "capo_opensearchmemory.types.pagination_token.PaginationToken"
    ] = None,
) -> "capo_opensearchmemory.types.search_events_output.SearchEventsOutput":
    """<p>Searches a space's events by relevance. It works like <code>SearchMemories</code> without the memory type and strategy selector. The query is a subset of the OpenSearch Query DSL. The service validates it, limits the search to the actor in <code>actorId</code> and the sessions in <code>sessionIds</code>, and returns ranked results. Each result is the matching chunk of an event, not the whole event. You can page through only a limited number of results. A request past that limit fails with <code>ValidationException</code> (reason <code>invalidNextToken</code>), and the message gives the limit.</p> <p>If the results are larger than 5 MiB, the request fails with <code>ValidationException</code> (reason <code>queryBodyTooLarge</code>). Lower <code>maxResults</code>.</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 space whose events to search. Use <code>actorId</code> and <code>sessionIds</code> to narrow the search within it.</p>
        actor_id: <p>The actor whose events to search (exact match). Required: every search covers exactly one actor, and an event stored without an actor is never returned. Narrow the search further with <code>sessionIds</code>, combined by AND. This is the only way to filter by actor: a query that references <code>system_metadata.actor_id</code> fails with <code>ValidationException</code> (reason <code>nonFilterableField</code>).</p>
        session_ids: <p>Returns only events from one of these sessions (exact match). Combined with <code>actorId</code> by AND. Omit for no session filter. An empty list fails validation. An event stored without a session never matches a session filter. This is the only way to filter by session: a query that references <code>system_metadata.session_id</code> fails with <code>ValidationException</code> (reason <code>nonFilterableField</code>).</p>
        query: <p>The query: a subset of the OpenSearch Query DSL (see <code>SearchQuery</code>), validated by the same rules as on <code>SearchMemories</code>. Query event text as <code>text</code> and embeddings as <code>vector</code>. A search covers both conversation turns and chunks of documents submitted as a <code>blob</code>. You can't use actor and session fields here. Use the top-level <code>actorId</code> and <code>sessionIds</code>.</p> <p>To search only the content of particular events, filter on <code>event_ids</code> with <code>term</code> or <code>terms</code>, for example with the <code>sourceEventIds</code> that a <code>SearchMemories</code> result returns. A <code>terms</code> clause on <code>event_ids</code> can list up to 10 event IDs. More IDs fail with <code>ValidationException</code> (reason <code>queryBodyTooLarge</code>). You can use <code>event_ids</code> only in <code>term</code>, <code>terms</code>, and <code>exists</code> queries.</p>
        sort: <p>The sort order (see <code>SearchSort</code>). Omit to return the most relevant events first.</p>
        max_results: <p>The maximum number of events to return, from 1 to 100. The default is 20.</p>
        next_token: <p>The token for the next set of results. Use the value returned in the previous response in the next request to retrieve the next set of results.</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.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.search_events_input.SearchEventsInput]",
    ) -> OperationResponse[
        "capo_opensearchmemory.types.search_events_output.SearchEventsOutput"
    ]:
        import capo_opensearchmemory._operations.open_search_memory.search_events

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

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

        return capo_opensearchmemory.types.search_events_input.redact_sensitive(
            input_
        )

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

        return capo_opensearchmemory.types.search_events_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "SearchEvents", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_opensearchmemory.types.search_events_input.SearchEventsInput = {
        "space_id": space_id,
        "actor_id": actor_id,
        "query": query,
    }
    if session_ids is not None:
        input_["session_ids"] = session_ids
    if sort is not None:
        input_["sort"] = sort
    if max_results is not None:
        input_["max_results"] = max_results
    if next_token is not None:
        input_["next_token"] = next_token

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