Class for generating embeddings using the TogetherAI API. Extends the Embeddings class and implements TogetherAIEmbeddingsParams.

Example

const embeddings = new TogetherAIEmbeddings({
apiKey: process.env.TOGETHER_AI_API_KEY, // Default value
model: "togethercomputer/m2-bert-80M-8k-retrieval", // Default value
});
const res = await embeddings.embedQuery(
"What would be a good company name a company that makes colorful socks?"
);

Hierarchy

Implements

Constructors

Properties

apiKey: string

The API key to use for the TogetherAI API.

Default

{process.env.TOGETHER_AI_API_KEY}
batchSize: number = 512

The maximum number of documents to embed in a single request.

Default

{512}
caller: AsyncCaller

The async caller should be used by subclasses to make any async calls, which will thus benefit from the concurrency and retry logic.

modelName: string = "togethercomputer/m2-bert-80M-8k-retrieval"

Model name to use

Default

{"togethercomputer/m2-bert-80M-8k-retrieval"}
stripNewLines: boolean = false

Whether to strip new lines from the input text. May not be suitable for all use cases.

Default

{false}
timeout?: number

Timeout to use when making requests to TogetherAI.

Default

{undefined}

Methods

  • Method to generate embeddings for an array of documents. Splits the documents into batches and makes requests to the TogetherAI API to generate embeddings.

    Parameters

    • texts: string[]

      Array of documents to generate embeddings for.

    Returns Promise<number[][]>

    Promise that resolves to a 2D array of embeddings for each document.

  • Method to generate an embedding for a single document. Calls the embeddingWithRetry method with the document as the input.

    Parameters

    • text: string

      Document to generate an embedding for.

    Returns Promise<number[]>

    Promise that resolves to an embedding for the document.

Generated using TypeDoc