OpenSearchMemory / Client / search_events

search_events

OpenSearchMemory.Client.search_events(**kwargs)

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.

See also: AWS API Documentation

Request Syntax

response = client.search_events(
    spaceId='string',
    actorId='string',
    sessionIds=[
        'string',
    ],
    query={...}|[...]|123|123.4|'string'|True|None,
    sort={...}|[...]|123|123.4|'string'|True|None,
    maxResults=123,
    nextToken='string'
)
Parameters:
  • spaceId (string) –

    [REQUIRED]

    The space whose events to search. Use actorId and sessionIds to narrow the search within it.

  • actorId (string) –

    [REQUIRED]

    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).

  • sessionIds (list) –

    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).

    • (string) –

      The ID of a session, which groups an actor’s events.

  • query (document) –

    [REQUIRED]

    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 (document) – The sort order (see SearchSort). Omit to return the most relevant events first.

  • maxResults (integer) – The maximum number of events to return, from 1 to 100. The default is 20.

  • nextToken (string) – 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.

Return type:

dict

Returns:

Response Syntax

{
    'events': [
        {
            'eventId': 'string',
            'score': 123.0,
            'systemMetadata': {
                'actorId': 'string',
                'sessionId': 'string',
                'createdAt': datetime(2015, 1, 1),
                'updatedAt': datetime(2015, 1, 1)
            },
            'metadata': {
                'string': 'string'
            },
            'matchedContent': 'string'
        },
    ],
    'nextToken': 'string'
}

Response Structure

  • (dict) –

    • events (list) –

      The matching event chunks, in the order sort requests, or most relevant first when it has none. Empty when nothing matches. Each result is the matching chunk of an event. Call GetEvent for the whole event.

      • (dict) –

        A SearchEvents result: the matching chunk of an event and its provenance. Unlike EventSummary from ListEvents, it has a relevance score and the matched content, but not the full payload.

        • eventId (string) –

          The ID of the event that the chunk belongs to. Use it with GetEvent or DeleteEvent.

        • score (float) –

          The relevance score of the result. A higher score is more relevant. Scores aren’t normalized to a fixed range and can be greater than 1, so use them only to order results.

        • systemMetadata (dict) –

          Provenance for the chunk: the owning actor and session, and when it was created and last updated. It is the same block that ListMemories and SearchMemories return. Event chunks are never modified, so updatedAt always equals createdAt.

          Absent when the service has no provenance for the chunk.

          • actorId (string) –

            The owning actor. Absent when none was recorded.

          • sessionId (string) –

            The owning session. Absent when none was recorded.

          • createdAt (datetime) –

            When the record was created. Always present on ListMemories and GetMemory. It can be absent from search results.

          • updatedAt (datetime) –

            When the record was last updated. Equals createdAt for a record that has never been updated, and always for a SearchEvents result.

        • metadata (dict) –

          The event’s metadata tags. All values are strings. In a query, filter on a tag as metadata.<key>.

          • (string) –

            A metadata key: letters, digits, hyphens ( -), and underscores ( _). Dots are not allowed, because a query uses dots to separate nested field names.

            • (string) –

              The value of a metadata entry.

        • matchedContent (string) –

          The text of the matching chunk.

    • nextToken (string) –

      The token for the next set of results. Absent when there are no more results.

Exceptions