Skip to content

KnowledgeBase

Source: src/AWS/Bedrock/KnowledgeBase.ts

An Amazon Bedrock knowledge base — a managed RAG index that embeds source documents into a vector store for retrieval.

KnowledgeBase owns the index configuration; attach one or more DataSources (e.g. an S3 bucket) to feed it documents, then trigger ingestion. Query it at runtime with the Retrieve and RetrieveAndGenerate bindings, or attach it to an Agent.

The roleArn must grant Bedrock access to the embedding model, the vector store, and the source data. The vector store (storageConfiguration) must already exist — provision an OpenSearch Serverless collection (with a vector index) or another supported store first.

import * as Bedrock from "alchemy/AWS/Bedrock";
const kb = yield* Bedrock.KnowledgeBase("docs", {
roleArn: role.roleArn,
knowledgeBaseConfiguration: {
type: "VECTOR",
vectorKnowledgeBaseConfiguration: {
embeddingModelArn:
"arn:aws:bedrock:us-west-2::foundation-model/amazon.titan-embed-text-v2:0",
},
},
storageConfiguration: {
type: "OPENSEARCH_SERVERLESS",
opensearchServerlessConfiguration: {
collectionArn: collection.arn,
vectorIndexName: "bedrock-index",
fieldMapping: {
vectorField: "bedrock-vector",
textField: "bedrock-text",
metadataField: "bedrock-metadata",
},
},
},
});