From 146f998e3652f19c510f4ebde2549a4390b12cd1 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Wed, 26 Aug 2026 15:17:49 +0200 Subject: [PATCH 1/4] adding docs for bedrockretriever --- .../docs/pipeline-components/retrievers.mdx | 1 + .../bedrockknowledgebaseretriever.mdx | 129 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx diff --git a/docs-website/docs/pipeline-components/retrievers.mdx b/docs-website/docs/pipeline-components/retrievers.mdx index 122bdd046c0..f22f77cb820 100644 --- a/docs-website/docs/pipeline-components/retrievers.mdx +++ b/docs-website/docs/pipeline-components/retrievers.mdx @@ -162,6 +162,7 @@ For details on how to initialize and use a Retriever in a pipeline, see the docu | [AzureAISearchEmbeddingRetriever](retrievers/azureaisearchembeddingretriever.mdx) | An embedding Retriever compatible with the Azure AI Search Document Store. | | [AzureAISearchBM25Retriever](retrievers/azureaisearchbm25retriever.mdx) | A keyword-based Retriever that fetches Documents matching a query from the Azure AI Search Document Store. | | [AzureAISearchHybridRetriever](retrievers/azureaisearchhybridretriever.mdx) | A Retriever based both on dense and sparse embeddings, compatible with the Azure AI Search Document Store. | +| [BedrockKnowledgeBaseRetriever](retrievers/bedrockknowledgebaseretriever.mdx) | Retrieves documents from an Amazon Bedrock Managed Knowledge Base. | | [ChromaEmbeddingRetriever](retrievers/chromaembeddingretriever.mdx) | An embedding-based Retriever compatible with the Chroma Document Store. | | [ChromaQueryTextRetriever](retrievers/chromaqueryretriever.mdx) | A Retriever compatible with the Chroma Document Store that uses the Chroma query API. | | [CogneeRetriever](retrievers/cogneeretriever.mdx) | Retrieves memories from a CogneeMemoryStore and returns them as system ChatMessage objects. | diff --git a/docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx b/docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx new file mode 100644 index 00000000000..bbb36e325e0 --- /dev/null +++ b/docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx @@ -0,0 +1,129 @@ +--- +title: "BedrockKnowledgeBaseRetriever" +id: bedrockknowledgebaseretriever +slug: "/bedrockknowledgebaseretriever" +description: "Retrieves documents from an Amazon Bedrock Managed Knowledge Base." +--- + +# BedrockKnowledgeBaseRetriever + +Retrieves documents from an Amazon Bedrock Managed Knowledge Base. + +
+ +| | | +| --- | --- | +| **Most common position in a pipeline** | 1. Before a [`ChatPromptBuilder`](../builders/chatpromptbuilder.mdx) in a RAG pipeline 2. The last component in the semantic search pipeline | +| **Mandatory init variables** | `knowledge_base_id`: The ID of the Amazon Bedrock Knowledge Base. Falls back to the `AWS_KNOWLEDGE_BASE_ID` env var. | +| **Optional init variables** | `aws_access_key_id`: AWS access key ID. Can be set with `AWS_ACCESS_KEY_ID` env var.

`aws_secret_access_key`: AWS secret access key. Can be set with `AWS_SECRET_ACCESS_KEY` env var.

`aws_session_token`: AWS session token. Can be set with `AWS_SESSION_TOKEN` env var.

`aws_region_name`: AWS region name. Can be set with `AWS_DEFAULT_REGION` env var.

`aws_profile_name`: AWS profile name. Can be set with `AWS_PROFILE` env var.

`number_of_results`: Maximum number of results to return. Defaults to `5`.

