Skip to content

Queries a knowledge base and generates responses based on the retrieved results, with output in streaming format

Description

Queries a knowledge base and generates responses based on the retrieved results, with output in streaming format.

This API cannot be used with managed knowledge bases. Use agentic_retrieve_stream or retrieve with managed knowledge bases.

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeModelWithResponseStream.

This operation requires permission for the bedrock:RetrieveAndGenerate action.

Usage

bedrockagentruntime_retrieve_and_generate_stream(input,
  retrieveAndGenerateConfiguration, sessionConfiguration, sessionId,
  userContext)

Arguments

  • input

    [required] Contains the query to be made to the knowledge base.

  • retrieveAndGenerateConfiguration

    Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations.

  • sessionConfiguration

    Contains details about the session with the knowledge base.

  • sessionId

    The unique identifier of the session. When you first make a retrieve_and_generate request, Amazon Bedrock automatically generates this value. You must reuse this value for all subsequent requests in the same conversational session. This value allows Amazon Bedrock to maintain context and knowledge from previous interactions. You can't explicitly set the sessionId yourself.

  • userContext

    Contains information about the user making the request. This is used for access control filtering to ensure that retrieval results only include documents the user is authorized to access.

Value

A list with the following syntax:

list(
  sessionId = "string",
  stream = list(
    accessDeniedException = list(
      message = "string"
    ),
    badGatewayException = list(
      message = "string",
      resourceName = "string"
    ),
    citation = list(
      citation = list(
        generatedResponsePart = list(
          textResponsePart = list(
            span = list(
              end = 123,
              start = 123
            ),
            text = "string"
          )
        ),
        retrievedReferences = list(
          list(
            content = list(
              audio = list(
                s3Uri = "string",
                transcription = "string"
              ),
              byteContent = "string",
              row = list(
                list(
                  columnName = "string",
                  columnValue = "string",
                  type = "BLOB"|"BOOLEAN"|"DOUBLE"|"NULL"|"LONG"|"STRING"
                )
              ),
              text = "string",
              type = "TEXT"|"IMAGE"|"ROW"|"AUDIO"|"VIDEO",
              video = list(
                s3Uri = "string",
                summary = "string"
              )
            ),
            location = list(
              confluenceLocation = list(
                url = "string"
              ),
              customDocumentLocation = list(
                id = "string"
              ),
              googleDriveLocation = list(
                url = "string"
              ),
              kendraDocumentLocation = list(
                uri = "string"
              ),
              oneDriveLocation = list(
                url = "string"
              ),
              s3Location = list(
                uri = "string"
              ),
              salesforceLocation = list(
                url = "string"
              ),
              sharePointLocation = list(
                url = "string"
              ),
              sqlLocation = list(
                query = "string"
              ),
              type = "S3"|"WEB"|"CONFLUENCE"|"SALESFORCE"|"SHAREPOINT"|"CUSTOM"|"KENDRA"|"SQL"|"ONEDRIVE"|"GOOGLEDRIVE",
              webLocation = list(
                url = "string"
              )
            ),
            metadata = list(
              list()
            )
          )
        )
      ),
      generatedResponsePart = list(
        textResponsePart = list(
          span = list(
            end = 123,
            start = 123
          ),
          text = "string"
        )
      ),
      retrievedReferences = list(
        list(
          content = list(
            audio = list(
              s3Uri = "string",
              transcription = "string"
            ),
            byteContent = "string",
            row = list(
              list(
                columnName = "string",
                columnValue = "string",
                type = "BLOB"|"BOOLEAN"|"DOUBLE"|"NULL"|"LONG"|"STRING"
              )
            ),
            text = "string",
            type = "TEXT"|"IMAGE"|"ROW"|"AUDIO"|"VIDEO",
            video = list(
              s3Uri = "string",
              summary = "string"
            )
          ),
          location = list(
            confluenceLocation = list(
              url = "string"
            ),
            customDocumentLocation = list(
              id = "string"
            ),
            googleDriveLocation = list(
              url = "string"
            ),
            kendraDocumentLocation = list(
              uri = "string"
            ),
            oneDriveLocation = list(
              url = "string"
            ),
            s3Location = list(
              uri = "string"
            ),
            salesforceLocation = list(
              url = "string"
            ),
            sharePointLocation = list(
              url = "string"
            ),
            sqlLocation = list(
              query = "string"
            ),
            type = "S3"|"WEB"|"CONFLUENCE"|"SALESFORCE"|"SHAREPOINT"|"CUSTOM"|"KENDRA"|"SQL"|"ONEDRIVE"|"GOOGLEDRIVE",
            webLocation = list(
              url = "string"
            )
          ),
          metadata = list(
            list()
          )
        )
      )
    ),
    conflictException = list(
      message = "string"
    ),
    dependencyFailedException = list(
      message = "string",
      resourceName = "string"
    ),
    guardrail = list(
      action = "INTERVENED"|"NONE"
    ),
    internalServerException = list(
      message = "string",
      reason = "string"
    ),
    output = list(
      text = "string"
    ),
    resourceNotFoundException = list(
      message = "string"
    ),
    serviceQuotaExceededException = list(
      message = "string"
    ),
    throttlingException = list(
      message = "string"
    ),
    validationException = list(
      message = "string"
    )
  )
)

Request syntax

