Skip to content

BedrockAgentRuntimeClient.retrieve_and_generate

rboto-bedrock-agent-runtime==0.4.0 · Service index · Types

Model summary (excerpt): 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 AgenticRetrieveStream or Retrieve with managed knowledge bases.

Install and imports

python -m pip install "rboto[bedrock-agent-runtime]==0.4.0"
from rboto import BedrockAgentRuntimeClient
from rboto_bedrock_agent_runtime.types import (
    RetrieveAndGenerateConfiguration,
    RetrieveAndGenerateInput,
    RetrieveAndGenerateOutput,
    RetrieveAndGenerateSessionConfiguration,
    UserContext,
)

Signature

async def retrieve_and_generate(
    *,
    input: RetrieveAndGenerateInput,
    session_id: str | None = None,
    retrieve_and_generate_configuration: RetrieveAndGenerateConfiguration | None = None,
    session_configuration: RetrieveAndGenerateSessionConfiguration | None = None,
    user_context: UserContext | None = None,
) -> RetrieveAndGenerateOutput: ...

Arguments without defaults are required. None omits an optional request argument. Static types do not validate resource existence, permissions, lengths, ranges, or conditional service requirements.

Arguments

Argument Required Model notes (excerpt)
input Yes Contains the query to be made to the knowledge base.
session_id No 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.
retrieve_and_generate_configuration No Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations .
session_configuration No Contains details about the session with the knowledge base.
user_context No 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.

Output

RetrieveAndGenerateOutput.

Read-only native attributes, accessed as response.field. Collection getters materialize Python values; to_dict() recursively materializes a mapping. Streams are consumed once.

Field Type Presence References
session_id str Always present —
output RetrieveAndGenerateValueOutput | None Always present RetrieveAndGenerateValueOutput
citations list[CitationOutput] | None Always present CitationOutput
guardrail_action GuadrailActionOutput | None Always present GuadrailActionOutput

| None means a value can be absent. Output mappings include every declared key; optional input keys may be omitted. Unknown output enum/union variants are not automatically valid inputs.

RetrieveAndGenerateConfiguration, RetrieveAndGenerateInput, RetrieveAndGenerateOutput, RetrieveAndGenerateSessionConfiguration, UserContext

Follow these links for nested inputs and outputs; recursive types link back to the same type page.

Pagination and streaming

No generated paginator for this operation.

No output stream.

Errors

Import from rboto_bedrock_agent_runtime.exceptions:

AccessDeniedError, BadGatewayError, ConflictError, DependencyFailedError, InternalServerError, ResourceNotFoundError, ServiceQuotaExceededError, ThrottlingError, ValidationError.

Other service failures use the service base error; credential, transport and timeout failures use shared errors.

Service guide · Pinned model