Similarity score

Supported in: Batch

Returns the similarity score of two embedding vectors.

Expression categories: Numeric

Declared arguments

  • Left embedded vector - The left embedded vector.
    Expression<T>
  • Right embedded vector - The right embedded vector.
    Expression<T>
  • Similarity metric - The similarity metric for comparing the left and right embeddings.
    Enum<Cosine Similarity, Dot Product, Euclidean Distance>

Type variable bounds: T accepts Embedded vector

Output type: Double

Examples

Example 1: Base case

Description: Cosine similarity of the Ada embeddings for the word 'palantir' and 'foundry'. Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: COSINE_SIMILARITY
leftEmbeddedVectorrightEmbeddedVectorOutput
[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...[ -0.0046147984, -0.014344796, -0.022795992, -0.035806388, -0.028467191, 0.026243191, -0.028161392, ...0.7814455755180517

Example 2: Base case

Description: Cosine similarity between the Ada embeddings for the word 'palantir'. Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: COSINE_SIMILARITY
leftEmbeddedVectorrightEmbeddedVectorOutput
[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...1.0

Example 3: Base case

Description: Dot product of the Ada embeddings for the word 'palantir' and 'foundry'. Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: DOT_PRODUCT
leftEmbeddedVectorrightEmbeddedVectorOutput
[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...[ -0.0046147984, -0.014344796, -0.022795992, -0.035806388, -0.028467191, 0.026243191, -0.028161392, ...0.7814455030932973

Example 4: Base case

Description: Dot product of the Ada embeddings for the word 'palantir'. Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: DOT_PRODUCT
leftEmbeddedVectorrightEmbeddedVectorOutput
[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...1.0

Example 5: Base case

Description: Euclidean distance between the Ada embeddings for the word 'palantir' and 'foundry'. Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: EUCLIDEAN_DISTANCE
leftEmbeddedVectorrightEmbeddedVectorOutput
[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...[ -0.0046147984, -0.014344796, -0.022795992, -0.035806388, -0.028467191, 0.026243191, -0.028161392, ...0.6611420486192364

Example 6: Base case

Description: Euclidean distance between the Ada embeddings for the word 'palantir'. Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: EUCLIDEAN_DISTANCE
leftEmbeddedVectorrightEmbeddedVectorOutput
[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...[ -0.019182289, -0.02127992, 0.009529043, -0.008066221, -0.0014429842, 0.019154688, -0.023556953, -0...0.0

Example 7: Null case

Description: Null inputs should have a null output Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: COSINE_SIMILARITY
leftEmbeddedVectorrightEmbeddedVectorOutput
nullnullnull

Example 8: Null case

Description: Null inputs should have a null output Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: DOT_PRODUCT
leftEmbeddedVectorrightEmbeddedVectorOutput
nullnullnull

Example 9: Null case

Description: Null inputs should have a null output Argument values:

  • Left embedded vector: leftEmbeddedVector
  • Right embedded vector: rightEmbeddedVector
  • Similarity metric: EUCLIDEAN_DISTANCE
leftEmbeddedVectorrightEmbeddedVectorOutput
nullnullnull