Queries a knowledge base and generates responses based on the retrieved results and using the specified foundation model or inference profile¶
Description¶
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.
This API cannot be used with managed knowledge bases. Use agentic_retrieve_stream or retrieve with managed knowledge bases.
Usage¶
bedrockagentruntime_retrieve_and_generate(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(
citations = 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()
)
)
)
)
),
guardrailAction = "INTERVENED"|"NONE",
output = list(
text = "string"
),
sessionId = "string"
)
Request syntax¶
svc$retrieve_and_generate(
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"
)
)