Document compressor that uses Cohere Rerank API.

Hierarchy

  • BaseDocumentCompressor
    • CohereRerank

Constructors

Properties

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

Methods

  • Compress documents using Cohere's rerank API.

    Parameters

    • documents: DocumentInterface<Record<string, any>>[]

      A sequence of documents to compress.

    • query: string

      The query to use for compressing the documents.

    Returns Promise<DocumentInterface<Record<string, any>>[]>

    A sequence of compressed documents.

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

    Parameters

    • documents: (string | Record<string, string> | DocumentInterface<Record<string, 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.

  • Parameters

    • x: any

    Returns x is BaseDocumentCompressor