retrieve_and_generate¶
Operation¶
retrieve_and_generate
¶
retrieve_and_generate(request: RetrieveAndGenerateOperationInput | RetrieveAndGenerateOperationInputDict | None = None, /, *, plugins: list[Plugin] | None = None, **kwargs: Unpack[RetrieveAndGenerateOperationInputDict]) -> RetrieveAndGenerateOperationOutput
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.
Note
This API cannot be used with managed knowledge bases. Use AgenticRetrieveStream or Retrieve with managed knowledge bases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RetrieveAndGenerateOperationInput | RetrieveAndGenerateOperationInputDict | None
|
The input as a model or dictionary. Pass this or keyword arguments, not both. |
None
|
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
|
**kwargs
|
Unpack[RetrieveAndGenerateOperationInputDict]
|
The input fields as keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
RetrieveAndGenerateOperationOutput
|
An instance of |
retrieve_and_generate
async
¶
retrieve_and_generate(request: RetrieveAndGenerateOperationInput | RetrieveAndGenerateOperationInputDict | None = None, /, *, plugins: list[Plugin] | None = None, **kwargs: Unpack[RetrieveAndGenerateOperationInputDict]) -> RetrieveAndGenerateOperationOutput
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.
Note
This API cannot be used with managed knowledge bases. Use AgenticRetrieveStream or Retrieve with managed knowledge bases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RetrieveAndGenerateOperationInput | RetrieveAndGenerateOperationInputDict | None
|
The input as a model or dictionary. Pass this or keyword arguments, not both. |
None
|
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
|
**kwargs
|
Unpack[RetrieveAndGenerateOperationInputDict]
|
The input fields as keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
RetrieveAndGenerateOperationOutput
|
An instance of |
Input¶
Pass the input as keyword arguments, a positional dictionary, or a positional model object. Pass plugins separately as a keyword argument.
RetrieveAndGenerateOperationInputDict
¶
Bases: TypedDict
Dictionary form of RetrieveAndGenerateOperationInput.
Attributes¶
input
instance-attribute
¶
Contains the query to be made to the knowledge base.
retrieve_and_generate_configuration
instance-attribute
¶
retrieve_and_generate_configuration: RetrieveAndGenerateConfiguration | RetrieveAndGenerateConfigurationDict | None
Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations.
session_configuration
instance-attribute
¶
session_configuration: RetrieveAndGenerateSessionConfiguration | RetrieveAndGenerateSessionConfigurationDict | None
Contains details about the session with the knowledge base.
session_id
instance-attribute
¶
session_id: str | 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
instance-attribute
¶
user_context: UserContext | UserContextDict | None
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.
RetrieveAndGenerateOperationInput
dataclass
¶
Bases: _SerdeShape
Dataclass for RetrieveAndGenerateOperationInput structure.
Attributes¶
input
class-attribute
instance-attribute
¶
input: RetrieveAndGenerateInput | 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 = ...
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 = ...
Contains details about the session with the knowledge base.
session_id
class-attribute
instance-attribute
¶
session_id: str | 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 = ...
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¶
RetrieveAndGenerateOperationOutput
dataclass
¶
Bases: _SerdeShape
Dataclass for RetrieveAndGenerateOperationOutput structure.
Attributes¶
citations
class-attribute
instance-attribute
¶
A list of segments of the generated response that are based on sources in the knowledge base, alongside information about the sources.
guardrail_action
class-attribute
instance-attribute
¶
guardrail_action: str | None = ...
Specifies if there is a guardrail intervention in the response.
output
instance-attribute
¶
output: RetrieveAndGenerateOutput
Contains the response generated from querying the knowledge base.
response_metadata
class-attribute
instance-attribute
¶
Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.
session_id
instance-attribute
¶
session_id: str
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.