svc$retrieve_and_generate_stream(
  input = list(
    text = "string"
  ),
  retrieveAndGenerateConfiguration = list(
    externalSourcesConfiguration = list(
      generationConfiguration = list(
        additionalModelRequestFields = list(
          list()
        ),
        guardrailConfiguration = list(
          guardrailId = "string",
          guardrailVersion = "string"
        ),
        inferenceConfig = list(
          textInferenceConfig = list(
            maxTokens = 123,
            stopSequences = list(
              "string"
            ),
            temperature = 123.0,
            topP = 123.0
          )
        ),
        performanceConfig = list(
          latency = "standard"|"optimized"
        ),
        promptTemplate = list(
          textPromptTemplate = "string"
        )
      ),
      modelArn = "string",
      sources = list(
        list(
          byteContent = list(
            contentType = "string",
            data = raw,
            identifier = "string"
          ),
          s3Location = list(
            uri = "string"
          ),
          sourceType = "S3"|"BYTE_CONTENT"
        )
      )
    ),
    knowledgeBaseConfiguration = list(
      generationConfiguration = list(
        additionalModelRequestFields = list(
          list()
        ),
        guardrailConfiguration = list(
          guardrailId = "string",
          guardrailVersion = "string"
        ),
        inferenceConfig = list(
          textInferenceConfig = list(
            maxTokens = 123,
            stopSequences = list(
              "string"
            ),
            temperature = 123.0,
            topP = 123.0
          )
        ),
        performanceConfig = list(
          latency = "standard"|"optimized"
        ),
        promptTemplate = list(
          textPromptTemplate = "string"
        )
      ),
      knowledgeBaseId = "string",
      modelArn = "string",
      orchestrationConfiguration = list(
        additionalModelRequestFields = list(
          list()
        ),
        inferenceConfig = list(
          textInferenceConfig = list(
            maxTokens = 123,
            stopSequences = list(
              "string"
            ),
            temperature = 123.0,
            topP = 123.0
          )
        ),
        performanceConfig = list(
          latency = "standard"|"optimized"
        ),
        promptTemplate = list(
          textPromptTemplate = "string"
        ),
        queryTransformationConfiguration = list(
          type = "QUERY_DECOMPOSITION"
        )
      ),
      retrievalConfiguration = list(
        managedSearchConfiguration = list(
          filter = list(
            andAll = list(
              list()
            ),
            equals = list(
              key = "string",
              value = list()
            ),
            greaterThan = list(
              key = "string",
              value = list()
            ),
            greaterThanOrEquals = list(
              key = "string",
              value = list()
            ),
            in = list(
              key = "string",
              value = list()
            ),
            lessThan = list(
              key = "string",
              value = list()
            ),
            lessThanOrEquals = list(
              key = "string",
              value = list()
            ),
            listContains = list(
              key = "string",
              value = list()
            ),
            notEquals = list(
              key = "string",
              value = list()
            ),
            notIn = list(
              key = "string",
              value = list()
            ),
            orAll = list(
              list()
            ),
            startsWith = list(
              key = "string",
              value = list()
            ),
            stringContains = list(
              key = "string",
              value = list()
            )
          ),
          numberOfResults = 123,
          rerankingConfiguration = list(
            bedrockRerankingConfiguration = list(
              metadataConfiguration = list(
                selectionMode = "SELECTIVE"|"ALL",
                selectiveModeConfiguration = list(
                  fieldsToExclude = list(
                    list(
                      fieldName = "string"
                    )
                  ),
                  fieldsToInclude = list(
                    list(
                      fieldName = "string"
                    )
                  )
                )
              ),
              modelConfiguration = list(
                additionalModelRequestFields = list(
                  list()
                ),
                modelArn = "string"
              ),
              numberOfRerankedResults = 123
            ),
            type = "BEDROCK_RERANKING_MODEL"
          ),
          rerankingModelType = "CUSTOM"|"MANAGED"|"NONE"
        ),
        vectorSearchConfiguration = list(
          filter = list(
            andAll = list(
              list()
            ),
            equals = list(
              key = "string",
              value = list()
            ),
            greaterThan = list(
              key = "string",
              value = list()
            ),
            greaterThanOrEquals = list(
              key = "string",
              value = list()
            ),
            in = list(
              key = "string",
              value = list()
            ),
            lessThan = list(
              key = "string",
              value = list()
            ),
            lessThanOrEquals = list(
              key = "string",
              value = list()
            ),
            listContains = list(
              key = "string",
              value = list()
            ),
            notEquals = list(
              key = "string",
              value = list()
            ),
            notIn = list(
              key = "string",
              value = list()
            ),
            orAll = list(
              list()
            ),
            startsWith = list(
              key = "string",
              value = list()
            ),
            stringContains = list(
              key = "string",
              value = list()
            )
          ),
          implicitFilterConfiguration = list(
            metadataAttributes = list(
              list(
                description = "string",
                key = "string",
                type = "STRING"|"NUMBER"|"BOOLEAN"|"STRING_LIST"
              )
            ),
            modelArn = "string"
          ),
          numberOfResults = 123,
          overrideSearchType = "HYBRID"|"SEMANTIC",
          rerankingConfiguration = list(
            bedrockRerankingConfiguration = list(
              metadataConfiguration = list(
                selectionMode = "SELECTIVE"|"ALL",
                selectiveModeConfiguration = list(
                  fieldsToExclude = list(
                    list(
                      fieldName = "string"
                    )
                  ),
                  fieldsToInclude = list(
                    list(
                      fieldName = "string"
                    )
                  )
                )
              ),
              modelConfiguration = list(
                additionalModelRequestFields = list(
                  list()
                ),
                modelArn = "string"
              ),
              numberOfRerankedResults = 123
            ),
            type = "BEDROCK_RERANKING_MODEL"
          )
        )
      )
    ),
    type = "KNOWLEDGE_BASE"|"EXTERNAL_SOURCES"
  ),
  sessionConfiguration = list(
    kmsKeyArn = "string"
  ),
  sessionId = "string",
  userContext = list(
    userId = "string"
  )
)