Skip to content

Document VECTOR type and new vector functions #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/ROOT/content-nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
** xref::values-and-types/spatial.adoc[]
** xref::values-and-types/lists.adoc[]
** xref::values-and-types/maps.adoc[]
** xref::values-and-types/vector.adoc[]
** xref:values-and-types/graph-references.adoc[]
** xref::values-and-types/working-with-null.adoc[]
** xref::values-and-types/casting-data.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,122 @@ RETURN val, val IS :: INTEGER AS isInteger
2+d|Rows: 4
|===

[role=label-new-2025.xx]
[[type-predicate-vector]]
=== VECTOR values

Whilst it is not possible to store a xref:values-and-types/vector.adoc[`VECTOR`] value without a coordinate type and dimension, it is possible to use the `VECTOR` supertype (encompassing all combinations of `VECTOR<TYPE>(DIMENSION)`) in type predicate expressions.

The following examples uses a `VECTOR` (constructed using the xref:functions/vector.adoc#functions-vector[`vector()` function]) with `3` dimensions and `INTEGER8` coordinate type.

.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR` supertype
[source, cypher]
----
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
RETURN vector IS :: VECTOR AS isVector
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| isVector

| true

1+d|Rows: 1
|===

The same is true for the supertypes `VECTOR<TYPE>` (which encompasses all `VECTOR` values with the same coordinate type regardless of the dimension) and `VECTOR(DIMENSION)` (which encompasses all `VECTOR` values with the same dimension regardless of the coordinate type).

.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR<TYPE>` supertype
[source, cypher]
----
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
RETURN vector IS :: VECTOR<INTEGER8> AS isInteger8Vector
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| isInteger8Vector

| true

1+d|Rows: 1
|===

.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR(DIMENSION)` supertype
[source, cypher]
----
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
RETURN vector IS :: VECTOR(3) AS isDimension3Vector
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| isDimension3Vector

| true

1+d|Rows: 1
|===

If the coordinate type or dimension in the `VECTOR` does not match what is specified in the type predicate expression, the result will be `false`.

.Verify a `VECTOR<TYPE>(DIMENSION)` value against a `VECTOR` with a different dimension
[source, cypher]
----
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
RETURN vector IS :: VECTOR(5) AS isDimension5Vector
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| isDimension5Vector

| false

1+d|Rows: 1
|===


.Verify a `VECTOR<TYPE>(DIMENSION)` value against a `VECTOR` with a different coordinate type
[source, cypher]
----
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
RETURN vector IS :: VECTOR<INTEGER16> AS isInteger16Vector
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| isInteger16Vector

| false

1+d|Rows: 1
|===

.Verify a `VECTOR<TYPE>(DIMENSION)` value against a `VECTOR` the same coordinate type and dimension
[source, cypher]
----
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
RETURN vector IS :: VECTOR<INTEGER8>(3) AS isVector
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| isVector

| true

1+d|Rows: 1
|===


[[type-predicate-not]]
== Type predicate expressions with NOT

Expand Down Expand Up @@ -205,6 +321,9 @@ RETURN $int16param IS :: INTEGER AS isInteger

More information about parameters can be found xref::syntax/parameters.adoc[here].

[NOTE]
The xref:values-and-types/vector.adoc#vector-type[vector-only coordinate types] cannot be used as the numeric type to verify against in type predicate expressions.

[[type-predicate-syntax-variation]]
== Syntactical variations of type predicate expressions

Expand Down
25 changes: 21 additions & 4 deletions modules/ROOT/pages/functions/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ Converts a `LIST<ANY>` of values to a `LIST<BOOLEAN>` values.
If any values are not convertible to `BOOLEAN` they will be null in the `LIST<BOOLEAN>` returned.

1.1+| xref::functions/list.adoc#functions-tofloatlist[`toFloatList()`]
| `toFloatList(input :: LIST<ANY>) :: LIST<FLOAT>`
| `toFloatList(input :: VECTOR \| LIST<ANY>) :: LIST<FLOAT>`
a|
Converts a `LIST<ANY>` to a `LIST<FLOAT>` values.
If any values are not convertible to `FLOAT` they will be null in the `LIST<FLOAT>` returned.

1.1+| xref::functions/list.adoc#functions-tointegerlist[`toIntegerList()`]
| `toIntegerList(input :: LIST<ANY>) :: LIST<INTEGER>`
| `toIntegerList(input :: VECTOR \| LIST<ANY>) :: LIST<INTEGER>`
a|
Converts a `LIST<ANY>` to a `LIST<INTEGER>` values.
If any values are not convertible to `INTEGER` they will be null in the `LIST<INTEGER>` returned.
Expand Down Expand Up @@ -791,12 +791,29 @@ Vector functions allow you to compute the similarity scores of vector pairs.
|===
| Function | Signature | Description

1.1+| xref::functions/vector.adoc#functions-vector[`vector()`]
| `vector(vectorValue :: STRING \| LIST<INTEGER \| FLOAT>, dimension :: INTEGER, coordinateType :: [INTEGER64, INTEGER32, INTEGER16, INTEGER8, FLOAT64, FLOAT32]) :: VECTOR`
| Constructs a `VECTOR` value. label:new[Introduced in Neo4j 2025.xx]

1.1+| xref::functions/vector.adoc#functions-similarity-cosine[`vector.similarity.cosine()`]
| `vector.similarity.cosine(a :: LIST<INTEGER \| FLOAT>, b :: LIST<INTEGER \| FLOAT>) :: FLOAT`
| `vector.similarity.cosine(a :: VECTOR \| LIST<INTEGER \| FLOAT>, b :: VECTOR \| LIST<INTEGER \| FLOAT>) :: FLOAT`
| Returns a `FLOAT` representing the similarity between the argument vectors based on their cosine.

1.1+| xref::functions/vector.adoc#functions-similarity-euclidean[`vector.similarity.euclidean()`]
| `vector.similarity.euclidean(a :: LIST<INTEGER \| FLOAT>, b :: LIST<INTEGER \| FLOAT>) :: FLOAT`
| `vector.similarity.euclidean(a :: VECTOR \| LIST<INTEGER \| FLOAT>, b :: VECTOR \| LIST<INTEGER \| FLOAT>) :: FLOAT`
| Returns a `FLOAT` representing the similarity between the argument vectors based on their Euclidean distance.

1.1+| xref::functions/vector.adoc#functions-vector_dimension_count[`vector_dimension_count()`]
| `(vector :: VECTOR) :: INTEGER`
| Returns the dimension of a `VECTOR`. label:new[Introduced in Neo4j 2025.xx]

1.1+| xref::functions/vector.adoc#functions-vector_distance[`vector_distance()`]
| `(vector1 :: VECTOR, vector2 :: VECTOR, vectorDistanceMetric :: [EUCLIDEAN, EUCLIDEAN_SQUARED, MANHATTAN, COSINE, DOT, HAMMING]) :: FLOAT`
| Returns a `FLOAT` representing the distance between the two vector values based on the selected `vectorDistanceMetric` algorithm. label:new[Introduced in Neo4j 2025.xx]

1.1+| xref::functions/vector.adoc#functions-vector_norm[`vector_norm()`]
| `vector_norm(vector :: VECTOR, vectorDistanceMetric :: [EUCLIDEAN, MANHATTAN]) :: FLOAT`
| Returns a `FLOAT` representing the distance between the given vector and a vector of the same dimension with all coordinates set to zero, calculated using the specified `vectorDistanceMetric`. label:new[Introduced in Neo4j 2025.xx]

|===

30 changes: 16 additions & 14 deletions modules/ROOT/pages/functions/list.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ The property named `likedColors` and a `LIST<ANY>` comprising all but the first
| Any `BOOLEAN` value in `input` is preserved.
| If the `input` is `null`, `null` will be returned.
| If the `input` is not a `LIST<ANY>`, an error will be returned.
| The conversion for each value in `list` is done according to the xref::functions/scalar.adoc#functions-tobooleanornull[`toBooleanOrNull()` function].
| The conversion for each value in `input` is done according to the xref::functions/scalar.adoc#functions-tobooleanornull[`toBooleanOrNull()` function].

|===

Expand Down Expand Up @@ -470,19 +470,20 @@ toBooleanList(['a string', true, 'false', null, ['A','B']]) as mixedList
.Details
|===
| *Syntax* 3+| `toFloatList(input)`
| *Description* 3+| Converts a `LIST<ANY>` to a `LIST<FLOAT>` values. If any values are not convertible to `FLOAT` they will be null in the `LIST<FLOAT>` returned.
| *Description* 3+| Converts a `LIST<ANY>` or a `VECTOR` to a `LIST<FLOAT>` values. If any values are not convertible to `FLOAT` they will be null in the `LIST<FLOAT>` returned.
.2+| *Arguments* | *Name* | *Type* | *Description*
| `input` | `LIST<ANY>` | A list of values to be converted into a list of floats.
| `input` | `VECTOR` \| `LIST<ANY>` | A list of values or a vector value to be converted into a list of floats.
| *Returns* 3+| `LIST<FLOAT>`
|===

.Considerations
|===

| Any `null` element in `list` is preserved.
| Any `FLOAT` value in `list` is preserved.
| Any `null` element in `input` is preserved.
| Any `FLOAT` value in `input` is preserved.
| If the `input` is `null`, `null` will be returned.
| If the `input` is not a `LIST<ANY>`, an error will be returned.
| If the `input` is not a `VECTOR` or `LIST<ANY>`, an error will be returned.
| `input` accepts `VECTOR` values as of Neo4j 2025.xx
| The conversion for each value in `input` is done according to the xref::functions/scalar.adoc#functions-tofloatornull[`toFloatOrNull()` function].

|===
Expand Down Expand Up @@ -520,9 +521,9 @@ toFloatList(['a string', 2.5, '3.14159', null, ['A','B']]) as mixedList
.Details
|===
| *Syntax* 3+| `toIntegerList(input)`
| *Description* 3+| Converts a `LIST<ANY>` to a `LIST<INTEGER>` values. If any values are not convertible to `INTEGER` they will be null in the `LIST<INTEGER>` returned.
| *Description* 3+| Converts a `LIST<ANY>` or a `VECTOR` to a `LIST<INTEGER>` values. If any values are not convertible to `INTEGER` they will be null in the `LIST<INTEGER>` returned.
.2+| *Arguments* | *Name* | *Type* | *Description*
| `input` | `LIST<ANY>` | A list of values to be converted into a list of integers.
| `input` | `VECTOR` \| `LIST<ANY>` | A list of values or a vector value to be converted into a list of integers.
| *Returns* 3+| `LIST<INTEGER>`
|===

Expand All @@ -532,7 +533,8 @@ toFloatList(['a string', 2.5, '3.14159', null, ['A','B']]) as mixedList
| Any `null` element in `input` is preserved.
| Any `INTEGER` value in `input` is preserved.
| If the `input` is `null`, `null` will be returned.
| If the `input` is not a `LIST<ANY>`, an error will be returned.
| If the `input` is not a `VECTOR` or a `LIST<ANY>`, an error will be returned.
| `input` accepts `VECTOR` values as of Neo4j 2025.xx
| The conversion for each value in `list` is done according to the xref::functions/scalar.adoc#functions-tointegerornull[`toIntegerOrNull()` function].

|===
Expand Down Expand Up @@ -579,11 +581,11 @@ toIntegerList(['a string', 2, '5', null, ['A','B']]) as mixedList
.Considerations
|===

| Any `null` element in `list` is preserved.
| Any `STRING` value in `list` is preserved.
| If the `list` is `null`, `null` will be returned.
| If the `list` is not a `LIST<ANY>`, an error will be returned.
| The conversion for each value in `list` is done according to the xref::functions/string.adoc#functions-tostringornull[`toStringOrNull()` function].
| Any `null` element in `input` is preserved.
| Any `STRING` value in `input` is preserved.
| If the `input` is `null`, `null` will be returned.
| If the `input` is not a `LIST<ANY>`, an error will be returned.
| The conversion for each value in `input` is done according to the xref::functions/string.adoc#functions-tostringornull[`toStringOrNull()` function].

|===

Expand Down
Loading