Skip to content

Commit 98baf93

Browse files
Document VECTOR type and new vector functions (#1299)
See also: #1325 Co-authored-by: Stefano Ottolenghi <[email protected]>
1 parent 0bec8e4 commit 98baf93

File tree

16 files changed

+1292
-191
lines changed

16 files changed

+1292
-191
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
** xref::values-and-types/spatial.adoc[]
6565
** xref::values-and-types/lists.adoc[]
6666
** xref::values-and-types/maps.adoc[]
67+
** xref::values-and-types/vector.adoc[]
6768
** xref:values-and-types/graph-references.adoc[]
6869
** xref::values-and-types/working-with-null.adoc[]
6970
** xref::values-and-types/casting-data.adoc[]

modules/ROOT/pages/appendix/gql-conformance/additional-cypher.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ Either the pattern already exists, or it needs to be created.
5252
| Cypher feature
5353
| Description
5454

55+
| xref:values-and-types/maps.adoc#query-operators-list[`MAP` values].
56+
| Map values - the GQL equivalent is Records.
57+
5558
| xref:values-and-types/spatial.adoc[`POINT` values]
5659
| Spatial values.
5760

58-
| xref:values-and-types/maps.adoc#query-operators-list[`MAP` values].
59-
| Map values - the GQL equivalent is Records.
61+
| xref:values-and-types/vector.adoc[`VECTOR<TYPE>(DIMENSION)` values]
62+
| Vector values, defined with a coordinate type and dimension.
6063

6164
|===
6265

modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,67 @@ For more information, see xref:queries/select-version.adoc[].
2626
[[cypher-deprecations-additions-removals-2025.10]]
2727
== Neo4j 2025.10
2828

29+
=== New in Cypher 25
30+
31+
[cols="2", options="header"]
32+
|===
33+
| Feature
34+
| Details
35+
36+
a|
37+
label:functionality[]
38+
label:new[]
39+
[source, cypher]
40+
----
41+
VECTOR([1.05, 0.123, 5], 3, FLOAT32 NOT NULL)
42+
----
43+
44+
a| Introduced a `VECTOR` value type that can be stored as xref:indexes/semantic-indexes/vector-indexes.adoc#embeddings[embedding] properties on nodes and relationships and utilized for efficient semantic retrieval using Neo4j's xref:indexes/semantic-indexes/vector-indexes.adoc[vector indexes] and xref:genai-integrations.adoc[GenAI plugin].
45+
For more information, see xref:values-and-types/vector.adoc[Values and types -> Vectors].
46+
47+
a|
48+
label:functionality[]
49+
label:new[]
50+
[source, cypher]
51+
----
52+
WITH vector([1, 2, 3], 3, INTEGER) AS vector
53+
RETURN vector, valueType(vector) AS vectorType
54+
----
55+
56+
a| New xref:functions/vector.adoc#functions-vector[`vector()`] function for the construction of xref:values-and-types/vector.adoc[`VECTOR`] values.
57+
58+
a|
59+
label:functionality[]
60+
label:new[]
61+
[source, cypher]
62+
----
63+
RETURN vector_dimension_count(vector([1, 2, 3], 3, INTEGER)) AS size
64+
----
65+
66+
a| New xref:functions/vector.adoc#functions-vector_dimension_count[`vector_dimension_count()`] function, which returns the dimension of a xref:values-and-types/vector.adoc[`VECTOR`] value.
67+
68+
a|
69+
label:functionality[]
70+
label:new[]
71+
[source, cypher]
72+
----
73+
RETURN vector_distance(vector([1, 2, 3], 3, INT), vector([1, 2, 4], 3, INT), COSINE) AS distance
74+
----
75+
76+
a| New xref:functions/vector.adoc#functions-vector_distance[`vector_distance()`] function, which returns the distance between two xref:values-and-types/vector.adoc[`VECTOR`] values based on the selected `vectorDistanceMetric` algorithm.
77+
78+
a|
79+
label:functionality[]
80+
label:new[]
81+
[source, cypher]
82+
----
83+
RETURN vector_norm(vector([1.0, 5.0, 3.0, 6.7], 4, FLOAT), EUCLIDEAN) AS norm
84+
----
85+
86+
a| New xref:functions/vector.adoc#functions-vector_norm[`vector_norm()`] function, which returns the distance between the given vector and an origin vector, which is a vector with the same dimension with all coordinates set to zero, calculated using the specified `vectorDistanceMetric`.
87+
88+
|===
89+
2990
=== Updated in Cypher 25
3091

3192
[cols="2", options="header"]
@@ -36,7 +97,20 @@ For more information, see xref:queries/select-version.adoc[].
3697
a|
3798
label:functionality[]
3899
label:updated[]
39-
[source, cypher, role="noheader"]
100+
[source, cypher]
101+
----
102+
RETURN toFloatList(Vector([1, 2, 3], 3, INTEGER64)),
103+
toIntegerList(Vector([1, 2, 3], 3, INTEGER8)),
104+
vector.similarity.cosine(vector([3, 5, 7], 3, INT), vector([-1, -2, -3], 3, INT)),
105+
vector.similarity.euclidean(vector([3, 5, 7], 3, INT), vector([-1, -2, -3], 3, INT))
106+
----
107+
108+
a| The xref:functions/list.adoc#functions-tofloatlist[`toFloatList()`], xref:functions/list.adoc#functions-tointegerlist[`toIntegerList()`], xref:functions/vector.adoc#functions-similarity-cosine[`vector.similarity.cosine()`], and xref:functions/vector.adoc#functions-similarity-euclidean[`vector.similarity.euclidean()`] functions now accept `VECTOR` values as input arguments.
109+
110+
a|
111+
label:functionality[]
112+
label:updated[]
113+
[source, cypher]
40114
----
41115
RETURN datetime('11/18/1986', "MM/dd/yyyy") AS dt
42116
----
@@ -68,7 +142,7 @@ RETURN format(dt, "MM/dd/yyyy") AS US, format(dt, "dd/MM/yyyy") AS EU
68142

69143
| Cypher's new xref:functions/temporal/format.adoc[`format()`] function can create dynamically formatted string representations of temporal instance and duration types.
70144

71-
a|
145+
a|
72146
label:functionality[]
73147
label:new[]
74148

@@ -119,7 +193,7 @@ label:functionality[]
119193
label:updated[]
120194
[source, cypher]
121195
----
122-
PROFILE
196+
PROFILE
123197
WITH "Person" AS label
124198
MATCH (people:$(label))
125199
RETURN people.name
@@ -143,7 +217,7 @@ label:new[]
143217
----
144218
MATCH (()-->(n))+
145219
WHERE allReduce(acc = 0, node IN n \| acc + node.x, 6 < acc < 30)
146-
RETURN [i IN n \| i.x] AS sequence
220+
RETURN [i IN n \| i.x] AS sequence
147221
ORDER BY head(n).x, size(n)
148222
----
149223

@@ -517,10 +591,10 @@ label:new[]
517591
----
518592
CREATE ALIAS `remote-with-default-language`
519593
FOR DATABASE `northwind-graph-2020`
520-
AT "neo4j+s://location:7687"
521-
USER alice
522-
PASSWORD 'example_secret'
523-
DEFAULT LANGUAGE CYPHER 25
594+
AT "neo4j+s://location:7687"
595+
USER alice
596+
PASSWORD 'example_secret'
597+
DEFAULT LANGUAGE CYPHER 25
524598
----
525599

526600
a| Set the default Cypher version for a remote database alias when creating it.
@@ -942,7 +1016,7 @@ CASE x ... WHEN contains - 1 THEN ... END
9421016
a| Using a variable named `contains` (or any casing variant, like `CONTAINS`) in addition or subtraction operations within a `WHEN` operand of a xref:expressions/conditional-expressions.adoc#case-simple[simple `CASE`] expression is deprecated.
9431017
To continue using variables with this name, use backticks to quote the variable name:
9441018

945-
* Additions: `CASE x ... WHEN ++`contains`++ + 1 THEN ... END`
1019+
* Additions: `CASE x ... WHEN ++`contains`++ + 1 THEN ... END`
9461020
* Subtractions: `CASE x ... WHEN ++`contains`++ - 1 THEN ... END`
9471021

9481022
a|
@@ -957,8 +1031,8 @@ CASE x ... WHEN in["abc"] THEN ... END
9571031
----
9581032
a| Using the `[]` operator on a variable named `in` (or any casing variant, like `IN`) within a `WHEN` operand of a xref:expressions/conditional-expressions.adoc#case-simple[simple `CASE`] expression is deprecated.
9591033
To continue using variables with this name, use backticks to quote the variable name:
960-
961-
* `CASE x ... WHEN ++`in`++[1] THEN ... END`
1034+
1035+
* `CASE x ... WHEN ++`in`++[1] THEN ... END`
9621036
* `CASE x ... WHEN ++`in`++["abc"] THEN ... END`
9631037

9641038

@@ -1157,7 +1231,7 @@ label:functionality[]
11571231
label:updated[]
11581232
[source, cypher, role="noheader"]
11591233
----
1160-
CREATE (n:Label {property: 'name'}),
1234+
CREATE (n:Label {property: 'name'}),
11611235
()-[r:REL_TYPE]->()
11621236
----
11631237
| Neo4j's link:{neo4j-docs-base-uri}/operations-manual/current/database-internals/store-formats/#store-format-overview[block format] now implements xref:appendix/gql-conformance/index.adoc[GQL's] limit on the maximum length of identifiers.
@@ -1208,7 +1282,7 @@ RETURN t AS team, players
12081282

