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
modelid. For generation use a provider-backed embeddings id or the built-intext.hash_embedding_v1; for scoring useembeddings.cosine_similarity(alsoembeddings.euclidean_distanceorembeddings.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.
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
Next steps
Last updated
Was this helpful?