AWSKendraFrontendService

2020/09/03 - AWSKendraFrontendService - 1 updated api methods

Changes  Amazon Kendra now returns confidence scores for both 'answer' and 'question and answer' query responses.

Query (updated) Link ΒΆ
Changes (response)
{'ResultItems': {'ScoreAttributes': {'ScoreConfidence': 'VERY_HIGH | HIGH | '
                                                        'MEDIUM'}}}

Searches an active index. Use this API to search your documents using query. The Query operation enables to do faceted search and to filter results based on document attributes.

It also enables you to provide user context that Amazon Kendra uses to enforce document access control in the search results.

Amazon Kendra searches your index for text content and question and answer (FAQ) content. By default the response contains three types of results.

  • Relevant passages

  • Matching FAQs

  • Relevant documents

You can specify that the query return only one type of result using the QueryResultTypeConfig parameter.

See also: AWS API Documentation

Request Syntax

client.query(
    IndexId='string',
    QueryText='string',
    AttributeFilter={
        'AndAllFilters': [
            {'... recursive ...'},
        ],
        'OrAllFilters': [
            {'... recursive ...'},
        ],
        'NotFilter': {'... recursive ...'},
        'EqualsTo': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        },
        'ContainsAll': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        },
        'ContainsAny': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        },
        'GreaterThan': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        },
        'GreaterThanOrEquals': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        },
        'LessThan': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        },
        'LessThanOrEquals': {
            'Key': 'string',
            'Value': {
                'StringValue': 'string',
                'StringListValue': [
                    'string',
                ],
                'LongValue': 123,
                'DateValue': datetime(2015, 1, 1)
            }
        }
    },
    Facets=[
        {
            'DocumentAttributeKey': 'string'
        },
    ],
    RequestedDocumentAttributes=[
        'string',
    ],
    QueryResultTypeFilter='DOCUMENT'|'QUESTION_ANSWER'|'ANSWER',
    PageNumber=123,
    PageSize=123,
    SortingConfiguration={
        'DocumentAttributeKey': 'string',
        'SortOrder': 'DESC'|'ASC'
    }
)
type IndexId

string

param IndexId

[REQUIRED]

The unique identifier of the index to search. The identifier is returned in the response from the operation.

type QueryText

string

param QueryText

[REQUIRED]

The text to search for.

type AttributeFilter

dict

param AttributeFilter

Enables filtered searches based on document attributes. You can only provide one attribute filter; however, the AndAllFilters , NotFilter , and OrAllFilters parameters contain a list of other filters.

The AttributeFilter parameter enables you to create a set of filtering rules that a document must satisfy to be included in the query results.

  • AndAllFilters (list) --

    Performs a logical AND operation on all supplied filters.

    • (dict) --

      Provides filtering the query results based on document attributes.

      When you use the AndAllFilters or OrAllFilters , filters you can use 2 layers under the first attribute filter. For example, you can use:

      <AndAllFilters>

      • <OrAllFilters>

      • <EqualTo>

      If you use more than 2 layers, you receive a ValidationException exception with the message "AttributeFilter cannot have a depth of more than 2."

  • OrAllFilters (list) --

    Performs a logical OR operation on all supplied filters.

    • (dict) --

      Provides filtering the query results based on document attributes.

      When you use the AndAllFilters or OrAllFilters , filters you can use 2 layers under the first attribute filter. For example, you can use:

      <AndAllFilters>

      • <OrAllFilters>

      • <EqualTo>

      If you use more than 2 layers, you receive a ValidationException exception with the message "AttributeFilter cannot have a depth of more than 2."

  • NotFilter (dict) --

    Performs a logical NOT operation on all supplied filters.

  • EqualsTo (dict) --

    Performs an equals operation on two document attributes.

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

  • ContainsAll (dict) --

    Returns true when a document contains all of the specified document attributes. This filter is only applicable to StringListValue metadata.

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

  • ContainsAny (dict) --

    Returns true when a document contains any of the specified document attributes. This filter is only applicable to StringListValue metadata.

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

  • GreaterThan (dict) --

    Performs a greater than operation on two document attributes. Use with a document attribute of type Integer or Long .

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

  • GreaterThanOrEquals (dict) --

    Performs a greater or equals than operation on two document attributes. Use with a document attribute of type Integer or Long .

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

  • LessThan (dict) --

    Performs a less than operation on two document attributes. Use with a document attribute of type Integer or Long .

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

  • LessThanOrEquals (dict) --

    Performs a less than or equals operation on two document attributes. Use with a document attribute of type Integer or Long .

    • Key (string) -- [REQUIRED]

      The identifier for the attribute.

    • Value (dict) -- [REQUIRED]

      The value of the attribute.

      • StringValue (string) --

        A string, such as "department".

      • StringListValue (list) --

        A list of strings.

        • (string) --

      • LongValue (integer) --

        A long integer value.

      • DateValue (datetime) --

        A date expressed as an ISO 8601 string.

