Inspect, transform, and perform arithmetic operations on vectors, and manage vector indexes.
Returns the number of dimensions in a vector.
| Syntax | ai.dimension(<vector>) | ||
| Arguments | Name | Type | Description |
<vector> | VECTOR | A vector value | |
| Return Type | INT | ||
GQLLET v = ai.vector([3.0, 4.0]) RETURN ai.dimension(v)
Result: 2
Returns the magnitude (L2 norm) of a vector.
| Syntax | ai.magnitude(<vector>) | ||
| Arguments | Name | Type | Description |
<vector> | VECTOR | A vector value | |
| Return Type | FLOAT | ||
GQLLET v = ai.vector([3.0, 4.0]) RETURN ai.magnitude(v)
Result: 5
Normalizes a vector to a unit vector (magnitude of 1).
| Syntax | ai.normalize(<vector>) | ||
| Arguments | Name | Type | Description |
<vector> | VECTOR | A vector value | |
| Return Type | VECTOR | ||
GQLLET v = ai.vector([3.0, 4.0]) RETURN ai.normalize(v)
Result:
JSON{ "values": [ 0.6000000238418579, 0.800000011920929 ] }
Converts a vector to a list of numbers.
| Syntax | ai.toList(<vector>) | ||
| Arguments | Name | Type | Description |
<vector> | VECTOR | A vector value | |
| Return Type | LIST | ||
GQLLET embedding = ai.embed("Introduction to graph databases") RETURN ai.toList(embedding)
Result: [-0.0258026123046875, -0.0126800537109375, …, 0.0162200927734375, -0.017486572265625]
Adds two vectors element-wise.
| Syntax | ai.add(<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 | VECTOR | ||
GQLLET v1 = ai.vector([1.0, 2.0]) LET v2 = ai.vector([3.0, 4.0]) RETURN ai.toList(ai.add(v1, v2))
Result: [4, 6]
Subtracts the second vector from the first element-wise.
| Syntax | ai.subtract(<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 | VECTOR | ||
GQLLET v1 = ai.vector([5.0, 3.0]) LET v2 = ai.vector([1.0, 2.0]) RETURN ai.toList(ai.subtract(v1, v2))
Result: [4, 1]
Multiplies a vector by a scalar value.
| Syntax | ai.scale(<vector>, <scalar>) | ||
| Arguments | Name | Type | Description |
<vector> | VECTOR | A vector value | |
<scalar> | Numeric | The scalar multiplier | |
| Return Type | VECTOR | ||
GQLLET v = ai.vector([1.0, 2.0, 3.0]) RETURN ai.toList(ai.scale(v, 2))
Result: [2, 4, 6]
Rebuilds an HNSW vector index from the underlying data. Use this to recover a STALE index (e.g., after a crash) or to apply new m/efConstruction parameters.
| Syntax | ai.rebuildIndex(<indexName>) | ||
| Arguments | Name | Type | Description |
<indexName> | STRING | The name of the vector index to rebuild | |
| Return Type | STRING | ||
GQLRETURN ai.rebuildIndex('summary_embedding')
Updates a runtime-mutable vector index option. Currently only efSearch can be changed at runtime; changing m or efConstruction requires a rebuild.
| Syntax | ai.setIndexOption(<indexName>, <key>, <value>) | ||
| Arguments | Name | Type | Description |
<indexName> | STRING | The name of the vector index | |
<key> | STRING | The option to set (e.g., "efSearch") | |
<value> | Numeric | The new value | |
| Return Type | STRING | ||
GQLRETURN ai.setIndexOption('summary_embedding', 'efSearch', 200)