Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

AmazonBedrockKnowledgeBaseRetriever

Retrieve documents from an Amazon Bedrock Managed Knowledge Base using semantic search — no separate document store required.

Key Features​

  • Connects directly to Amazon Bedrock Knowledge Bases, bypassing the need for a separate document store.
  • Supports both the standard Retrieve API and the AgenticRetrieveStream API for richer, agent-compatible results.
  • Automatically falls back from AgenticRetrieveStream to the standard Retrieve API when the agentic endpoint is unavailable.
  • Returns documents with source URIs extracted from S3, web, Confluence, Salesforce, SharePoint, and custom locations.
  • Flexible AWS authentication: access keys, session tokens, IAM roles, or named profiles.
  • Configurable number of results at init time, overridable at query time.

Configuration​

  1. Drag the AmazonBedrockKnowledgeBaseRetriever component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Set the knowledge_base_id to the ID of your Bedrock Knowledge Base. You can also set the AWS_KNOWLEDGE_BASE_ID environment variable instead.
    2. Create secrets with your AWS credentials. For instructions, see Create Secrets. Use these environment variable names:
      • AWS_ACCESS_KEY_ID
      • AWS_SECRET_ACCESS_KEY
      • AWS_DEFAULT_REGION
  4. Go to the Advanced tab to configure number_of_results and use_agentic_retrieval.

Connections​

AmazonBedrockKnowledgeBaseRetriever receives a text query string as input, typically from the Input component. It outputs a list of retrieved Document objects you can connect to PromptBuilder, a ranker, or AnswerBuilder.

Source Code​

To check this component's source code, open knowledge_base_retriever.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

AmazonBedrockKnowledgeBaseRetriever:
type: haystack_integrations.components.retrievers.amazon_bedrock.knowledge_base_retriever.AmazonBedrockKnowledgeBaseRetriever
init_parameters:
knowledge_base_id: ABCDEFGHIJ
number_of_results: 5
aws_access_key_id:
type: env_var
env_vars:
- AWS_ACCESS_KEY_ID
strict: false
aws_secret_access_key:
type: env_var
env_vars:
- AWS_SECRET_ACCESS_KEY
strict: false
aws_region_name:
type: env_var
env_vars:
- AWS_DEFAULT_REGION
strict: false

Using the Component in a Pipeline​

# haystack-pipeline
components:
retriever:
type: haystack_integrations.components.retrievers.amazon_bedrock.knowledge_base_retriever.AmazonBedrockKnowledgeBaseRetriever
init_parameters:
knowledge_base_id: ABCDEFGHIJ
number_of_results: 5
aws_access_key_id:
type: env_var
env_vars:
- AWS_ACCESS_KEY_ID
strict: false
aws_secret_access_key:
type: env_var
env_vars:
- AWS_SECRET_ACCESS_KEY
strict: false
aws_region_name:
type: env_var
env_vars:
- AWS_DEFAULT_REGION
strict: false

prompt_builder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
required_variables: "*"
template:
- role: system
content: Answer questions based on the provided documents.
- role: user
content: |
Documents:
{% for doc in documents %}
{{ doc.content }}
{% endfor %}
Question: {{ question }}

llm:
type: haystack_integrations.components.generators.amazon_bedrock.chat.chat_generator.AmazonBedrockChatGenerator
init_parameters:
model: global.anthropic.claude-sonnet-4-6
aws_access_key_id:
type: env_var
env_vars:
- AWS_ACCESS_KEY_ID
strict: false
aws_secret_access_key:
type: env_var
env_vars:
- AWS_SECRET_ACCESS_KEY
strict: false

answer_builder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters:
reference_pattern: acm

connections:
- sender: retriever.documents
receiver: prompt_builder.documents
- sender: prompt_builder.prompt
receiver: llm.messages
- sender: llm.replies
receiver: answer_builder.replies

max_runs_per_component: 100

metadata: {}

inputs:
query:
- retriever.query
- prompt_builder.question
- answer_builder.query

outputs:
answers: answer_builder.answers

Parameters​

Inputs​

ParameterTypeDescription
querystrThe search query to run against the Knowledge Base.
top_kOptional[int]Maximum number of documents to return. Overrides number_of_results when provided.

Outputs​

ParameterTypeDescription
documentsList[Document]The retrieved documents. Each document includes a source URI and a relevance score in its metadata.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
knowledge_base_idstrThe ID of the Bedrock Knowledge Base. Falls back to the AWS_KNOWLEDGE_BASE_ID environment variable.
aws_access_key_idOptional[Secret]Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False)The AWS access key ID.
aws_secret_access_keyOptional[Secret]Secret.from_env_var("AWS_SECRET_ACCESS_KEY", strict=False)The AWS secret access key.
aws_session_tokenOptional[Secret]Secret.from_env_var("AWS_SESSION_TOKEN", strict=False)The AWS session token for temporary credentials.
aws_region_nameOptional[Secret or str]Secret.from_env_var("AWS_DEFAULT_REGION", strict=False)The AWS region. Required when using region-specific Knowledge Bases.
aws_profile_nameOptional[Secret]Secret.from_env_var("AWS_PROFILE", strict=False)The AWS named profile to use for authentication.
number_of_resultsint5Maximum number of documents to return per query.
use_agentic_retrievalOptional[bool]TrueWhen True, the component tries AgenticRetrieveStream first and falls back to the standard Retrieve API. Defaults to the USE_AGENTIC_RETRIEVAL environment variable.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
querystrThe search query to run against the Knowledge Base.
top_kOptional[int]NoneOverride the init-time number_of_results for this request.