type Facets

list

param Facets

An array of documents attributes. Amazon Kendra returns a count for each attribute key specified. You can use this information to help narrow the search for your user.

  • (dict) --

    Information about a document attribute

    • DocumentAttributeKey (string) --

      The unique key for the document attribute.

type RequestedDocumentAttributes

list

param RequestedDocumentAttributes

An array of document attributes to include in the response. No other document attributes are included in the response. By default all document attributes are included in the response.

  • (string) --

type QueryResultTypeFilter

string

param QueryResultTypeFilter

Sets the type of query. Only results for the specified query type are returned.

type PageNumber

integer

param PageNumber

Query results are returned in pages the size of the PageSize parameter. By default, Amazon Kendra returns the first page of results. Use this parameter to get result pages after the first one.

type PageSize

integer

param PageSize

Sets the number of results that are returned in each page of results. The default page size is 10. The maximum number of results returned is 100. If you ask for more than 100 results, only 100 are returned.

type SortingConfiguration

dict

param SortingConfiguration

Provides information that determines how the results of the query are sorted. You can set the field that Amazon Kendra should sort the results on, and specify whether the results should be sorted in ascending or descending order. In the case of ties in sorting the results, the results are sorted by relevance.

If you don't provide sorting configuration, the results are sorted by the relevance that Amazon Kendra determines for the result.

  • DocumentAttributeKey (string) -- [REQUIRED]

    The name of the document attribute used to sort the response. You can use any field that has the Sortable flag set to true.

    You can also sort by any of the following built-in attributes:

    • _category

    • _created_at

    • _last_updated_at

    • _version

    • _view_count

  • SortOrder (string) -- [REQUIRED]

    The order that the results should be returned in. In case of ties, the relevance assigned to the result by Amazon Kendra is used as the tie-breaker.

rtype

dict

returns

Response Syntax

{
    'QueryId': 'string',
    'ResultItems': [
        {
            'Id': 'string',
            'Type': 'DOCUMENT'|'QUESTION_ANSWER'|'ANSWER',
            'AdditionalAttributes': [
                {
                    'Key': 'string',
                    'ValueType': 'TEXT_WITH_HIGHLIGHTS_VALUE',
                    'Value': {
                        'TextWithHighlightsValue': {
                            'Text': 'string',
                            'Highlights': [
                                {
                                    'BeginOffset': 123,
                                    'EndOffset': 123,
                                    'TopAnswer': True|False
                                },
                            ]
                        }
                    }
                },
            ],
            'DocumentId': 'string',
            'DocumentTitle': {
                'Text': 'string',
                'Highlights': [
                    {
                        'BeginOffset': 123,
                        'EndOffset': 123,
                        'TopAnswer': True|False
                    },
                ]
            },
            'DocumentExcerpt': {
                'Text': 'string',
                'Highlights': [
                    {
                        'BeginOffset': 123,
                        'EndOffset': 123,
                        'TopAnswer': True|False
                    },
                ]
            },
            'DocumentURI': 'string',
            'DocumentAttributes': [
                {
                    'Key': 'string',
                    'Value': {
                        'StringValue': 'string',
                        'StringListValue': [
                            'string',
                        ],
                        'LongValue': 123,
                        'DateValue': datetime(2015, 1, 1)
                    }
                },
            ],
            'ScoreAttributes': {
                'ScoreConfidence': 'VERY_HIGH'|'HIGH'|'MEDIUM'
            }
        },
    ],
    'FacetResults': [
        {
            'DocumentAttributeKey': 'string',
            'DocumentAttributeValueCountPairs': [
                {
                    'DocumentAttributeValue': {
                        'StringValue': 'string',
                        'StringListValue': [
                            'string',
                        ],
                        'LongValue': 123,
                        'DateValue': datetime(2015, 1, 1)
                    },
                    'Count': 123
                },
            ]
        },
    ],
    'TotalNumberOfResults': 123
}

