Documentation

Embeddings

Bytecompute's Embeddings API lets you turn some input text (the input) into an array of numbers (the embedding). The resulting embedding can be compared against other embeddings to determine how closely related the two input strings are.

Embeddings from large datasets can be stored in vector databases for later retrieval or comparison. Common use cases for embeddings are search, classification, and recommendations. They're also used for building Retrieval Augmented Generation (RAG) applications.

Generating a single embedding

Use client.embeddings.create to generate an embedding for some input text, passing in a model name and input string:

Python Copy
import os
from bytecompute import bytecompute

client = bytecompute()

response = client.embeddings.create(
  model = "BAAI/bge-base-en-v1.5",
  input = "Our solar system orbits the Milky Way galaxy at about 515,000 mph"
)
TypeScript Copy
import bytecompute from "bytecompute-ai";

const bytecompute = new bytecompute();

const response = await client.embeddings.create({
  model: 'BAAI/bge-base-en-v1.5',
  input: 'Our solar system orbits the Milky Way galaxy at about 515,000 mph',
});
SH Copy
curl -X POST https://api.bytecompute.xyz/v1/embeddings \
     -H "Authorization: Bearer $bytecompute_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
         "input": "Our solar system orbits the Milky Way galaxy at about 515,000 mph.",
         "model": "BAAI/bge-base-en-v1.5"
        }'

The response will be an object that contains the embedding under the data key, as well as some metadata:

JSON Copy
{
  model: 'BAAI/bge-base-en-v1.5',
  object: 'list',
  data: [
    {
      index: 0,
      object: 'embedding',
      embedding: [0.2633975, 0.13856208, ..., 0.04331574],
    },
  ],
};

Generating multiple embeddings

You can also pass an array of input strings to the input option:

Python Copy
import os
from bytecompute import bytecompute

client = bytecompute()

response = client.embeddings.create(
  model = "BAAI/bge-base-en-v1.5",
  input = [
    "Our solar system orbits the Milky Way galaxy at about 515,000 mph",
    "Jupiter's Great Red Spot is a storm that has been raging for at least 350 years."
  ]
)
HTTP Copy
curl -X POST https://api.bytecompute.xyz/v1/embeddings \
     -H "Authorization: Bearer $bytecompute_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
         "model": "BAAI/bge-base-en-v1.5",
         "input": [
            "Our solar system orbits the Milky Way galaxy at about 515,000 mph",
            "Jupiter'\''s Great Red Spot is a storm that has been raging for at least 350 years."
         ]
        }'

The response.data key will contain an array of objects for each input string you provide:

JSON Copy
{
  model: 'BAAI/bge-base-en-v1.5',
  object: 'list',
  data: [
    {
      index: 0,
      object: 'embedding',
      embedding: [0.2633975, 0.13856208, ..., 0.04331574],
    },
    {
      index: 1,
      object: 'embedding',
      embedding: [-0.14496337, 0.21044481, ..., -0.16187587]
    },
  ],
};