RetrieveAndGenerate
Queries a knowledge base and generates responses based on the retrieved results and using the specified foundation model or inference profile. The response only cites sources that are relevant to the query.
Note
This API cannot be used with managed knowledge bases. Use AgenticRetrieveStream or Retrieve with managed knowledge bases.
Request Syntax
POST /retrieveAndGenerate HTTP/1.1
Content-type: application/json
{
"input": {
"text": "string"
},
"retrieveAndGenerateConfiguration": {
"externalSourcesConfiguration": {
"generationConfiguration": {
"additionalModelRequestFields": {
"string" : JSON value
},
"guardrailConfiguration": {
"guardrailId": "string",
"guardrailVersion": "string"
},
"inferenceConfig": {
"textInferenceConfig": {
"maxTokens": number,
"stopSequences": [ "string" ],
"temperature": number,
"topP": number
}
},
"performanceConfig": {
"latency": "string"
},
"promptTemplate": {
"textPromptTemplate": "string"
}
},
"modelArn": "string",
"sources": [
{
"byteContent": {
"contentType": "string",
"data": blob,
"identifier": "string"
},
"s3Location": {
"uri": "string"
},
"sourceType": "string"
}
]
},
"knowledgeBaseConfiguration": {
"generationConfiguration": {
"additionalModelRequestFields": {
"string" : JSON value
},
"guardrailConfiguration": {
"guardrailId": "string",
"guardrailVersion": "string"
},
"inferenceConfig": {
"textInferenceConfig": {
"maxTokens": number,
"stopSequences": [ "string" ],
"temperature": number,
"topP": number
}
},
"performanceConfig": {
"latency": "string"
},
"promptTemplate": {
"textPromptTemplate": "string"
}
},
"knowledgeBaseId": "string",
"modelArn": "string",
"orchestrationConfiguration": {
"additionalModelRequestFields": {
"string" : JSON value
},
"inferenceConfig": {
"textInferenceConfig": {
"maxTokens": number,
"stopSequences": [ "string" ],
"temperature": number,
"topP": number
}
},
"performanceConfig": {
"latency": "string"
},
"promptTemplate": {
"textPromptTemplate": "string"
},
"queryTransformationConfiguration": {
"type": "string"
}
},
"retrievalConfiguration": {
"managedSearchConfiguration": {
"filter": { ... },
"numberOfResults": number,
"rerankingConfiguration": {
"bedrockRerankingConfiguration": {
"metadataConfiguration": {
"selectionMode": "string",
"selectiveModeConfiguration": { ... }
},
"modelConfiguration": {
"additionalModelRequestFields": {
"string" : JSON value
},
"modelArn": "string"
},
"numberOfRerankedResults": number
},
"type": "string"
},
"rerankingModelType": "string"
},
"vectorSearchConfiguration": {
"filter": { ... },
"implicitFilterConfiguration": {
"metadataAttributes": [
{
"description": "string",
"key": "string",
"type": "string"
}
],
"modelArn": "string"
},
"numberOfResults": number,
"overrideSearchType": "string",
"rerankingConfiguration": {
"bedrockRerankingConfiguration": {
"metadataConfiguration": {
"selectionMode": "string",
"selectiveModeConfiguration": { ... }
},
"modelConfiguration": {
"additionalModelRequestFields": {
"string" : JSON value
},
"modelArn": "string"
},
"numberOfRerankedResults": number
},
"type": "string"
}
}
}
},
"type": "string"
},
"sessionConfiguration": {
"kmsKeyArn": "string"
},
"sessionId": "string",
"userContext": {
"userId": "string"
}
}
URI Request Parameters
The request does not use any URI parameters.
Request Body
The request accepts the following data in JSON format.
- input
-
Contains the query to be made to the knowledge base.
Type: RetrieveAndGenerateInput object
Required: Yes
- retrieveAndGenerateConfiguration
-
Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations.
Type: RetrieveAndGenerateConfiguration object
Required: No
- sessionConfiguration
-
Contains details about the session with the knowledge base.
Type: RetrieveAndGenerateSessionConfiguration object
Required: No
- sessionId
-
The unique identifier of the session. When you first make a
RetrieveAndGeneraterequest, 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 thesessionIdyourself.Type: String
Length Constraints: Minimum length of 2. Maximum length of 100.
Pattern:
[0-9a-zA-Z._:-]+Required: No
- 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.
Type: UserContext object
Required: No
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"citations": [
{
"generatedResponsePart": {
"textResponsePart": {
"span": {
"end": number,
"start": number
},
"text": "string"
}
},
"retrievedReferences": [
{
"content": {
"audio": {
"s3Uri": "string",
"transcription": "string"
},
"byteContent": "string",
"row": [
{
"columnName": "string",
"columnValue": "string",
"type": "string"
}
],
"text": "string",
"type": "string",
"video": {
"s3Uri": "string",
"summary": "string"
}
},
"location": {
"confluenceLocation": {
"url": "string"
},
"customDocumentLocation": {
"id": "string"
},
"googleDriveLocation":