Context / Client / search_agent_context

search_agent_context

Context.Client.search_agent_context(**kwargs)

Searches an agent context for entities matching a query. Returns ranked entities with relevance scores and metadata. To see the edges around a result node, pass its node ID to TraverseAgentContext.

See also: AWS API Documentation

Request Syntax

response = client.search_agent_context(
    maxResults=123,
    nextToken='string',
    agentContextId='string',
    query='string',
    filter={
        'equalTo': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'notEqualTo': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'greaterThan': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'greaterThanOrEqualTo': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'lessThan': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'lessThanOrEqualTo': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'in': {
            'key': 'string',
            'value': {
                'stringValue': 'string',
                'numberValue': 123.0,
                'booleanValue': True|False,
                'stringListValue': [
                    'string',
                ]
            }
        },
        'andAll': [
            {'... recursive ...'},
        ]
    },
    searchType='KEYWORD'|'SEMANTIC'|'AUTO'
)
Parameters:
  • maxResults (integer) – Maximum number of results to return per page.

  • nextToken (string) – Opaque continuation token from a prior response. Omit on the first page.

  • agentContextId (string) –

    [REQUIRED]

    The agent context to search, by ID or full Amazon Resource Name (ARN).

  • query (string) –

    [REQUIRED]

    The natural-language query or keywords to search for in the agent context. AWS Context interprets it based on searchType: as literal text for KEYWORD, as a semantic concept for SEMANTIC, or as both for AUTO.

  • filter (dict) –

    Optional filter on node attributes: a single comparison, or andAll of comparisons that must all match.

    Note

    This is a Tagged Union structure. Only one of the following top level keys can be set: equalTo, notEqualTo, greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, in, andAll.

    • equalTo (dict) –

      Matches entities whose attribute equals the value. The value must be a stringValue, numberValue, or booleanValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • notEqualTo (dict) –

      Matches entities whose attribute does not equal the value. The value must be a stringValue, numberValue, or booleanValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • greaterThan (dict) –

      Matches entities whose attribute is greater than the value. The value must be a stringValue, numberValue, or booleanValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • greaterThanOrEqualTo (dict) –

      Matches entities whose attribute is greater than or equal to the value. The value must be a stringValue, numberValue, or booleanValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • lessThan (dict) –

      Matches entities whose attribute is less than the value. The value must be a stringValue, numberValue, or booleanValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • lessThanOrEqualTo (dict) –

      Matches entities whose attribute is less than or equal to the value. The value must be a stringValue, numberValue, or booleanValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • in (dict) –

      Matches entities whose attribute equals any of the values. The value must be a stringListValue.

      • key (string) – [REQUIRED]

        The name of the attribute to compare. 1 to 128 characters, with no whitespace or backtick characters.

      • value (dict) – [REQUIRED]

        The value to compare the attribute with. Use stringListValue for an in condition, and stringValue, numberValue, or booleanValue for any other condition.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: stringValue, numberValue, booleanValue, stringListValue.

        • stringValue (string) –

          A string, 1 to 2,048 characters.

        • numberValue (float) –

          A number. It must be finite.

        • booleanValue (boolean) –

          A Boolean value.

        • stringListValue (list) –

          A list of 1 to 50 strings, each 1 to 2,048 characters. Valid only for an in condition.

          • (string) –

            The value to match exactly, up to 2,048 characters, so any stored string property value can be named in an exact-match filter.

    • andAll (list) –

      Matches entities that match every condition in the list. Specify 2 to 5 conditions. A condition in the list can’t itself be an andAll.

      • (dict) –

        Filter on entity attributes: a single comparison, or andAll of comparisons that must all match.

        Note

        This is a Tagged Union structure. Only one of the following top level keys can be set: equalTo, notEqualTo, greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, in, andAll.

  • searchType (string) –

    [REQUIRED]

    The search strategy to use. Valid values:

    • KEYWORD - Full-text keyword matching (BM25).

    • SEMANTIC - Vector similarity of embeddings.

    • AUTO - Keyword matches first, then semantic matches for the remaining results.

Return type:

dict

Returns:

Response Syntax