`use_agentic_retrieval`: If `True`, tries the Agentic Retrieve API before falling back to the standard Retrieve API. Defaults to the `USE_AGENTIC_RETRIEVAL` env var, or `True`. | +| **Mandatory run variables** | `query`: A string | +| **Optional run variables** | `top_k`: Maximum number of results to return. Overrides `number_of_results` if provided. | +| **Output variables** | `documents`: A list of Documents | +| **API reference** | [Amazon Bedrock](/reference/integrations-amazon-bedrock) | +| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/amazon_bedrock/ | +| **Package name** | `amazon-bedrock-haystack` | + +
+ +## Overview + +`BedrockKnowledgeBaseRetriever` retrieves Documents from an Amazon Bedrock Managed Knowledge Base. Unlike most other Retrievers, it doesn't need a Haystack Document Store or an Embedder: indexing and embedding are handled entirely by AWS, and the component only needs a text `query` to search the Knowledge Base. + +By default, the Retriever tries the Agentic Retrieve API first and falls back to the standard Retrieve API if agentic retrieval isn't available for the configured Knowledge Base. You can control this behavior with the `use_agentic_retrieval` init parameter, or the `USE_AGENTIC_RETRIEVAL` environment variable. + +Each returned Document includes a `score` and metadata about where it came from: `source` (the S3, web, Confluence, Salesforce, SharePoint, or custom document location of the underlying content), `knowledge_base_id`, and `knowledge_base_type`. + +This component uses AWS for authentication. You can use the AWS CLI to authenticate through your IAM. For more information on setting up an IAM identity-based policy, see the [official documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html). + +If the AWS environment is configured correctly, the AWS credentials are not required, as they're loaded automatically from the environment or the AWS configuration file. If the AWS environment is not configured, set `aws_access_key_id`, `aws_secret_access_key`, and `aws_region_name` as environment variables or pass them as [Secret](../../concepts/secret-management.mdx) arguments. + +## Installation + +Install the Amazon Bedrock integration: + +```bash +pip install amazon-bedrock-haystack +``` + +You also need an existing [Amazon Bedrock Knowledge Base](https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base.html) with documents already ingested. Set its ID as the `AWS_KNOWLEDGE_BASE_ID` environment variable, or pass it directly as the `knowledge_base_id` init parameter. + +## Usage + +### On its own + +```python +from haystack.utils import Secret + +from haystack_integrations.components.retrievers.amazon_bedrock import ( + BedrockKnowledgeBaseRetriever, +) + +retriever = BedrockKnowledgeBaseRetriever( + knowledge_base_id="ABCDEFGHIJ", + aws_region_name=Secret.from_token("eu-central-1"), +) + +result = retriever.run(query="What are the benefits of managed knowledge bases?") +for doc in result["documents"]: + print(doc.content) + print(doc.meta["source"]) + print(doc.score) +``` + +### In a RAG pipeline + +```python +from haystack import Pipeline +from haystack.components.builders import ChatPromptBuilder +from haystack.dataclasses import ChatMessage +from haystack.utils import Secret + +from haystack_integrations.components.generators.amazon_bedrock import ( + AmazonBedrockChatGenerator, +) +from haystack_integrations.components.retrievers.amazon_bedrock import ( + BedrockKnowledgeBaseRetriever, +) + +template = [ + ChatMessage.from_user( + """ + Given these documents, answer the question.\nDocuments: + {% for doc in documents %} + {{ doc.content }} + {% endfor %} + + \nQuestion: {{question}} + \nAnswer: + """, + ), +] + +rag_pipeline = Pipeline() +rag_pipeline.add_component( + "retriever", + BedrockKnowledgeBaseRetriever( + knowledge_base_id="ABCDEFGHIJ", + aws_region_name=Secret.from_token("eu-central-1"), + ), +) +rag_pipeline.add_component( + "prompt_builder", + ChatPromptBuilder(template=template, required_variables="*"), +) +rag_pipeline.add_component( + "llm", AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6") +) + +rag_pipeline.connect("retriever.documents", "prompt_builder.documents") +rag_pipeline.connect("prompt_builder.prompt", "llm.messages") + +question = "What are the benefits of managed knowledge bases?" +result = rag_pipeline.run( + { + "retriever": {"query": question}, + "prompt_builder": {"question": question}, + }, +) +print(result["llm"]["replies"][0].text) +``` From c4d54f71a51f534b4c3b179ef43a3c2afac4a3ad Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Wed, 26 Aug 2026 16:43:04 +0200 Subject: [PATCH 2/4] updating component name --- .../docs/pipeline-components/retrievers.mdx | 2 +- ...=> amazonbedrockknowledgebaseretriever.mdx} | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) rename docs-website/docs/pipeline-components/retrievers/{bedrockknowledgebaseretriever.mdx => amazonbedrockknowledgebaseretriever.mdx} (89%) diff --git a/docs-website/docs/pipeline-components/retrievers.mdx b/docs-website/docs/pipeline-components/retrievers.mdx index f22f77cb820..195f0fc421e 100644 --- a/docs-website/docs/pipeline-components/retrievers.mdx +++ b/docs-website/docs/pipeline-components/retrievers.mdx @@ -155,6 +155,7 @@ For details on how to initialize and use a Retriever in a pipeline, see the docu | --- | --- | | [AlloyDBEmbeddingRetriever](retrievers/alloydbembeddingretriever.mdx) | An embedding-based Retriever compatible with the AlloyDB Document Store. | | [AlloyDBKeywordRetriever](retrievers/alloydbkeywordretriever.mdx) | A keyword-based Retriever that fetches Documents matching a query from the AlloyDB Document Store. | +| [AmazonBedrockKnowledgeBaseRetriever](retrievers/amazonbedrockknowledgebaseretriever.mdx) | Retrieves documents from an Amazon Bedrock Managed Knowledge Base. | | [ArangoEmbeddingRetriever](retrievers/arangoembeddingretriever.mdx) | An embedding-based Retriever compatible with the ArangoDB Document Store. | | [ArcadeDBEmbeddingRetriever](retrievers/arcadedbembeddingretriever.mdx) | An embedding-based Retriever compatible with the ArcadeDB Document Store. | | [AstraEmbeddingRetriever](retrievers/astraretriever.mdx) | An embedding-based Retriever compatible with the AstraDocumentStore. | @@ -162,7 +163,6 @@ For details on how to initialize and use a Retriever in a pipeline, see the docu | [AzureAISearchEmbeddingRetriever](retrievers/azureaisearchembeddingretriever.mdx) | An embedding Retriever compatible with the Azure AI Search Document Store. | | [AzureAISearchBM25Retriever](retrievers/azureaisearchbm25retriever.mdx) | A keyword-based Retriever that fetches Documents matching a query from the Azure AI Search Document Store. | | [AzureAISearchHybridRetriever](retrievers/azureaisearchhybridretriever.mdx) | A Retriever based both on dense and sparse embeddings, compatible with the Azure AI Search Document Store. | -| [BedrockKnowledgeBaseRetriever](retrievers/bedrockknowledgebaseretriever.mdx) | Retrieves documents from an Amazon Bedrock Managed Knowledge Base. | | [ChromaEmbeddingRetriever](retrievers/chromaembeddingretriever.mdx) | An embedding-based Retriever compatible with the Chroma Document Store. | | [ChromaQueryTextRetriever](retrievers/chromaqueryretriever.mdx) | A Retriever compatible with the Chroma Document Store that uses the Chroma query API. | | [CogneeRetriever](retrievers/cogneeretriever.mdx) | Retrieves memories from a CogneeMemoryStore and returns them as system ChatMessage objects. | diff --git a/docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx b/docs-website/docs/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx similarity index 89% rename from docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx rename to docs-website/docs/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx index bbb36e325e0..483689b88ad 100644 --- a/docs-website/docs/pipeline-components/retrievers/bedrockknowledgebaseretriever.mdx +++ b/docs-website/docs/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx @@ -1,11 +1,11 @@ --- -title: "BedrockKnowledgeBaseRetriever" -id: bedrockknowledgebaseretriever -slug: "/bedrockknowledgebaseretriever" +title: "AmazonBedrockKnowledgeBaseRetriever" +id: amazonbedrockknowledgebaseretriever +slug: "/amazonbedrockknowledgebaseretriever" description: "Retrieves documents from an Amazon Bedrock Managed Knowledge Base." --- -# BedrockKnowledgeBaseRetriever +# AmazonBedrockKnowledgeBaseRetriever Retrieves documents from an Amazon Bedrock Managed Knowledge Base. @@ -27,7 +27,7 @@ Retrieves documents from an Amazon Bedrock Managed Knowledge Base. ## Overview -`BedrockKnowledgeBaseRetriever` retrieves Documents from an Amazon Bedrock Managed Knowledge Base. Unlike most other Retrievers, it doesn't need a Haystack Document Store or an Embedder: indexing and embedding are handled entirely by AWS, and the component only needs a text `query` to search the Knowledge Base. +`AmazonBedrockKnowledgeBaseRetriever` retrieves Documents from an Amazon Bedrock Managed Knowledge Base. Unlike most other Retrievers, it doesn't need a Haystack Document Store or an Embedder: indexing and embedding are handled entirely by AWS, and the component only needs a text `query` to search the Knowledge Base. By default, the Retriever tries the Agentic Retrieve API first and falls back to the standard Retrieve API if agentic retrieval isn't available for the configured Knowledge Base. You can control this behavior with the `use_agentic_retrieval` init parameter, or the `USE_AGENTIC_RETRIEVAL` environment variable. @@ -55,10 +55,10 @@ You also need an existing [Amazon Bedrock Knowledge Base](https://docs.aws.amazo from haystack.utils import Secret from haystack_integrations.components.retrievers.amazon_bedrock import ( - BedrockKnowledgeBaseRetriever, + AmazonBedrockKnowledgeBaseRetriever, ) -retriever = BedrockKnowledgeBaseRetriever( +retriever = AmazonBedrockKnowledgeBaseRetriever( knowledge_base_id="ABCDEFGHIJ", aws_region_name=Secret.from_token("eu-central-1"), ) @@ -82,7 +82,7 @@ from haystack_integrations.components.generators.amazon_bedrock import ( AmazonBedrockChatGenerator, ) from haystack_integrations.components.retrievers.amazon_bedrock import ( - BedrockKnowledgeBaseRetriever, + AmazonBedrockKnowledgeBaseRetriever, ) template = [ @@ -102,7 +102,7 @@ template = [ rag_pipeline = Pipeline() rag_pipeline.add_component( "retriever", - BedrockKnowledgeBaseRetriever( + AmazonBedrockKnowledgeBaseRetriever( knowledge_base_id="ABCDEFGHIJ", aws_region_name=Secret.from_token("eu-central-1"), ), From 0876f9fb0e1c4d218676400d816dc0bc67910585 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 27 Aug 2026 14:40:57 +0200 Subject: [PATCH 3/4] adding sideber link + docs to 3.1 --- docs-website/sidebars.js | 1 + .../version-3.1/pipeline-components/retrievers.mdx | 1 + docs-website/versioned_sidebars/version-3.1-sidebars.json | 1 + 3 files changed, 3 insertions(+) diff --git a/docs-website/sidebars.js b/docs-website/sidebars.js index 8cbe2f4314f..936e5ccc647 100644 --- a/docs-website/sidebars.js +++ b/docs-website/sidebars.js @@ -603,6 +603,7 @@ export default { items: [ 'pipeline-components/retrievers/alloydbembeddingretriever', 'pipeline-components/retrievers/alloydbkeywordretriever', + 'pipeline-components/retrievers/amazonbedrockknowledgebaseretriever', 'pipeline-components/retrievers/arangoembeddingretriever', 'pipeline-components/retrievers/arcadedbembeddingretriever', 'pipeline-components/retrievers/astraretriever', diff --git a/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers.mdx b/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers.mdx index 122bdd046c0..195f0fc421e 100644 --- a/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers.mdx +++ b/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers.mdx @@ -155,6 +155,7 @@ For details on how to initialize and use a Retriever in a pipeline, see the docu | --- | --- | | [AlloyDBEmbeddingRetriever](retrievers/alloydbembeddingretriever.mdx) | An embedding-based Retriever compatible with the AlloyDB Document Store. | | [AlloyDBKeywordRetriever](retrievers/alloydbkeywordretriever.mdx) | A keyword-based Retriever that fetches Documents matching a query from the AlloyDB Document Store. | +| [AmazonBedrockKnowledgeBaseRetriever](retrievers/amazonbedrockknowledgebaseretriever.mdx) | Retrieves documents from an Amazon Bedrock Managed Knowledge Base. | | [ArangoEmbeddingRetriever](retrievers/arangoembeddingretriever.mdx) | An embedding-based Retriever compatible with the ArangoDB Document Store. | | [ArcadeDBEmbeddingRetriever](retrievers/arcadedbembeddingretriever.mdx) | An embedding-based Retriever compatible with the ArcadeDB Document Store. | | [AstraEmbeddingRetriever](retrievers/astraretriever.mdx) | An embedding-based Retriever compatible with the AstraDocumentStore. | diff --git a/docs-website/versioned_sidebars/version-3.1-sidebars.json b/docs-website/versioned_sidebars/version-3.1-sidebars.json index 28fe5f27451..5108d4457d0 100644 --- a/docs-website/versioned_sidebars/version-3.1-sidebars.json +++ b/docs-website/versioned_sidebars/version-3.1-sidebars.json @@ -597,6 +597,7 @@ "items": [ "pipeline-components/retrievers/alloydbembeddingretriever", "pipeline-components/retrievers/alloydbkeywordretriever", + "pipeline-components/retrievers/amazonbedrockknowledgebaseretriever", "pipeline-components/retrievers/arangoembeddingretriever", "pipeline-components/retrievers/arcadedbembeddingretriever", "pipeline-components/retrievers/astraretriever", From a89a1c4ee2a8011703bae61b6553668d4493fadc Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 27 Aug 2026 14:48:27 +0200 Subject: [PATCH 4/4] adding missing file --- .../amazonbedrockknowledgebaseretriever.mdx | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 docs-website/versioned_docs/version-3.1/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx diff --git a/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx b/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx new file mode 100644 index 00000000000..483689b88ad --- /dev/null +++ b/docs-website/versioned_docs/version-3.1/pipeline-components/retrievers/amazonbedrockknowledgebaseretriever.mdx @@ -0,0 +1,129 @@ +--- +title: "AmazonBedrockKnowledgeBaseRetriever" +id: amazonbedrockknowledgebaseretriever +slug: "/amazonbedrockknowledgebaseretriever" +description: "Retrieves documents from an Amazon Bedrock Managed Knowledge Base." +--- + +# AmazonBedrockKnowledgeBaseRetriever + +Retrieves documents from an Amazon Bedrock Managed Knowledge Base. + +
+ +| | | +| --- | --- | +| **Most common position in a pipeline** | 1. Before a [`ChatPromptBuilder`](../builders/chatpromptbuilder.mdx) in a RAG pipeline 2. The last component in the semantic search pipeline | +| **Mandatory init variables** | `knowledge_base_id`: The ID of the Amazon Bedrock Knowledge Base. Falls back to the `AWS_KNOWLEDGE_BASE_ID` env var. | +| **Optional init variables** | `aws_access_key_id`: AWS access key ID. Can be set with `AWS_ACCESS_KEY_ID` env var.

