Class for interacting with Amazon Kendra, an intelligent search service provided by AWS. Extends the BaseRetriever class.

const retriever = new AmazonKendraRetriever({
topK: 10,
indexId: "YOUR_INDEX_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)

Constructors

Properties

indexId: string
kendraClient: KendraClient
topK: number
attributeFilter?: AttributeFilter

Methods

  • Combines title and excerpt into a single string.

    Parameters

    • Optionaltitle: string

      The title of the document.

    • Optionalexcerpt: string

      An excerpt from the document.

    Returns string

    A single string combining the title and excerpt.

  • Extracts the attribute value from a DocumentAttributeValue object.

    Parameters

    • value: DocumentAttributeValue

      The DocumentAttributeValue object to extract the value from.

    Returns
        | string
        | number
        | string[]
        | Date

    The extracted attribute value.

  • Extracts the attribute key-value pairs from an array of DocumentAttribute objects.

    Parameters

    • OptionaldocumentAttributes: DocumentAttribute[]

      The array of DocumentAttribute objects to extract the key-value pairs from.

    Returns {
        [key: string]: unknown;
    }

    An object containing the extracted attribute key-value pairs.

    • [key: string]: unknown
  • Extracts the top-k documents from a QueryCommandOutput object.

    Parameters

    • response: QueryCommandOutput

      The QueryCommandOutput object to extract the documents from.

    • pageSize: number

      The number of documents to extract.

    Returns any[]

    An array of Document objects.

  • Extracts the top-k documents from a RetrieveCommandOutput object.

    Parameters

    • response: RetrieveCommandOutput

      The RetrieveCommandOutput object to extract the documents from.

    • pageSize: number

      The number of documents to extract.

    Returns Document[]

    An array of Document objects.

  • Sends a retrieve or query request to Kendra and returns the top-k documents.

    Parameters

    • query: string

      The query to send to Kendra.

    • topK: number

      The number of top documents to return.

    • OptionalattributeFilter: AttributeFilter

      Optional filter to apply when retrieving documents.

    Returns Promise<Document[]>

    A Promise that resolves to an array of Document objects.