SearchMemories
Searches a space's memories by relevance. The query is a subset of the OpenSearch Query DSL. The service
validates it, limits the search to the requested strategies and to the actor in actorId, and returns
one ranked list of memories. 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.
Memories past their expiry (set from the space's memoryExpiryDays when each memory is written)
are left out of the results. Only current memories are returned: a memory that consolidation has superseded (an
older version of a fact that a newer memory replaced) is left out.
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.
Request Syntax
{
"actorId": "string",
"maxResults": number,
"memoryStrategies": [
{
"memoryStrategyNames": [ "string" ],
"memoryType": "string"
}
],
"nextToken": "string",
"query": JSON value,
"sort": JSON value,
"spaceId": "string"
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
- actorId
-
The actor whose memories to search (exact match). Required: every search covers exactly one actor, and a memory stored without an actor is never returned. This is the only way to filter by actor: a query that references
system_metadata.actor_idfails withValidationException(reasonnonFilterableField).Type: String
Length Constraints: Minimum length of 1. Maximum length of 255.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9-_]*Required: Yes
- maxResults
-
The maximum number of memories to return, from 1 to 100. The default is 20.
Type: Integer
Valid Range: Minimum value of 1. Maximum value of 100.
Required: No
- memoryStrategies
-
The strategies to search, as a list of selectors. Each selector names a memory type and, optionally, specific strategy names of that type. A space can hold several strategies of the same type. A selector without
memoryStrategyNamessearches every strategy of its type, and omittingmemoryStrategiessearches every strategy in the space. A name that is not a declared strategy of that type fails withValidationException.Type: Array of StrategySelector objects
Array Members: Minimum number of 1 item. Maximum number of 5 items.
Required: No
- nextToken
-
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.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
Required: No
- query
-
The query: a subset of the OpenSearch Query DSL (see
SearchQuery). You can't use the actor and session fieldssystem_metadata.actor_idandsystem_metadata.session_idhere. Use the top-levelactorIdto filter by actor. Searching memories doesn't filter by session.Type: JSON value
Required: Yes
- sort
-
The sort order (see
SearchSort). Omit to return the most relevant memories first.Type: JSON value
Required: No
- spaceId
-
The space to search. Use
actorIdto narrow the search within it.Type: String
Length Constraints: Minimum length of 1. Maximum length of 64.
Pattern:
sp-[a-f0-9]{12}Required: Yes
Response Syntax
{
"memories": [
{
"content": "string",
"memoryId": "string",
"memoryType": "string",
"metadata": {
"string" : "string"
},
"score": number,
"sourceEventIds": [ "string" ],
"strategyName": "string",
"systemMetadata": {
"actorId": "string",
"createdAt": "string",
"sessionId": "string",
"updatedAt": "string"
}
}
],
"nextToken": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- memories
-
The matching memories, in the order
sortrequests, or most relevant first when it has none. Empty when nothing matches.Type: Array of MemorySearchSummary objects
- nextToken
-
The token for the next set of results. Absent when there are no more results.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
Errors
For information about the errors that are common to all actions, see Common Error Types.
- 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.
- message
-
A message that describes which access the request is missing.
HTTP Status Code: 403
- InternalServerException
-
The service couldn't process the request because of an internal error. Retry the request.
- message
-
A message that describes the internal error.
HTTP Status Code: 500
- ResourceNotFoundException
-
The specified resource doesn't exist. Check the IDs in the request.
- message
-
A message that describes which resource wasn't found.
- resourceId
-
The ID of the resource that wasn't found.
- resourceType
-
The type of the resource that wasn't found.
HTTP Status Code: 404
- ThrottlingException
-
The service throttled the request. Retry the request with exponential backoff.
- message
-
A message that describes the throttling.
- retryAfterSeconds
-
The number of seconds to wait before you retry the request.
HTTP Status Code: 429
- ValidationException
-
The request isn't valid. The
reason,message, andfieldListmembers describe the problem. Fix the request, and then try again.- fieldList
-
The fields that failed validation, if any.
- message
-
A message that describes why the request failed validation, such as the field, key, or limit involved.
- reason
-
The reason that the request failed validation.
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: