API
Image Embeddings
POST /api/ai/embeddings — generate a CLIP vector embedding for an image or text
Image Embeddings
Generate a CLIP vector embedding for an image or text string.
SDK equivalent: sdk.embed() + sdk.similarity() — see Vision SDK
Endpoint
POST /api/ai/embeddingsRequest
curl -X POST https://lab.coreviz.io/api/ai/embeddings \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"input": "https://example.com/photo.jpg",
"type": "image"
}'Request Body
| Field | Type | Required | Description |
|---|---|---|---|
input | string | Yes | Image URL, base64 data URI, or text string |
type | string | No | "image" or "text". Auto-detected if omitted |
Response
{
"embedding": [0.123, -0.456, 0.789, ...]
}| Field | Type | Description |
|---|---|---|
embedding | number[] | CLIP vector (512 or 768 dimensions) |
Computing Similarity
Use cosine similarity to compare two embeddings. The SDK's sdk.similarity(a, b) method handles this:
function cosineSimilarity(a, b) {
const dot = a.reduce((sum, ai, i) => sum + ai * b[i], 0);
const magA = Math.sqrt(a.reduce((sum, ai) => sum + ai * ai, 0));
const magB = Math.sqrt(b.reduce((sum, bi) => sum + bi * bi, 0));
return dot / (magA * magB);
}