retrieve_and_generate_stream
async
¶
retrieve_and_generate_stream(
input: RetrieveAndGenerateInput,
*,
config_overrides: Optional[AsyncBedrockAgentRuntimeClientConfig] = None,
session_id: Optional[SessionId] = None,
retrieve_and_generate_configuration: Optional[
RetrieveAndGenerateConfiguration
] = None,
session_configuration: Optional[RetrieveAndGenerateSessionConfiguration] = None,
user_context: Optional[UserContext] = None,
) -> AsyncGenerator[RetrieveAndGenerateStreamResponse]
Queries a knowledge base and generates responses based on the retrieved results, with output in streaming format.
This API cannot be used with managed knowledge bases. Use AgenticRetrieveStream or Retrieve with managed knowledge bases.
The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeModelWithResponseStream.
This operation requires permission for the bedrock:RetrieveAndGenerate action.
Parameters:
-
session_id(Optional[SessionId], default:None) –The unique identifier of the session. When you first make a
RetrieveAndGeneraterequest, 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 thesessionIdyourself. -
input(RetrieveAndGenerateInput) –Contains the query to be made to the knowledge base.
-
retrieve_and_generate_configuration(Optional[RetrieveAndGenerateConfiguration], default:None) –Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations.
-
session_configuration(Optional[RetrieveAndGenerateSessionConfiguration], default:None) –Contains details about the session with the knowledge base.
-
user_context(Optional[UserContext], default: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.
Raises:
-
AccessDeniedException–The request is denied because of missing access permissions. Check your permissions and retry your request.
-
BadGatewayException–There was an issue with a dependency due to a server issue. Retry your request.
-
ConflictException–There was a conflict performing an operation. Resolve the conflict and retry your request.
-
DependencyFailedException–There was an issue with a dependency. Check the resource configurations and retry the request.
-
InternalServerException–An internal server error occurred. Retry your request.
-
ResourceNotFoundException–The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.
-
ServiceQuotaExceededException–The number of requests exceeds the service quota. Resubmit your request later.
-
ThrottlingException–The number of requests exceeds the limit. Resubmit your request later.
-
ValidationException–Input validation failed. Check your request parameters and retry the request.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_bedrock_agent_runtime/_services/async_bedrock_agent_runtime.py
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 | |