OpenSearchMemory / Client / search_events
search_events¶
- OpenSearchMemory.Client.search_events(**kwargs)¶
Searches a space’s events by relevance. It works like
SearchMemorieswithout 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 inactorIdand the sessions insessionIds, 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 withValidationException(reasoninvalidNextToken), and the message gives the limit.If the results are larger than 5 MiB, the request fails with
ValidationException(reasonqueryBodyTooLarge). LowermaxResults.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
AccessDeniedExceptionif you aren’t allowed to use the key, and withThrottlingExceptionif AWS KMS throttles the request. It fails withValidationExceptionif 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
actorIdandsessionIdsto 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 referencessystem_metadata.actor_idfails withValidationException(reasonnonFilterableField).sessionIds (list) –
Returns only events from one of these sessions (exact match). Combined with
actorIdby 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 referencessystem_metadata.session_idfails withValidationException(reasonnonFilterableField).(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 onSearchMemories. Query event text astextand embeddings asvector. A search covers both conversation turns and chunks of documents submitted as ablob. You can’t use actor and session fields here. Use the top-levelactorIdandsessionIds.To search only the content of particular events, filter on
event_idswithtermorterms, for example with thesourceEventIdsthat aSearchMemoriesresult returns. Atermsclause onevent_idscan list up to 10 event IDs. More IDs fail withValidationException(reasonqueryBodyTooLarge). You can useevent_idsonly interm,terms, andexistsqueries.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
sortrequests, or most relevant first when it has none. Empty when nothing matches. Each result is the matching chunk of an event. CallGetEventfor the whole event.(dict) –
A
SearchEventsresult: the matching chunk of an event and its provenance. UnlikeEventSummaryfromListEvents, 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
GetEventorDeleteEvent.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
ListMemoriesandSearchMemoriesreturn. Event chunks are never modified, soupdatedAtalways equalscreatedAt.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
ListMemoriesandGetMemory. It can be absent from search results.updatedAt (datetime) –
When the record was last updated. Equals
createdAtfor a record that has never been updated, and always for aSearchEventsresult.
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
OpenSearchMemory.Client.exceptions.ResourceNotFoundExceptionOpenSearchMemory.Client.exceptions.AccessDeniedExceptionOpenSearchMemory.Client.exceptions.ThrottlingExceptionOpenSearchMemory.Client.exceptions.InternalServerExceptionOpenSearchMemory.Client.exceptions.ValidationException