12091283
[source, cypher, role="noheader"]
12101284
----
1211-
OPTIONAL CALL db.labels() YIELD label
1285+
OPTIONAL CALL db.labels() YIELD label
12121286
RETURN label
12131287
----
12141288

@@ -1559,7 +1633,7 @@ MATCH SHORTEST 2 GROUPS (:A)-[:R]->{0,10}(:B)
15591633

15601634
a| Introduced new graph pattern matching keywords to find variations of the xref:patterns/shortest-paths.adoc[shortest paths] between nodes.
15611635

1562-
a|
1636+
a|
15631637
label:functionality[]
15641638
label:new[]
15651639

@@ -4757,4 +4831,4 @@ MATCH (n:N {prop1: 42} WHERE n.prop2 > 42)
47574831
a|
47584832
New syntax that enables inlining of `WHERE` clauses inside node patterns.
47594833

4760-
|===
4834+
|===

modules/ROOT/pages/expressions/predicates/type-predicate-expressions.adoc

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,122 @@ RETURN val, val IS :: INTEGER AS isInteger
3838
2+d|Rows: 4
3939
|===
4040

41+
[role=label--new-Neo4j-2025.10 label--cypher-25-only]
42+
[[type-predicate-vector]]
43+
=== Vector values and supertypes
44+
45+
The following examples use `VECTOR` values (constructed using the xref:functions/vector.adoc#functions-vector[`vector()` function]) with `3` dimensions and `INTEGER8` coordinate type.
46+
47+
.Verify a `VECTOR<TYPE>(DIMENSION)` value against a `VECTOR` the same coordinate type and dimension
48+
[source, cypher]
49+
----
50+
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
51+
RETURN vector IS :: VECTOR<INTEGER8>(3) AS isVector
52+
----
53+
54+
.Result
55+
[role="queryresult",options="header,footer",cols="1*<m"]
56+
|===
57+
| isVector
58+
59+
| true
60+
61+
1+d|Rows: 1
62+
|===
63+
64+
Although it is not possible to store xref:values-and-types/vector.adoc[`VECTOR`] values 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.
65+
66+
.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR` supertype
67+
[source, cypher]
68+
----
69+
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
70+
RETURN vector IS :: VECTOR AS isVector
71+
----
72+
73+
.Result
74+
[role="queryresult",options="header,footer",cols="1*<m"]
75+
|===
76+
| isVector
77+
78+
| true
79+
80+
1+d|Rows: 1
81+
|===
82+
83+
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).
84+
85+
.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR<TYPE>` supertype
86+
[source, cypher]
87+
----
88+
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
89+
RETURN vector IS :: VECTOR<INTEGER8> AS isInteger8Vector
90+
----
91+
92+
.Result
93+
[role="queryresult",options="header,footer",cols="1*<m"]
94+
|===
95+
| isInteger8Vector
96+
97+
| true
98+
99+
1+d|Rows: 1
100+
|===
101+
102+
.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR(DIMENSION)` supertype
103+
[source, cypher]
104+
----
105+
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
106+
RETURN vector IS :: VECTOR(3) AS isDimension3Vector
107+
----
108+
109+
.Result
110+
[role="queryresult",options="header,footer",cols="1*<m"]
111+
|===
112+
| isDimension3Vector
113+
114+
| true
115+
116+
1+d|Rows: 1
117+
|===
118+
119+
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`.
120+
121+
.Verify a `VECTOR<TYPE>(DIMENSION)` value against a `VECTOR` with a different dimension
122+
[source, cypher]
123+
----
124+
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
125+
RETURN vector IS :: VECTOR(5) AS isDimension5Vector
126+
----
127+
128+
.Result
129+
[role="queryresult",options="header,footer",cols="1*<m"]
130+
|===
131+
| isDimension5Vector
132+
133+
| false
134+
135+
1+d|Rows: 1
136+
|===
137+
138+
139+
.Verify a `VECTOR<TYPE>(DIMENSION)` value against a `VECTOR` with a different coordinate type
140+
[source, cypher]
141+
----
142+
WITH vector([1, 2, 3], 3, INTEGER8) AS vector
143+
RETURN vector IS :: VECTOR<INTEGER16> AS isInteger16Vector
144+
----
145+
146+
.Result
147+
[role="queryresult",options="header,footer",cols="1*<m"]
148+
|===
149+
| isInteger16Vector
150+
151+
| false
152+
153+
1+d|Rows: 1
154+
|===
155+
156+
41157
[[type-predicate-not]]
42158
== Type predicate expressions with NOT
43159

@@ -189,7 +305,16 @@ Cypher will therefore regard any exact numerical parameter as an `INTEGER` regar
189305
For example, an `INT16` or an `INT32` passed through from a link:https://neo4j.com/docs/create-applications/[language library] will both be treated by Cypher as an `INTEGER`.
190306
Note that any exact numerical parameter used must fit within the range of an `INT64`.
191307

192-
[source, cypher, role=test-skip]
308+
////
309+
[source, parameters]
310+
----
311+
{
312+
"int16param": 65537
313+
}
314+
----
315+
////
316+
317+
[source, cypher]
193318
----
194319
RETURN $int16param IS :: INTEGER AS isInteger
195320
----
@@ -205,6 +330,9 @@ RETURN $int16param IS :: INTEGER AS isInteger
205330

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

333+
[NOTE]
334+
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.
335+
208336
[[type-predicate-syntax-variation]]
209337
== Syntactical variations of type predicate expressions
210338

0 commit comments

Comments
 (0)