Agents for Amazon Bedrock Runtime

2024/02/28 - Agents for Amazon Bedrock Runtime - 2 updated api methods

Changes  This release adds support to override search strategy performed by the Retrieve and RetrieveAndGenerate APIs for Amazon Bedrock Agents

Retrieve (updated) Link ¶
Changes (request)
{'retrievalConfiguration': {'vectorSearchConfiguration': {'overrideSearchType': 'HYBRID '
                                                                                '| '
                                                                                'SEMANTIC'}}}

Retrieve from knowledge base.

See also: AWS API Documentation

Request Syntax

client.retrieve(
    knowledgeBaseId='string',
    retrievalQuery={
        'text': 'string'
    },
    retrievalConfiguration={
        'vectorSearchConfiguration': {
            'numberOfResults': 123,
            'overrideSearchType': 'HYBRID'|'SEMANTIC'
        }
    },
    nextToken='string'
)
type knowledgeBaseId

string

param knowledgeBaseId

[REQUIRED]

Identifier of the KnowledgeBase

type retrievalQuery

dict

param retrievalQuery

[REQUIRED]

Knowledge base input query.

  • text (string) -- [REQUIRED]

    Knowledge base input query in text

type retrievalConfiguration

dict

param retrievalConfiguration

Search parameters for retrieving from knowledge base.

  • vectorSearchConfiguration (dict) -- [REQUIRED]

    Knowledge base vector search configuration

    • numberOfResults (integer) --

      Top-K results to retrieve from knowledge base.

    • overrideSearchType (string) --

      Override the type of query to be performed on data store

type nextToken

string

param nextToken

Opaque continuation token of previous paginated response.

rtype

dict

returns

Response Syntax

{
    'retrievalResults': [
        {
            'content': {
                'text': 'string'
            },
            'location': {
                'type': 'S3',
                's3Location': {
                    'uri': 'string'
                }
            },
            'score': 123.0
        },
    ],
    'nextToken': 'string'
}

Response Structure

  • (dict) --

    • retrievalResults (list) --

      List of knowledge base retrieval results

      • (dict) --

        Result item returned from a knowledge base retrieval.

        • content (dict) --

          Content of a retrieval result.

          • text (string) --

            Content of a retrieval result in text

        • location (dict) --

          The source location of a retrieval result.

          • type (string) --

            The location type of a retrieval result.

          • s3Location (dict) --

            The S3 location of a retrieval result.

            • uri (string) --

              URI of S3 location

        • score (float) --

          The relevance score of a result.

    • nextToken (string) --

      Opaque continuation token of previous paginated response.

RetrieveAndGenerate (updated) Link ¶
Changes (request)
{'retrieveAndGenerateConfiguration': {'knowledgeBaseConfiguration': {'retrievalConfiguration': {'vectorSearchConfiguration': {'numberOfResults': 'integer',
                                                                                                                              'overrideSearchType': 'HYBRID '
                                                                                                                                                    '| '
                                                                                                                                                    'SEMANTIC'}}}}}

RetrieveAndGenerate API

See also: AWS API Documentation

Request Syntax

client.retrieve_and_generate(
    sessionId='string',
    input={
        'text': 'string'
    },
    retrieveAndGenerateConfiguration={
        'type': 'KNOWLEDGE_BASE',
        'knowledgeBaseConfiguration': {
            'knowledgeBaseId': 'string',
            'modelArn': 'string',
            'retrievalConfiguration': {
                'vectorSearchConfiguration': {
                    'numberOfResults': 123,
                    'overrideSearchType': 'HYBRID'|'SEMANTIC'
                }
            }
        }
    },
    sessionConfiguration={
        'kmsKeyArn': 'string'
    }
)
type sessionId

string

param sessionId

Identifier of the session.

type input

dict

param input

[REQUIRED]

Customer input of the turn

  • text (string) -- [REQUIRED]

    Customer input of the turn in text

type retrieveAndGenerateConfiguration

dict

param retrieveAndGenerateConfiguration

Configures the retrieval and generation for the session.

  • type (string) -- [REQUIRED]

    The type of RetrieveAndGenerate.

  • knowledgeBaseConfiguration (dict) --

    Configurations for retrieval and generation for knowledge base.

    • knowledgeBaseId (string) -- [REQUIRED]

      Identifier of the KnowledgeBase

    • modelArn (string) -- [REQUIRED]

      Arn of a Bedrock model.

    • retrievalConfiguration (dict) --

      Search parameters for retrieving from knowledge base.

      • vectorSearchConfiguration (dict) -- [REQUIRED]

        Knowledge base vector search configuration

        • numberOfResults (integer) --

          Top-K results to retrieve from knowledge base.

        • overrideSearchType (string) --

          Override the type of query to be performed on data store

type sessionConfiguration

dict

param sessionConfiguration

Configures common parameters of the session.

  • kmsKeyArn (string) -- [REQUIRED]

    The KMS key arn to encrypt the customer data of the session.

rtype

dict

returns

Response Syntax

{
    'sessionId': 'string',
    'output': {
        'text': 'string'
    },
    'citations': [
        {
            'generatedResponsePart': {
                'textResponsePart': {
                    'text': 'string',
                    'span': {
                        'start': 123,
                        'end': 123
                    }
                }
            },
            'retrievedReferences': [
                {
                    'content': {
                        'text': 'string'
                    },
                    'location': {
                        'type': 'S3',
                        's3Location': {
                            'uri': 'string'
                        }
                    }
                },
            ]
        },
    ]
}

Response Structure

  • (dict) --

    • sessionId (string) --

      Identifier of the session.

    • output (dict) --

      Service response of the turn

      • text (string) --

        Service response of the turn in text

    • citations (list) --

      List of citations

      • (dict) --

        Citation associated with the agent response

        • generatedResponsePart (dict) --

          Generate response part

          • textResponsePart (dict) --

            Text response part

            • text (string) --

              Response part in text

            • span (dict) --

              Span of text

              • start (integer) --

                Start of span

              • end (integer) --

                End of span

        • retrievedReferences (list) --

          list of retrieved references

          • (dict) --

            Retrieved reference

            • content (dict) --

              Content of a retrieval result.

              • text (string) --

                Content of a retrieval result in text

            • location (dict) --

              The source location of a retrieval result.

              • type (string) --

                The location type of a retrieval result.

              • s3Location (dict) --

                The S3 location of a retrieval result.

                • uri (string) --

                  URI of S3 location