Skip to Content

Embeddings

Turn text into vectors with the OpenAI embeddings API, for search, retrieval, classification and clustering. The embedding models are a preview.

Munito AI turns text into vectors with an embedding model, in the request format of OpenAI's embeddings API. The embedding models are a preview. Munito AI can change or remove them without notice.

Models

ModelModel IDDimensionsContext
EmbeddingGemma 2google/embeddinggemma-2768, or 512, 256 and 1288,192 tokens
Harrier OSS v1 270Mmicrosoft/harrier-oss-v1-270m64032,768 tokens
  • Both models read text in many languages.
  • Munito AI serves the open weights of EmbeddingGemma 2 (Apache 2.0) and of Harrier OSS v1 270M (MIT).
  • EmbeddingGemma 2 takes text only on Munito AI. Images, audio and video are not available.
  • Munito AI serves both models in the EU. Use the global host, api.munito.ai, or the EU host, api.eu.munito.ai. See Regions.

Get access

  1. Write to support@munito.ai, or open Support in the console, with your organization and your use.
  2. Munito AI turns the preview on for your organization.
  3. The models then show on the Models page of your console and in GET /models.

Without access, a request for these models gets 404, as a request for an unknown model does.

Create embeddings

curl https://api.munito.ai/inference/v1/embeddings \
  -H "Authorization: Bearer $MUNITO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/embeddinggemma-2",
    "input": [
      "task: search result | query: Which city is the capital of France?",
      "title: none | text: Paris is the capital of France."
    ]
  }'

The answer has one vector for each text, in the order of the request:

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        0.0123,
        -0.0456,
        0.0789
      ]
    },
    {
      "object": "embedding",
      "index": 1,
      "embedding": [
        0.0234,
        -0.0345,
        0.0678
      ]
    }
  ],
  "model": "google/embeddinggemma-2",
  "usage": {
    "prompt_tokens": 31,
    "total_tokens": 31
  }
}

Each vector has a length of 1, so the dot product of two vectors is their cosine similarity.

Use the OpenAI Python client

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.munito.ai/inference/v1",
    api_key=os.environ["MUNITO_API_KEY"],
)
response = client.embeddings.create(
    model="google/embeddinggemma-2",
    input=[
        "task: search result | query: Which city is the capital of France?",
        "title: none | text: Paris is the capital of France.",
    ],
)
query, document = (item.embedding for item in response.data)
print(sum(a * b for a, b in zip(query, document)))

Use the OpenAI JavaScript client

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.munito.ai/inference/v1",
  apiKey: process.env.MUNITO_API_KEY,
});
const response = await client.embeddings.create({
  model: "google/embeddinggemma-2",
  input: ["title: none | text: Paris is the capital of France."],
});
console.log(response.data[0].embedding.length);

Fields

FieldValue
modelAn embedding model. Required.
inputOne text, or an array of 1 to 2,048 texts. Required.
encoding_formatfloat (the default) gives arrays of numbers. base64 gives the 32-bit floats as base64 text.
dimensionsA vector size of the model. Omit it for the full vector.
userAn identifier of your end user. Munito AI does not use it.

A request with another field gets 400, and the error names the field.

Tell the model the task

Each model gives better vectors when the text starts with the prefix of its task. You write the prefix into the text.

EmbeddingGemma 2. Put the query prefix on a query and the document prefix on a document:

UseQuery prefixDocument prefix
Searchtask: search result | query: title: none | text:
Question answeringtask: question answering | query: title: none | text:
Fact checkingtask: fact checking | query: title: none | text:
Code searchtask: code retrieval | query: title: none | text:
Classificationtask: classification | query: The same prefix as the other text
Clusteringtask: clustering | query: The same prefix as the other text
Sentence similaritytask: sentence similarity | query: The same prefix as the other text

For a document with a title, write the title in place of none.

Harrier OSS v1 270M. Put an instruction of one sentence on a query, and no prefix on a document:

Instruct: Given a web search query, retrieve relevant passages that answer the query
Query: Which city is the capital of France?

The model card of each model has the full list of its prefixes.

Shorter vectors

EmbeddingGemma 2 can return a shorter vector, which takes less storage and gives a small loss of quality.

  • Send dimensions with 512, 256 or 128. The model returns the first values of the vector, normalized again.
  • Use one size for the queries and the documents of an index.
  • Harrier OSS v1 270M has one size, 640. Another value of dimensions gets 400.

Limits

  • One request holds at most 2,048 texts and 1,200,000 characters. Send more texts in more requests.
  • A request with more than 64 texts can get 503 with the code server_busy while the API holds many large answers. Retry it after the time in Retry-After.
  • Each text must fit the context of the model. A longer text gets 400 with the code context_length_exceeded. Split a long document into parts.
  • Send text only. A token array gets 400, because each model has its own tokenizer.
  • The rate limits count requests and input tokens each minute. The Limits page of your console shows your numbers.

LangChain. OpenAIEmbeddings counts tokens with OpenAI's tokenizer and sends token arrays by default. Turn that off:

import os
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(
    model="google/embeddinggemma-2",
    base_url="https://api.munito.ai/inference/v1",
    api_key=os.environ["MUNITO_API_KEY"],
    check_embedding_ctx_length=False,
)

LangChain sends up to 1,000 texts in one request. If your texts are long, set a lower chunk_size.

Usage and price

  • Munito AI bills the input tokens of a request. An embedding has no output tokens.
  • Each embedding model costs $0.01 for each million input tokens in the standard tier, on the global host and on the EU host.
  • usage.prompt_tokens gives the tokens that Munito AI bills.
  • The flex and priority service tiers apply. Send the header munito-service-tier.

See the embeddings reference for each field of the request and of the answer.