Skip to content

BedrockAgentRuntimeClient.retrieve

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

Model summary (excerpt): Queries a knowledge base and retrieves information from it.

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 (
    GuardrailConfiguration,
    KnowledgeBaseQuery,
    KnowledgeBaseRetrievalConfiguration,
    RetrieveOutput,
    UserContext,
)

Signature

async def retrieve(
    *,
    knowledge_base_id: str,
    retrieval_query: KnowledgeBaseQuery,
    retrieval_configuration: KnowledgeBaseRetrievalConfiguration | None = None,
    guardrail_configuration: GuardrailConfiguration | None = None,
    next_token: str | None = None,
    user_context: UserContext | None = None,
) -> RetrieveOutput: ...

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)
knowledge_base_id Yes The unique identifier of the knowledge base to query.
retrieval_query Yes Contains the query to send the knowledge base.
retrieval_configuration No Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations .
guardrail_configuration No Guardrail settings.
next_token No If there are more results than can fit in the response, the response returns a nextToken . Use this token in the nextToken field of another request to retrieve the next batch of results.
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

RetrieveOutput.

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
retrieval_results list[KnowledgeBaseRetrievalResultOutput] Always present KnowledgeBaseRetrievalResultOutput
guardrail_action GuadrailActionOutput | None Always present GuadrailActionOutput
next_token str | None Always present —

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

GuardrailConfiguration, KnowledgeBaseQuery, KnowledgeBaseRetrievalConfiguration, RetrieveOutput, UserContext

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

Pagination and streaming

client.paginators.retrieve(...) accepts the same arguments and returns AsyncIterator[RetrieveOutput]. Direct calls return one page. Pages preserve the Output representation above.

Input cursors: next_token. Page-size argument: not exposed.

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.

Example

Complete, type-checked service example. Replace its placeholders and configure credentials before running it.

import asyncio

from rboto import BedrockAgentRuntimeClient
from rboto_bedrock_agent_runtime.types import KnowledgeBaseQuery


async def main() -> None:
    client = BedrockAgentRuntimeClient(region="us-east-1")
    query: KnowledgeBaseQuery = {"text": "How do I reset my password?"}
    response = await client.retrieve(knowledge_base_id="KB12345678", retrieval_query=query)
    for result in response.retrieval_results:
        print(result.content, result.score)


if __name__ == "__main__":
    asyncio.run(main())

Service guide · Pinned model