`aws_secret_access_key`: AWS secret access key. Can be set with `AWS_SECRET_ACCESS_KEY` env var.

`aws_session_token`: AWS session token. Can be set with `AWS_SESSION_TOKEN` env var.

`aws_region_name`: AWS region name. Can be set with `AWS_DEFAULT_REGION` env var.

`aws_profile_name`: AWS profile name. Can be set with `AWS_PROFILE` env var.

`number_of_results`: Maximum number of results to return. Defaults to `5`.

`use_agentic_retrieval`: If `True`, tries the Agentic Retrieve API before falling back to the standard Retrieve API. Defaults to the `USE_AGENTIC_RETRIEVAL` env var, or `True`. | +| **Mandatory run variables** | `query`: A string | +| **Optional run variables** | `top_k`: Maximum number of results to return. Overrides `number_of_results` if provided. | +| **Output variables** | `documents`: A list of Documents | +| **API reference** | [Amazon Bedrock](/reference/integrations-amazon-bedrock) | +| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/amazon_bedrock/ | +| **Package name** | `amazon-bedrock-haystack` | + +
+ +## Overview + +`AmazonBedrockKnowledgeBaseRetriever` retrieves Documents from an Amazon Bedrock Managed Knowledge Base. Unlike most other Retrievers, it doesn't need a Haystack Document Store or an Embedder: indexing and embedding are handled entirely by AWS, and the component only needs a text `query` to search the Knowledge Base. + +By default, the Retriever tries the Agentic Retrieve API first and falls back to the standard Retrieve API if agentic retrieval isn't available for the configured Knowledge Base. You can control this behavior with the `use_agentic_retrieval` init parameter, or the `USE_AGENTIC_RETRIEVAL` environment variable. + +Each returned Document includes a `score` and metadata about where it came from: `source` (the S3, web, Confluence, Salesforce, SharePoint, or custom document location of the underlying content), `knowledge_base_id`, and `knowledge_base_type`. + +This component uses AWS for authentication. You can use the AWS CLI to authenticate through your IAM. For more information on setting up an IAM identity-based policy, see the [official documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html). + +If the AWS environment is configured correctly, the AWS credentials are not required, as they're loaded automatically from the environment or the AWS configuration file. If the AWS environment is not configured, set `aws_access_key_id`, `aws_secret_access_key`, and `aws_region_name` as environment variables or pass them as [Secret](../../concepts/secret-management.mdx) arguments. + +## Installation + +Install the Amazon Bedrock integration: + +```bash +pip install amazon-bedrock-haystack +``` + +You also need an existing [Amazon Bedrock Knowledge Base](https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base.html) with documents already ingested. Set its ID as the `AWS_KNOWLEDGE_BASE_ID` environment variable, or pass it directly as the `knowledge_base_id` init parameter. + +## Usage + +### On its own + +```python +from haystack.utils import Secret + +from haystack_integrations.components.retrievers.amazon_bedrock import ( + AmazonBedrockKnowledgeBaseRetriever, +) + +retriever = AmazonBedrockKnowledgeBaseRetriever( + knowledge_base_id="ABCDEFGHIJ", + aws_region_name=Secret.from_token("eu-central-1"), +) + +result = retriever.run(query="What are the benefits of managed knowledge bases?") +for doc in result["documents"]: + print(doc.content) + print(doc.meta["source"]) + print(doc.score) +``` + +### In a RAG pipeline + +```python +from haystack import Pipeline +from haystack.components.builders import ChatPromptBuilder +from haystack.dataclasses import ChatMessage +from haystack.utils import Secret + +from haystack_integrations.components.generators.amazon_bedrock import ( + AmazonBedrockChatGenerator, +) +from haystack_integrations.components.retrievers.amazon_bedrock import ( + AmazonBedrockKnowledgeBaseRetriever, +) + +template = [ + ChatMessage.from_user( + """ + Given these documents, answer the question.\nDocuments: + {% for doc in documents %} + {{ doc.content }} + {% endfor %} + + \nQuestion: {{question}} + \nAnswer: + """, + ), +] + +rag_pipeline = Pipeline() +rag_pipeline.add_component( + "retriever", + AmazonBedrockKnowledgeBaseRetriever( + knowledge_base_id="ABCDEFGHIJ", + aws_region_name=Secret.from_token("eu-central-1"), + ), +) +rag_pipeline.add_component( + "prompt_builder", + ChatPromptBuilder(template=template, required_variables="*"), +) +rag_pipeline.add_component( + "llm", AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6") +) + +rag_pipeline.connect("retriever.documents", "prompt_builder.documents") +rag_pipeline.connect("prompt_builder.prompt", "llm.messages") + +question = "What are the benefits of managed knowledge bases?" +result = rag_pipeline.run( + { + "retriever": {"query": question}, + "prompt_builder": {"question": question}, + }, +) +print(result["llm"]["replies"][0].text) +```