0

Create an Embed Job

by
Published Apr 8, 2025

This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings.

Script cohere Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Cohere = {
3
  apiKey: string;
4
};
5
/**
6
 * Create an Embed Job
7
 * This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings.
8
 */
9
export async function main(
10
  auth: Cohere,
11
  body: {
12
    model: string;
13
    dataset_id: string;
14
    input_type:
15
      | "search_document"
16
      | "search_query"
17
      | "classification"
18
      | "clustering"
19
      | "image";
20
    name?: string;
21
    embedding_types?: "float" | "int8" | "uint8" | "binary" | "ubinary"[];
22
    truncate?: "START" | "END";
23
  },
24
) {
25
  const url = new URL(`https://api.cohere.com/v1/embed-jobs`);
26

27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.apiKey,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41