Document compressor that uses Cohere Rerank API.

Hierarchy (view full)

Constructors

Properties

client: CohereClient
maxChunksPerDoc: undefined | number
model: undefined | string
topN: number = 3

Methods

  • Compress documents using Cohere's rerank API.

    Parameters

    • documents: DocumentInterface[]

      A sequence of documents to compress.

    • query: string

      The query to use for compressing the documents.

    Returns Promise<DocumentInterface[]>

    A sequence of compressed documents.

  • Returns an ordered list of documents ordered by their relevance to the provided query.

    Parameters

    • documents: any[]

      A list of documents as strings, DocumentInterfaces or objects with a pageContent key.

    • query: string

      The query to use for reranking the documents.

    • Optionaloptions: {
          maxChunksPerDoc?: number;
          model?: string;
          topN?: number;
      }
      • OptionalmaxChunksPerDoc?: number

        The maximum number of chunks per document.

      • Optionalmodel?: string

        The name of the model to use.

      • OptionaltopN?: number

        How many documents to return.

    Returns Promise<{
        index: number;
        relevanceScore: number;
    }[]>

    An ordered list of documents with relevance scores.