Response Structure

  • (dict) --

    • QueryId (string) --

      The unique identifier for the search. You use QueryId to identify the search when using the feedback API.

    • ResultItems (list) --

      The results of the search.

      • (dict) --

        A single query result.

        A query result contains information about a document returned by the query. This includes the original location of the document, a list of attributes assigned to the document, and relevant text from the document that satisfies the query.

        • Id (string) --

          The unique identifier for the query result.

        • Type (string) --

          The type of document.

        • AdditionalAttributes (list) --

          One or more additional attributes associated with the query result.

          • (dict) --

            An attribute returned from an index query.

            • Key (string) --

              The key that identifies the attribute.

            • ValueType (string) --

              The data type of the Value property.

            • Value (dict) --

              An object that contains the attribute value.

              • TextWithHighlightsValue (dict) --

                The text associated with the attribute and information about the highlight to apply to the text.

                • Text (string) --

                  The text to display to the user.

                • Highlights (list) --

                  The beginning and end of the text that should be highlighted.

                  • (dict) --

                    Provides information that you can use to highlight a search result so that your users can quickly identify terms in the response.

                    • BeginOffset (integer) --

                      The zero-based location in the response string where the highlight starts.

                    • EndOffset (integer) --

                      The zero-based location in the response string where the highlight ends.

                    • TopAnswer (boolean) --

                      Indicates whether the response is the best response. True if this is the best response; otherwise, false.

        • DocumentId (string) --

          The unique identifier for the document.

        • DocumentTitle (dict) --

          The title of the document. Contains the text of the title and information for highlighting the relevant terms in the title.

          • Text (string) --

            The text to display to the user.

          • Highlights (list) --

            The beginning and end of the text that should be highlighted.

            • (dict) --

              Provides information that you can use to highlight a search result so that your users can quickly identify terms in the response.

              • BeginOffset (integer) --

                The zero-based location in the response string where the highlight starts.

              • EndOffset (integer) --

                The zero-based location in the response string where the highlight ends.

              • TopAnswer (boolean) --

                Indicates whether the response is the best response. True if this is the best response; otherwise, false.

        • DocumentExcerpt (dict) --

          An extract of the text in the document. Contains information about highlighting the relevant terms in the excerpt.

          • Text (string) --

            The text to display to the user.

          • Highlights (list) --

            The beginning and end of the text that should be highlighted.

            • (dict) --

              Provides information that you can use to highlight a search result so that your users can quickly identify terms in the response.

              • BeginOffset (integer) --

                The zero-based location in the response string where the highlight starts.

              • EndOffset (integer) --

                The zero-based location in the response string where the highlight ends.

              • TopAnswer (boolean) --

                Indicates whether the response is the best response. True if this is the best response; otherwise, false.

        • DocumentURI (string) --

          The URI of the original location of the document.

        • DocumentAttributes (list) --

          An array of document attributes for the document that the query result maps to. For example, the document author (Author) or the source URI (SourceUri) of the document.

          • (dict) --

            A custom attribute value assigned to a document.

            • Key (string) --

              The identifier for the attribute.

            • Value (dict) --

              The value of the attribute.

              • StringValue (string) --

                A string, such as "department".

              • StringListValue (list) --

                A list of strings.

                • (string) --

              • LongValue (integer) --

                A long integer value.

              • DateValue (datetime) --

                A date expressed as an ISO 8601 string.

        • ScoreAttributes (dict) --

          Indicates the confidence that Amazon Kendra has that a result matches the query that you provided. Each result is placed into a bin that indicates the confidence, VERY_HIGH , HIGH , and MEDIUM . You can use the score to determine if a response meets the confidence needed for your application.

          Confidence scores are only returned for results with the Type field set to QUESTION_ANSWER or ANSWER . This field is not returned if the Type field is set to DOCUMENT .

          • ScoreConfidence (string) --

            A relative ranking for how well the response matches the query.

    • FacetResults (list) --

      Contains the facet results. A FacetResult contains the counts for each attribute key that was specified in the Facets input parameter.

      • (dict) --

        The facet values for the documents in the response.

        • DocumentAttributeKey (string) --

          The key for the facet values. This is the same as the DocumentAttributeKey provided in the query.

        • DocumentAttributeValueCountPairs (list) --

          An array of key/value pairs, where the key is the value of the attribute and the count is the number of documents that share the key value.

          • (dict) --

            Provides the count of documents that match a particular attribute when doing a faceted search.

            • DocumentAttributeValue (dict) --

              The value of the attribute. For example, "HR."

              • StringValue (string) --

                A string, such as "department".

              • StringListValue (list) --

                A list of strings.

                • (string) --

              • LongValue (integer) --

                A long integer value.

              • DateValue (datetime) --

                A date expressed as an ISO 8601 string.

            • Count (integer) --

              The number of documents in the response that have the attribute value for the key.

    • TotalNumberOfResults (integer) --

      The number of items returned by the search. Use this to determine when you have requested the last set of results.