Compare vectors and perform semantic search to find related content.
Computes cosine similarity between two vectors. Returns a value between -1 and 1, where 1 means identical direction.
| Syntax | ai.cosine(<vector1>, <vector2>) | ||
| Arguments | Name | Type | Description |
<vector1> | VECTOR | The first vector | |
<vector2> | VECTOR | The second vector; must have the same dimension as <vector1> | |
| Return Type | FLOAT | ||
GQLLET v1 = ai.vector([1.0, 0.0, 0.0]) LET v2 = ai.vector([1.0, 1.0, 0.0]) RETURN ai.cosine(v1, v2)
Result: 0.7071067690849304
Computes Euclidean distance between two vectors. Lower values indicate more similarity.
| Syntax | ai.euclidean(<vector1>, <vector2>) | ||
| Arguments | Name | Type | Description |
<vector1> | VECTOR | The first vector | |
<vector2> | VECTOR | The second vector; must have the same dimension as <vector1> | |
| Return Type | FLOAT | ||
GQLLET v1 = ai.vector([1.0, 0.0]) LET v2 = ai.vector([0.0, 1.0]) RETURN ai.euclidean(v1, v2)
Result: 1.4142135381698608
Computes the dot product of two vectors.
| Syntax | ai.dot(<vector1>, <vector2>) | ||
| Arguments | Name | Type | Description |
<vector1> | VECTOR | The first vector | |
<vector2> | VECTOR | The second vector; must have the same dimension as <vector1> | |
| Return Type | FLOAT | ||
GQLLET v1 = ai.vector([1.0, 2.0, 3.0]) LET v2 = ai.vector([4.0, 5.0, 6.0]) RETURN ai.dot(v1, v2)
Result: 32
Computes the cosine distance between two vectors (1 - cosine similarity). Lower values indicate more similarity.
| Syntax | ai.distance(<vector1>, <vector2>) | ||
| Arguments | Name | Type | Description |
<vector1> | VECTOR | The first vector | |
<vector2> | VECTOR | The second vector; must have the same dimension as <vector1> | |
| Return Type | FLOAT | ||
GQLLET v1 = ai.vector([1.0, 0.0, 0.0]) LET v2 = ai.vector([1.0, 1.0, 0.0]) RETURN ai.distance(v1, v2)
Result: 0.2928932309150696
For large datasets, create a vector index for efficient approximate nearest neighbor (ANN) search. See Vector Index for full syntax.
Create a vector index:
GQLCREATE VECTOR INDEX doc_search ON NODE Document (embedding) OPTIONS { dimensions: 1536, metric: "cosine" }
Find the k nearest neighbors using ORDER BY ... LIMIT. The optimizer automatically uses the vector index:
GQLLET query = ai.embed('how to model relationships in graphs') MATCH (d:Document) RETURN d.title, ai.cosine(d.embedding, query) AS similarity ORDER BY similarity DESC LIMIT 10
Find all vectors above a similarity threshold:
GQLLET query = ai.embed('cloud computing tutorial') MATCH (d:Document) WHERE ai.cosine(d.embedding, query) > 0.7 RETURN d.title, ai.cosine(d.embedding, query) AS relevance ORDER BY relevance DESC
Combine vector similarity with graph traversal and property filters:
GQLLET query = ai.embed('machine learning applications') MATCH (d:Document) WHERE ai.cosine(d.embedding, query) > 0.8 AND d.category = 'Technology' MATCH (d)-[:AUTHORED_BY]->(author:Person) RETURN d.title, ai.cosine(d.embedding, query) AS similarity, author.name ORDER BY similarity DESC LIMIT 5
Retrieve context for Retrieval Augmented Generation:
GQLLET query = ai.embed('How do I create a graph index?') MATCH (d:Document) RETURN d.content, ai.cosine(d.embedding, query) AS score ORDER BY score DESC LIMIT 3