{
    'nextToken': 'string',
    'items': [
        {
            'nodeId': 'string',
            'edgeId': {
                'from': 'string',
                'to': 'string'
            },
            'entityType': 'NODE'|'EDGE',
            'summary': 'string',
            'score': 123.0,
            'properties': {
                'string': {
                    'stringValue': 'string',
                    'intValue': 123,
                    'longValue': 123,
                    'boolValue': True|False,
                    'floatValue': ...,
                    'doubleValue': 123.0,
                    'stringListValue': [
                        'string',
                    ],
                    'intListValue': [
                        123,
                    ],
                    'longListValue': [
                        123,
                    ],
                    'floatListValue': [
                        ...,
                    ],
                    'doubleListValue': [
                        123.0,
                    ],
                    'boolListValue': [
                        True|False,
                    ]
                }
            }
        },
    ],
    'authorizationRequired': {
        'authorizationUrl': 'string',
        'message': 'string'
    }
}

Response Structure

  • (dict) –

    The response of SearchAgentContext.

    • nextToken (string) –

      Pagination cursor for the next page. Absent when there are no more results.

    • items (list) –

      The matching entities, ranked by relevance.

      • (dict) –

        One SearchAgentContext result.

        • nodeId (string) –

          Identifier of the matched node. Set when this result is a node (at most one of nodeId or edgeId).

        • edgeId (dict) –

          Identifier of the matched edge, set when this result is an edge (at most one of nodeId or edgeId). Edge search isn’t supported, so AWS Context doesn’t set this member. An edge document indexed by a custom ontology is returned with neither nodeId nor edgeId set.

          • from (string) –

            The ID of the node where the edge starts.

          • to (string) –

            The ID of the node where the edge ends.

        • entityType (string) –

          Specifies whether this result is a node or an edge. Valid values:

          • NODE - The result is a node. This is the only value that AWS Context returns.

          • EDGE - The result is an edge.

        • summary (string) –

          Human-readable description or summary of the entity.

        • score (float) –

          Relevance score indicating how well this entity matches the query.

        • properties (dict) –

          Arbitrary key-value properties stored on the entity.

          • (string) –

            • (dict) –

              The value of a property on a node or an edge in an agent context. Exactly one member is set, and the member that is set determines the value’s type.

              Note

              This is a Tagged Union structure. Only one of the following top level keys will be set: stringValue, intValue, longValue, boolValue, floatValue, doubleValue, stringListValue, intListValue, longListValue, floatListValue, doubleListValue, boolListValue. If a client receives an unknown member it will set SDK_UNKNOWN_MEMBER as the top level key, which maps to the name or tag of the unknown member. The structure of SDK_UNKNOWN_MEMBER is as follows:

              'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}
              
              • stringValue (string) –

                A string value, up to 2,048 characters.

              • intValue (integer) –

                A 32-bit signed integer value.

              • longValue (integer) –

                A 64-bit signed integer value.

              • boolValue (boolean) –

                A Boolean value.

              • floatValue (float) –

                A single-precision (32-bit) floating-point value.

              • doubleValue (float) –

                A double-precision (64-bit) floating-point value.

              • stringListValue (list) –

                A list of up to 1,000 string values, each up to 2,048 characters.

                • (string) –

              • intListValue (list) –

                A list of up to 1,000 32-bit signed integer values.

                • (integer) –

              • longListValue (list) –

                A list of up to 1,000 64-bit signed integer values.

                • (integer) –

              • floatListValue (list) –

                A list of up to 1,000 single-precision (32-bit) floating-point values.

                • (float) –

              • doubleListValue (list) –

                A list of up to 1,000 double-precision (64-bit) floating-point values.

                • (float) –

              • boolListValue (list) –

                A list of up to 1,000 Boolean values.

                • (boolean) –

    • authorizationRequired (dict) –

      Present when the end user must authorize access to a third-party resource before the search can run. In that case, items is empty. Show authorizationUrl to the end user, and retry after the user consents. Through the agent context’s MCP server, you receive this as an MCP elicitation request that contains the URL.

      • authorizationUrl (string) –

        The URL the end user opens to consent. Single-use and bound to the caller’s identity.

      • message (string) –

        A short, user-facing explanation of what is being authorized.

Exceptions