Embeddings

Vector similarity with OpenAI and Voyage AI

Embeddings

Echo PDK includes built-in embedding support for computing vector similarity between texts. Supported providers: OpenAI and Voyage AI.

Creating an Embedding Provider

import { createEmbeddingProvider } from "@goreal-ai/echo-pdk"

const openai = createEmbeddingProvider({
  type: "openai",
  apiKey: "sk-...",
  model: "text-embedding-3-small"   // default
})

const voyage = createEmbeddingProvider({
  type: "voyage",
  apiKey: "pa-...",
  model: "voyage-3-lite"            // default
})

Generating Embeddings

const vectors = await provider.embed([
  "The cat sat on the mat",
  "A feline rested on the rug"
])
// vectors[0] = [0.012, -0.034, 0.056, ...]  (1536 dimensions)
// vectors[1] = [0.011, -0.031, 0.049, ...]

Cosine Similarity

import { cosineSimilarity } from "@goreal-ai/echo-pdk"

const score = cosineSimilarity(vectors[0], vectors[1])
// 0.87 — high similarity
// Range: -1.0 to 1.0
//  1.0 = identical
//  0.0 = orthogonal (unrelated)
// -1.0 = opposite

Provider Shortcut

AI providers expose a similarity() method that handles embedding + comparison in one call:

const score = await provider.similarity(
  "The cat sat on the mat",
  "A feline rested on the rug"
)
// 0.87

Use with Eval

Embeddings power the similar_to assertion in eval suites:

yaml
# In your .eval file
tests:
  - name: "Response matches golden"
    expect_llm:
      - similar_to:
          dataset: customer_feedback
          threshold: 0.85