retrieve_and_generate_stream¶
Operation¶
retrieve_and_generate_stream
async
¶
retrieve_and_generate_stream(input: RetrieveAndGenerateStreamInput, plugins: list[Plugin] | None = None) -> OutputEventStream[RetrieveAndGenerateStreamResponseOutput, RetrieveAndGenerateStreamOutput]
Queries a knowledge base and generates responses based on the retrieved results, with output in streaming format.
Note
This API cannot be used with managed knowledge bases. Use AgenticRetrieveStream or Retrieve with managed knowledge bases.
Note:
The CLI doesn't support streaming operations in Amazon Bedrock,
including InvokeModelWithResponseStream.
This operation requires permission for the
bedrock:RetrieveAndGenerate action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
RetrieveAndGenerateStreamInput
|
An instance of |
required |
plugins
|
list[Plugin] | None
|
A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations. |
None
|
Returns:
| Type | Description |
|---|---|
OutputEventStream[RetrieveAndGenerateStreamResponseOutput, RetrieveAndGenerateStreamOutput]
|
An |
Input¶
RetrieveAndGenerateStreamInput
dataclass
¶
Dataclass for RetrieveAndGenerateStreamInput structure.
Attributes¶
input
class-attribute
instance-attribute
¶
input: RetrieveAndGenerateInput | None = field(repr=False, default=None)
Contains the query to be made to the knowledge base.
retrieve_and_generate_configuration
class-attribute
instance-attribute
¶
retrieve_and_generate_configuration: RetrieveAndGenerateConfiguration | None = None
Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations.
session_configuration
class-attribute
instance-attribute
¶
session_configuration: RetrieveAndGenerateSessionConfiguration | None = None
Contains details about the session with the knowledge base.
session_id
class-attribute
instance-attribute
¶
session_id: str | None = None
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.
user_context
class-attribute
instance-attribute
¶
user_context: UserContext | None = field(repr=False, default=None)
Contains information about the user making the request. Use this to pass user identity information for access control filtering, so that retrieval results only include documents the user is authorized to access.
Output¶
This operation returns an OutputEventStream for server-to-client streaming.
Event Stream Structure¶
Output Event Type¶
RetrieveAndGenerateStreamResponseOutput