agenticRetrieveStream method

Future<AgenticRetrieveStreamResponse> agenticRetrieveStream({
  1. required AgenticRetrieveConfiguration agenticRetrieveConfiguration,
  2. required List<AgenticRetrieveMessage> messages,
  3. required List<AgenticRetriever> retrievers,
  4. bool? generateResponse,
  5. String? nextToken,
  6. AgenticRetrievePolicyConfiguration? policyConfiguration,
  7. UserContext? userContext,
})

Retrieves information from one or more knowledge bases using an agentic approach. Agentic retrieval uses a foundation model to intelligently decompose complex queries into sub-queries and iteratively retrieve relevant information from your knowledge bases. This approach improves retrieval accuracy for complex, multi-step questions that a single retrieval pass might not fully address.

The operation returns results through a stream that includes retrieval results, trace events for visibility into the process, and a generated response synthesized from the results by default, which can be turned off.

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 agenticRetrieveConfiguration : Configuration settings for the agentic retrieval operation.

Parameter messages : The list of messages for the agentic retrieval conversation.

Parameter retrievers : The list of retrievers to use for agentic retrieval.

Parameter generateResponse : Whether to generate a response based on the retrieved results.

Parameter nextToken : Opaque continuation token for paginated results.

Parameter policyConfiguration : Policy configuration for guardrails and content filtering.

Parameter 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.

Implementation

Future<AgenticRetrieveStreamResponse> agenticRetrieveStream({
  required AgenticRetrieveConfiguration agenticRetrieveConfiguration,
  required List<AgenticRetrieveMessage> messages,
  required List<AgenticRetriever> retrievers,
  bool? generateResponse,
  String? nextToken,
  AgenticRetrievePolicyConfiguration? policyConfiguration,
  UserContext? userContext,
}) async {
  final $payload = <String, dynamic>{
    'agenticRetrieveConfiguration': agenticRetrieveConfiguration,
    'messages': messages,
    'retrievers': retrievers,
    if (generateResponse != null) 'generateResponse': generateResponse,
    if (nextToken != null) 'nextToken': nextToken,
    if (policyConfiguration != null)
      'policyConfiguration': policyConfiguration,
    if (userContext != null) 'userContext': userContext,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri: '/agenticRetrieveStream',
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return AgenticRetrieveStreamResponse(
    stream: AgenticRetrieveStreamResponseOutput.fromJson($json),
  );
}