cosSimilarity.php
Table of Contents
Functions
- cosSimilarity() : string
- Return the cosine similarity between two vectors.
Functions
cosSimilarity()
Return the cosine similarity between two vectors.
cosSimilarity(string|int $x, string|int $y) : string
This helper wraps the ArangoDB AQL function COSINE_SIMILARITY(x, y) which
calculates the cosine similarity between two vectors. Cosine similarity
measures the cosine of the angle between two vectors, ranging from -1 to 1.
Example AQL usage:
COSINE_SIMILARITY([1, 0], [1, 0]) // returns 1 (identical vectors)
COSINE_SIMILARITY([1, 0], [0, 1]) // returns 0 (orthogonal vectors)
COSINE_SIMILARITY([1, 0], [-1, 0]) // returns -1 (opposite vectors)
Parameters
- $x : string|int
-
First input array (vector).
- $y : string|int
-
Second input array (vector).
Tags
Return values
string —The formatted AQL expression.