Embeddings

An embedding is a list of numbers that captures the meaning of a piece of text. Texts that mean similar things land near each other in vector space, which is what makes semantic search, retrieval-augmented generation (RAG), deduplication, clustering, and classification work.

Embed some text

Pass a single string or an array of strings as input. You get back one vector per input, in the same order. Embed your documents once and store the vectors; at query time, embed the query and find the nearest stored vectors.

from pendra import Pendra

client = Pendra()
result = client.embeddings.create(
    model="embeddinggemma:300m",
    input=["the quick brown fox", "jumps over the lazy dog"],
)
for item in result.data:
    print(item.embedding)
Response
[ 0.0131, -0.0442,  0.0921, … ]   # "the quick brown fox"
[ 0.0204, -0.0118,  0.0815, … ]   # "jumps over the lazy dog"

One vector per input — two strings in, two vectors out, in the same order. Each is truncated here (…); a full vector has hundreds or thousands of dimensions, depending on the model.

Queries and documents

Many retrieval models are trained to read a search query and the text being searched slightly differently. Pendra handles that for you: tell it which one you are sending with input_type, and it formats the text the way the model expects.

  • document (the default): text you store and search over, and anything you compare with other text of the same kind.
  • query: a search, question or prompt you match against stored documents.
  • none: embed the text exactly as you sent it.
# Your documents, embedded once and stored. "document" is the default,
# so input_type can be left out here.
docs = client.embeddings.create(
    model="qwen3-embedding:4b",
    input=["Vaccines train the immune system to recognise a pathogen.",
           "The recipe calls for two cups of flour."],
)

# A search against them.
query = client.embeddings.create(
    model="qwen3-embedding:4b",
    input="How do vaccines work?",
    input_type="query",
)

If you leave input_type out, everything is embedded as a document. That is right for comparing two pieces of text, and documents you index before you start labelling still match once you send your searches as query. Use the same input_type for everything you store, and re-embed stored vectors if you change it.

Text you have already formatted yourself, such as one starting with query: for a model that uses that label, is not labelled a second time. Use none when you format text in your own way and want it embedded unchanged. The few extra tokens a label adds are counted in usage.prompt_tokens. A worker running an older release ignores input_type and embeds the text as sent.

Choosing a model

Pendra ships several embedding models — Qwen3-Embedding (0.6B/4B/8B), EmbeddingGemma, and BGE-M3 among them. Dimensionality and similarity behaviour differ per model, so pick one and embed your whole corpus with it consistently. Browse the options at /models?type=embedding.

Batching

Embedding many strings at once is far faster than one request each. Send a few hundred per request rather than one huge batch — a single request should complete quickly (it can run up to ~30 minutes before timing out). For big wire payloads, set encoding_format: "base64" to shrink the response.

For the full request and response shape, see the Embeddings API reference.