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

Example

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

  • BaseRetriever
    • AmazonKendraRetriever

Constructors

Properties

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

Methods

  • Combines title and excerpt into a single string.

    Parameters

    • Optional title: string

      The title of the document.

    • Optional excerpt: string

      An excerpt from the document.

    Returns string

    A single string combining the title and excerpt.

  • Converts a QueryResultItem object into a Document object.

    Parameters

    • item: QueryResultItem

      The QueryResultItem object to convert.

    Returns Document<{
        document_attributes: {
            [key: string]: unknown;
        };
        excerpt: string;
        source: undefined | string;
        title: string;
    }>

    A Document object.

  • Converts a RetrieveResultItem object into a Document object.

    Parameters

    • item: RetrieveResultItem

      The RetrieveResultItem object to convert.

    Returns Document<{
        document_attributes: {
            [key: string]: unknown;
        };
        excerpt: string;
        source: undefined | string;
        title: string;
    }>

    A Document object.

  • 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

    • Optional documentAttributes: 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 Document<{
        document_attributes: {
            [key: string]: unknown;
        };
        excerpt: string;
        source: undefined | string;
        title: string;
    }>[]

    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<Record<string, any>>[]

    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.

    • Optional attributeFilter: AttributeFilter

      Optional filter to apply when retrieving documents.

    Returns Promise<Document<Record<string, any>>[] | Document<{
        document_attributes: {
            [key: string]: unknown;
        };
        excerpt: string;
        source: undefined | string;
        title: string;
    }>[]>

    A Promise that resolves to an array of Document objects.

Generated using TypeDoc