retrieveAndGenerateStream method
- required RetrieveAndGenerateInput input,
- RetrieveAndGenerateConfiguration? retrieveAndGenerateConfiguration,
- RetrieveAndGenerateSessionConfiguration? sessionConfiguration,
- String? sessionId,
Queries a knowledge base and generates responses based on the retrieved
results, with output in streaming format.
This operation requires permission for the
bedrock:RetrieveAndGenerate action.
May throw AccessDeniedException.
May throw BadGatewayException.
May throw ConflictException.
May throw DependencyFailedException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter input :
Contains the query to be made to the knowledge base.
Parameter retrieveAndGenerateConfiguration :
Contains configurations for the knowledge base query and retrieval
process. For more information, see Query
configurations.
Parameter sessionConfiguration :
Contains details about the session with the knowledge base.
Parameter sessionId :
The unique identifier of the session. When you first make a
RetrieveAndGenerate 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.
Implementation
Future<RetrieveAndGenerateStreamResponse> retrieveAndGenerateStream({
required RetrieveAndGenerateInput input,
RetrieveAndGenerateConfiguration? retrieveAndGenerateConfiguration,
RetrieveAndGenerateSessionConfiguration? sessionConfiguration,
String? sessionId,
}) async {
final $payload = <String, dynamic>{
'input': input,
if (retrieveAndGenerateConfiguration != null)
'retrieveAndGenerateConfiguration': retrieveAndGenerateConfiguration,
if (sessionConfiguration != null)
'sessionConfiguration': sessionConfiguration,
if (sessionId != null) 'sessionId': sessionId,
};
final response = await _protocol.sendRaw(
payload: $payload,
method: 'POST',
requestUri: '/retrieveAndGenerateStream',
exceptionFnMap: _exceptionFns,
);
final $json = await _s.jsonFromResponse(response);
return RetrieveAndGenerateStreamResponse(
stream: RetrieveAndGenerateStreamResponseOutput.fromJson($json),
sessionId: _s.extractHeaderStringValue(
response.headers, 'x-amzn-bedrock-knowledge-base-session-id')!,
);
}