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
- Drag the
AmazonBedrockKnowledgeBaseRetrievercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the
knowledge_base_idto the ID of your Bedrock Knowledge Base. You can also set theAWS_KNOWLEDGE_BASE_IDenvironment variable instead. - Create secrets with your AWS credentials. For instructions, see Create Secrets. Use these environment variable names:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGION
- Set the
- Go to the Advanced tab to configure
number_of_resultsanduse_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
| Parameter | Type | Description |
|---|---|---|
query | str | The search query to run against the Knowledge Base. |
top_k | Optional[int] | Maximum number of documents to return. Overrides number_of_results when provided. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[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:
| Parameter | Type | Default | Description |
|---|---|---|---|
knowledge_base_id | str | The ID of the Bedrock Knowledge Base. Falls back to the AWS_KNOWLEDGE_BASE_ID environment variable. | |
aws_access_key_id | Optional[Secret] | Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False) | The AWS access key ID. |
aws_secret_access_key | Optional[Secret] | Secret.from_env_var("AWS_SECRET_ACCESS_KEY", strict=False) | The AWS secret access key. |
aws_session_token | Optional[Secret] | Secret.from_env_var("AWS_SESSION_TOKEN", strict=False) | The AWS session token for temporary credentials. |
aws_region_name | Optional[Secret or str] | Secret.from_env_var("AWS_DEFAULT_REGION", strict=False) | The AWS region. Required when using region-specific Knowledge Bases. |
aws_profile_name | Optional[Secret] | Secret.from_env_var("AWS_PROFILE", strict=False) | The AWS named profile to use for authentication. |
number_of_results | int | 5 | Maximum number of documents to return per query. |
use_agentic_retrieval | Optional[bool] | True | When 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | The search query to run against the Knowledge Base. | |
top_k | Optional[int] | None | Override the init-time number_of_results for this request. |
Related Information
Was this page helpful?