For the complete documentation index, see llms.txt. This page is also available as Markdown.

Generate embeddings

Generate text embeddings, score two vectors with a similarity metric, and rerank candidate documents over the Algenta LLM API — from curl, Python, TypeScript, or the CLI.

The Algenta LLM API has three vector routes. POST /v1/embeddings turns text into vectors. POST /v1/embeddings/similarity scores two precomputed vectors. POST /v1/rerank orders candidate documents by their precomputed vectors against a query vector. This guide runs all three.

Only /v1/embeddings generates vectors from text — similarity and rerank operate on vectors you already have. Each route names a model id from LLM models & providers.

Before you start

You need:

  • An API key sent as Authorization: Bearer $ALGENTA_API_KEY. See Authentication.

  • $ALGENTA_API_URL — https://api.algenta.ai (hosted) or your engine, e.g. http://localhost:8000.

  • A model id. For generation use a provider-backed embeddings id or the built-in text.hash_embedding_v1; for scoring use embeddings.cosine_similarity (also embeddings.euclidean_distance or embeddings.manhattan_distance).

Embed text

input is a single string or a list of strings. Each returned vector carries its index and token_count.

curl -sS -X POST "$ALGENTA_API_URL/v1/embeddings" \
  -H "Authorization: Bearer $ALGENTA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "provider.openai:text-embedding-3-small",
    "input": ["first document", "second document"]
  }'
import os
from decision_engine import AlgentaClient

client = AlgentaClient(
    api_key=os.environ["ALGENTA_API_KEY"],
    base_url=os.environ.get("ALGENTA_API_URL", "https://api.algenta.ai"),
)

result = client.embeddings(
    ["first document", "second document"],
    model="provider.openai:text-embedding-3-small",
)
print(len(result.data), "vectors")
import { AlgentaClient } from "algenta-sdk";

const client = new AlgentaClient({
  apiKey: process.env.ALGENTA_API_KEY,
  baseUrl: process.env.ALGENTA_API_URL ?? "https://api.algenta.ai",
});

const result = await client.embeddings({
  model: "provider.openai:text-embedding-3-small",
  input: ["first document", "second document"],
});
console.log(result.data.length, "vectors");

The 200 response is a list of embedding vectors plus usage.

The dimensions field (default 64) sets the output width of the built-in text.hash_embedding_v1 encoder. Provider-backed models return their own native dimensionality.

Score two vectors

POST /v1/embeddings/similarity scores two vectors you supply as left and right. It does not generate embeddings. The metric comes from the model: embeddings.cosine_similarity, embeddings.euclidean_distance, or embeddings.manhattan_distance.

The 200 response is { model, similarity_metric, score, dimension }.

Rerank documents

POST /v1/rerank orders candidate documents by their precomputed embeddings against a query_embedding. Each document needs an id and embedding, with optional text and metadata returned unchanged. top_n (optional) limits how many ranked rows come back.

The 200 response lists ranked rows in order, plus counts.

Troubleshooting

404 model_not_supported

The model id is not in GET /v1/models. Copy an exact id from the catalog. For a provider embeddings model, confirm the backend is configured and its key is present. Note that some backends serve chat only — see the capability table in LLM models & providers.

422 invalid_embedding_dimensions or model_capability_unsupported

invalid_embedding_dimensions means left and right (or a document embedding and the query embedding) are not the same length — rerank and similarity compare vectors of equal width. model_capability_unsupported means the model does not support this route; check the descriptor's capabilities.

429, 503, or 504

429 is a rate limit or provider rate limit; back off and retry. 503 (backend_unavailable) and 504 (provider_timeout) come from the upstream provider. Error bodies follow { "error": { "code", "message", "details", "request_id" } }; see Error codes.

Next steps

Last updated

Was this helpful?