Embedding Similarity
Vector SimilarityOverview
Calculate similarity between embedding vectors using various metrics. Support for cosine similarity, euclidean distance, dot product, and more.

Supported Metrics
- Cosine Similarity
- Euclidean Distance
- Dot Product
- Manhattan Distance
Key Features
- Multiple metrics
- Batch comparison
- Normalized scores
- Dimension validation
Configuration
Required Parameters
vectors
Array of embedding vectorsmetric
Similarity metric to use
Example Usage
// Calculate cosine similarity const cosineSim = new EmbeddingSimilarity({ metric: "cosine" }); // Compare two vectors const result = await cosineSim.compare({ vector1: [0.1, 0.2, 0.3], vector2: [0.2, 0.3, 0.4] }); // Batch comparison const batchResult = await cosineSim.compareBatch({ sourceVector: [0.1, 0.2, 0.3], targetVectors: [ [0.2, 0.3, 0.4], [0.3, 0.4, 0.5], [0.4, 0.5, 0.6] ] }); // Using different metrics const euclideanSim = new EmbeddingSimilarity({ metric: "euclidean" }); const dotProductSim = new EmbeddingSimilarity({ metric: "dot-product" });
Best Practices
- Normalize vectors when needed
- Choose appropriate metric
- Validate vector dimensions
- Handle edge cases
Metric Selection Tips
- Cosine for direction similarity
- Euclidean for absolute distance
- Dot product for quick comparison
Response Format
{ "similarity": { "score": number, "normalized_score": number, "metric": string }, "metadata": { "vector_dimensions": number, "comparison_time": number }, "status": { "success": boolean, "error": string | null } }