A class for generating embeddings using the Cohere API.

Hierarchy (view full)

Implements

Constructors

Properties

batchSize: number = 48

The maximum number of documents to embed in a single request. This is limited by the Cohere API to a maximum of 96.

inputType: undefined | string

Specifies the type of input you're giving to the model. Not required for older versions of the embedding models (i.e. anything lower than v3), but is required for more recent versions (i.e. anything bigger than v2).

  • search_document - Use this when you encode documents for embeddings that you store in a vector database for search use-cases.
  • search_query - Use this when you query your vector DB to find relevant documents.
  • classification - Use this when you use the embeddings as an input to a text classifier.
  • clustering - Use this when you want to cluster the embeddings.
model: string = "small"

Methods

  • Generates embeddings for an array of texts.

    Parameters

    • texts: string[]

      An array of strings to generate embeddings for.

    Returns Promise<number[][]>

    A Promise that resolves to an array of embeddings.

  • Generates an embedding for a single text.

    Parameters

    • text: string

      A string to generate an embedding for.

    Returns Promise<number[]>

    A Promise that resolves to an array of numbers representing the embedding.