Class for interacting with Amazon Bedrock Knowledge Bases, a RAG workflow oriented service provided by AWS. Extends the BaseRetriever class.

const retriever = new AmazonKnowledgeBaseRetriever({
topK: 10,
knowledgeBaseId: "YOUR_KNOWLEDGE_BASE_ID",
region: "us-east-2",
clientOptions: {
credentials: {
accessKeyId: "YOUR_ACCESS_KEY_ID",
secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
},
},
});

const docs = await retriever.getRelevantDocuments("How are clouds formed?");

Hierarchy (view full)

  • Toolkit
    • AmazonKnowledgeBaseRetriever

Constructors

Properties

bedrockAgentRuntimeClient: BedrockAgentRuntimeClient
knowledgeBaseId: string
topK: number
filter?: RetrievalFilter
overrideSearchType?: SearchType

Methods

  • Cleans the result text by replacing sequences of whitespace with a single space and removing ellipses.

    Parameters

    • resText: string

      The result text to clean.

    Returns string

    The cleaned result text.

  • Parameters

    • query: string
    • topK: number
    • Optionalfilter: RetrievalFilter
    • OptionaloverrideSearchType: SearchType

    Returns Promise<Document[]>