UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Overview
  • Provider Configuration
  • AI Completion
  • Vectors
  • Vector Similarity Search
  • Vector Utilities
  1. Docs
  2. /
  3. AI Functions

Vector Utilities

Inspect, transform, and perform arithmetic operations on vectors, and manage vector indexes.

Inspection

ai.dimension()

Returns the number of dimensions in a vector.

Syntaxai.dimension(<vector>)
ArgumentsNameTypeDescription
<vector>VECTORA vector value
Return TypeINT
GQL
LET v = ai.vector([3.0, 4.0])
RETURN ai.dimension(v)

Result: 2

ai.magnitude()

Returns the magnitude (L2 norm) of a vector.

Syntaxai.magnitude(<vector>)
ArgumentsNameTypeDescription
<vector>VECTORA vector value
Return TypeFLOAT
GQL
LET v = ai.vector([3.0, 4.0])
RETURN ai.magnitude(v)

Result: 5

ai.normalize()

Normalizes a vector to a unit vector (magnitude of 1).

Syntaxai.normalize(<vector>)
ArgumentsNameTypeDescription
<vector>VECTORA vector value
Return TypeVECTOR
GQL
LET v = ai.vector([3.0, 4.0])
RETURN ai.normalize(v)

Result:

JSON
{
  "values": [
    0.6000000238418579,
    0.800000011920929
  ]
}

ai.toList()

Converts a vector to a list of numbers.

Syntaxai.toList(<vector>)
ArgumentsNameTypeDescription
<vector>VECTORA vector value
Return TypeLIST
GQL
LET embedding = ai.embed("Introduction to graph databases")
RETURN ai.toList(embedding)

Result: [-0.0258026123046875, -0.0126800537109375, …, 0.0162200927734375, -0.017486572265625]

Vector Arithmetic

ai.add()

Adds two vectors element-wise.

Syntaxai.add(<vector1>, <vector2>)
ArgumentsNameTypeDescription
<vector1>VECTORThe first vector
<vector2>VECTORThe second vector; must have the same dimension as <vector1>
Return TypeVECTOR
GQL
LET 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]

ai.subtract()

Subtracts the second vector from the first element-wise.

Syntaxai.subtract(<vector1>, <vector2>)
ArgumentsNameTypeDescription
<vector1>VECTORThe first vector
<vector2>VECTORThe second vector; must have the same dimension as <vector1>
Return TypeVECTOR
GQL
LET 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]

ai.scale()

Multiplies a vector by a scalar value.

Syntaxai.scale(<vector>, <scalar>)
ArgumentsNameTypeDescription
<vector>VECTORA vector value
<scalar>NumericThe scalar multiplier
Return TypeVECTOR
GQL
LET v = ai.vector([1.0, 2.0, 3.0])
RETURN ai.toList(ai.scale(v, 2))

Result: [2, 4, 6]

Vector Index Management

ai.rebuildIndex()

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.

Syntaxai.rebuildIndex(<indexName>)
ArgumentsNameTypeDescription
<indexName>STRINGThe name of the vector index to rebuild
Return TypeSTRING
GQL
RETURN ai.rebuildIndex('summary_embedding')

ai.setIndexOption()

Updates a runtime-mutable vector index option. Currently only efSearch can be changed at runtime; changing m or efConstruction requires a rebuild.

Syntaxai.setIndexOption(<indexName>, <key>, <value>)
ArgumentsNameTypeDescription
<indexName>STRINGThe name of the vector index
<key>STRINGThe option to set (e.g., "efSearch")
<value>NumericThe new value
Return TypeSTRING
GQL
RETURN ai.setIndexOption('summary_embedding', 'efSearch', 200)