Embeddings

An embedding turns text into a list of numbers that captures its meaning. Texts that mean similar things get similar numbers, which is what powers semantic search, retrieval-augmented generation (RAG) and clustering.

Embed some text

Send one string or a list of them. You get one vector back for each, in the same order.

from pendra import Pendra

client = Pendra(api_key="pdr_sk_...")

result = client.embeddings.create(
    model="qwen3-embedding:4b",
    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"

Search your documents

Embed your documents once and store the vectors. To search, embed the question with input_type set to query, then find the stored vectors closest to it.

# Your documents, embedded once and stored
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",
)

Pendra formats each one the way the model expects. Text you send without an input_type is treated as a document. Use none to embed text exactly as you sent it.

Choosing a model

Pendra has several embedding models, including Qwen3 Embedding, EmbeddingGemma and BGE-M3, all listed in the models list. Vectors from different models can't be compared, so use the same model for everything you store.

Send a few hundred texts in each request. It's much faster than sending them one at a time.

For every field and response, see the Embeddings API reference.