approxNearCosine.php
Table of Contents
Functions
- approxNearCosine() : string
- Return the approximate cosine similarity between two vectors, accelerated by a vector index.
Functions
approxNearCosine()
Return the approximate cosine similarity between two vectors, accelerated by a vector index.
approxNearCosine(string|int $x, string|int $y[, int|null $nProbe = null ]) : string
This helper wraps the ArangoDB AQL function APPROX_NEAR_COSINE(x, y).
One of the two operands must reference a document attribute covered by a
VectorIndex created with the
"cosine" metric; the other is the query vector. The closer the returned
value is to 1, the more similar the vectors are.
Because higher is more similar, you sort in descending order to get the
nearest neighbours first — which is exactly what aqlVectorSearch()
does for the cosine metric.
Requires ArangoDB started with the experimental vector index feature.
Example AQL usage:
FOR doc IN items
SORT APPROX_NEAR_COSINE(doc.embedding, @query) DESC
LIMIT 10
RETURN doc
Parameters
- $x : string|int
-
First operand — the stored attribute or the query vector.
- $y : string|int
-
Second operand — the query vector or the stored attribute.
- $nProbe : int|null = null
-
Optional number of neighbouring centroids to probe (higher = more accurate, slower).
Tags
Return values
string —The formatted AQL expression.