Skip to content

Commit 9f70ea0

Browse files
revise pages
1 parent 45ee98d commit 9f70ea0

File tree

4 files changed

+119
-77
lines changed

4 files changed

+119
-77
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RETURN vector IS :: VECTOR<INTEGER8>(3) AS isVector
6161
1+d|Rows: 1
6262
|===
6363

64-
Although 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.
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.
6565

6666
.Verify a `VECTOR<TYPE>(DIMENSION)` value against the `VECTOR` supertype
6767
[source, cypher]

modules/ROOT/pages/genai-integrations.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ WITH collect(m) AS moviesList // <1>
214214
WITH moviesList, [movie IN moviesList | movie.title || ': ' || movie.plot] AS batch // <2>
215215
CALL genai.vector.encodeBatch(batch, 'OpenAI', { token: $openaiToken }) YIELD index, vector
216216
WITH moviesList, index, vector
217-
SET moviesList[index].embedding = vector(vector, 1536, FLOAT32) // <3>
217+
MATCH (toUpdate:Movie {title: moviesList[index]['title']})
218+
SET toUpdate.embedding = vector(vector, 1536, FLOAT32) // <3>
218219
----
219220

220221
<1> xref:functions/aggregating.adoc#functions-collect[Collect] all 20 `Movie` nodes into a `LIST<NODE>`.
221-
<2> Use a xref:expressions/list-expressions.adoc#list-comprehension[list comprehension] (`[]`) to extract the `title` and `plot` properties of the movies in `moviesList` into a new `LIST<STRING>`.
222+
<2> A xref:expressions/list-expressions.adoc#list-comprehension[list comprehension] (`[]`) extracts the `title` and `plot` properties of the movies in `moviesList` into a new `LIST<STRING>`.
222223
<3> `db.create.setNodeVectorProperty` is run for each `vector` returned by `genai.vector.encodeBatch()`, and stores that vector as a property named `embedding` on the corresponding node.
223224

224225
.Create embeddings from a large number properties and store them as `VECTOR` properties
@@ -232,7 +233,8 @@ UNWIND range(0, total-1, batchSize) AS batchStart // <3>
232233
CALL (moviesList, batchStart, batchSize) { // <4>
233234
WITH [movie IN moviesList[batchStart .. batchStart + batchSize] | movie.title || ': ' || movie.plot] AS batch // <5>
234235
CALL genai.vector.encodeBatch(batch, 'OpenAI', { token: $openaiToken }) YIELD index, vector
235-
SET moviesList[batchStart + index].embedding = vector(vector, 1536, FLOAT32) // <6>
236+
MATCH (toUpdate:Movie {title: moviesList[batchStart + index]['title']})
237+
SET toUpdate.embedding = vector(vector, 1536, FLOAT32) // <6>
236238
} IN CONCURRENT TRANSACTIONS OF 1 ROW // <7>
237239
----
238240

@@ -295,7 +297,7 @@ CALL db.create.setNodeVectorProperty(moviesList[index], 'embedding', vector) //
295297
----
296298

297299
<1> xref:functions/aggregating.adoc#functions-collect[Collect] all 20 `Movie` nodes into a `LIST<NODE>`.
298-
<2> Use a xref:expressions/list-expressions.adoc#list-comprehension[list comprehension] (`[]`) to extract the `title` and `plot` properties of the movies in `moviesList` into a new `LIST<STRING>`.
300+
<2> A xref:expressions/list-expressions.adoc#list-comprehension[list comprehension] (`[]`) extracts the `title` and `plot` properties of the movies in `moviesList` into a new `LIST<STRING>`.
299301
<3> `db.create.setNodeVectorProperty` is run for each `vector` returned by `genai.vector.encodeBatch()`, and stores that vector as a property named `embedding` on the corresponding node.
300302

301303
.Create embeddings from a large number properties and store them as `LIST<FLOAT>` values

modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Each word or token in a text is typically represented as high-dimensional vector
4141

4242
The embedding for a particular data object can be created by both proprietary (such as https://cloud.google.com/vertex-ai[Vertex AI] or https://openai.com/[OpenAI]) and open source (such as https://github.com/UKPLab/sentence-transformers[sentence-transformers]) embedding generators, which can produce vector embeddings with dimensions such as 256, 768, 1536, and 3072.
4343
Vector embeddings are stored as `LIST<INTEGER | FLOAT>` properties on a node or relationship.
44-
As of Neo4j 2025.xx, they can also be more efficiently stored as xref:values-and-types/vector.adoc[`VECTOR`] properties using Cypher 25.
44+
As of Neo4j 2025.10, they can also be more efficiently stored as xref:values-and-types/vector.adoc[`VECTOR`] properties using Cypher 25.
4545

4646
[NOTE]
4747
====
@@ -82,7 +82,7 @@ A newly created index is not immediately available but is created in the backgro
8282
[NOTE]
8383
Creating indexes requires link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/database-administration/#access-control-database-administration-index[the `CREATE INDEX` privilege].
8484

85-
.Create vector index for `Movie` nodes on the `embedding` property
85+
.Create vector index for `Movie` nodes on the `embedding` property
8686
[source, cypher]
8787
----
8888
CREATE VECTOR INDEX moviePlots IF NOT EXISTS // <1>
@@ -105,7 +105,7 @@ To read more about the available similarity functions, see xref:indexes/semantic
105105

106106
You can also create a vector index for relationships with a particular type on a given property using the following syntax:
107107

108-
.Create a vector index for a relationship type on a single property
108+
.Create a vector index for a relationship type on a single property
109109
[source, cypher, role=test-skip]
110110
----
111111
CREATE VECTOR INDEX name IF NOT EXISTS
@@ -229,7 +229,7 @@ If the query vector itself is not wanted, adding the predicate `WHERE score < 1`
229229

230230
To query a relationship vector index, use the link:{neo4j-docs-base-uri}/operations-manual/current/procedures/#procedure_db_index_vector_queryRelationships[`db.index.vector.queryRelationships`] procedure.
231231

232-
.Signature for `db.index.vector.queryRelationships()`
232+
.Signature for `db.index.vector.queryRelationships()`
233233
[source,syntax]
234234
----
235235
db.index.vector.queryRelationships(indexName :: STRING, numberOfNearestNeighbours :: INTEGER, query :: ANY) :: (relationship :: RELATIONSHIP, score :: FLOAT)
@@ -479,7 +479,7 @@ Returns the requested number of approximate nearest neighbor nodes and their sim
479479
| Use relationship vector index.
480480
| link:{neo4j-docs-base-uri}/operations-manual/current/procedures/#procedure_db_index_vector_queryRelationships[`db.index.vector.queryRelationships()`]
481481
| Query the given relationship vector index.
482-
Returns the requested number of approximate nearest neighbor relationships and their similarity score, ordered by score.
482+
Returns the requested number of approximate nearest neighbor relationships and their similarity score, ordered by score.
483483

484484
| Set node vector property.
485485
| link:{neo4j-docs-base-uri}/operations-manual/current/procedures/#procedure_db_create_setNodeVectorProperty[`db.create.setNodeVectorProperty()`]

modules/ROOT/pages/values-and-types/vector.adoc

Lines changed: 107 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,49 @@
22
:description: Information about Cypher's `VECTOR` type.
33
:page-role: new-neo4j-2025.10
44

5-
Cypher supports the construction of a `VECTOR` value that can be stored as xref:indexes/semantic-indexes/vector-indexes.adoc#embeddings[embedding] properties on nodes and relationships and used for efficient semantic retrieval using Neo4j's xref:indexes/semantic-indexes/vector-indexes.adoc[vector indexes] and xref:genai-integrations.adoc[GenAI plugin].
6-
`VECTOR` values can also be measured and compared (in terms of similarity, distance, and norm) using Cypher's xref:functions/vector.adoc[vector functions].
5+
`VECTOR` values can be created and stored as xref:indexes/semantic-indexes/vector-indexes.adoc#embeddings[embedding] properties on nodes and relationships, and used for efficient semantic retrieval using xref:indexes/semantic-indexes/vector-indexes.adoc[vector indexes] and the xref:genai-integrations.adoc[GenAI plugin].
6+
`VECTOR` values can also be measured and compared (in terms of similarity, distance, and norm) using xref:functions/vector.adoc[vector functions].
77

88
[[vector-type]]
99
== The vector type
1010

11-
The `VECTOR` type is a fixed-length, ordered collection of numeric coordinate values (`INTEGER` or `FLOAT`) stored as a single unit.
12-
It is defined by its dimension, which sets how many numeric values it holds, and its coordinate type, which specifies the specific numeric data type for those numbers.
13-
Each numeric value in the list represents a coordinate along one of the vector’s defined dimensions.
14-
The coordinate type controls the type of each coordinate in the `VECTOR`, influencing precision and storage size.
15-
A `VECTOR` value must have a dimension and a coordinate type.
11+
The `VECTOR` type is a fixed-length, ordered collection of numeric values (`INTEGER` or `FLOAT`) stored as a single unit.
12+
The type of a value is defined by:
1613

17-
.Example `VECTOR` type
14+
- *Dimension* -- The number of values it contains.
15+
- *Coordinate type* -- The data type of the entries, determining precision and storage size.
16+
17+
.An example `VECTOR` value
1818
[source]
1919
----
20-
VECTOR([1.05, 0.123, 5], 3, FLOAT32 NOT NULL)
20+
vector([1.05, 0.123, 5], 3, FLOAT32)
2121
----
2222

23-
In this example, `[1.05, 0.123, 5]` is the coordinates of the `VECTOR`, `3` its dimensionality, and `FLOAT32` the data type for each coordinate value.
24-
25-
.`VECTOR` and `LIST` values
26-
[NOTE]
27-
The dimensions and the formatting of a `VECTOR` is similar to a xref:values-and-types/lists.adoc[`LIST`] value.
28-
However, whereas elements in `LIST` values can be accessed individually with xref:expressions/list-expressions.adoc[list expressions], operations on a `VECTOR` must operate on the entire `VECTOR`: it is not possible to access or slice individual elements of a `VECTOR` value.
29-
Additionally, Neo4j cannot store lists containing `VECTOR` values.
23+
In this example, `[1.05, 0.123, 5]` is the list of values, `3` its dimension, and `FLOAT32` the data type of the individual entries. +
24+
Each number in the list can also be seen as a coordinate along one of the vector's dimensions.
3025

31-
The dimension of a `VECTOR` value must be larger than `0` and less than or equal to `4096`.
3226

33-
The following coordinate types are supported:
27+
[[valid-values]]
28+
=== Valid values
3429

35-
.Vector coordinate types
30+
- A `VECTOR` value must have a dimension and a coordinate type.
31+
- The dimension of a `VECTOR` value must be larger than `0` and less than or equal to `4096`.
32+
- Vectors cannot contain lists as elements.
33+
- Supported coordinate types are: +
34+
+
3635
[options="header",cols="2*<m"]
3736
|===
3837
| Default name | Alias
3938

4039
| `FLOAT` | `FLOAT64`
4140
| `FLOAT32` |
42-
| `INTEGER` | `INT`, `INT64`, `SIGNED INTEGER`, `INTEGER64`
41+
| `INTEGER` | `INT`, `INT64`, `INTEGER64`, `SIGNED INTEGER`
4342
| `INTEGER8` | `INT8`
4443
| `INTEGER16`| `INT16`
4544
| `INTEGER32` | `INT8`
4645

4746
|===
4847

49-
`VECTOR` is a supertype of `VECTOR<TYPE>(DIMENSION)` types.
50-
The same applies for `VECTOR` types that define only a coordinate type or a dimension:
51-
52-
- `VECTOR` with only a defined dimension is a supertype of all `VECTOR` values of that dimension regardless of the coordinate type.
53-
For example, `VECTOR(4)` is a supertype of `VECTOR<FLOAT>(4)` and `VECTOR<INT8>(4)`.
54-
- `VECTOR` with only a defined coordinate type is a supertype of all `VECTOR` values with that coordinate type regardless of the dimension.
55-
For example, `VECTOR<INT>` is a supertype of `VECTOR<INT>(3)` and `VECTOR<INT>(1024)`.
56-
57-
All of these supertypes can be used in xref:expressions/predicates/type-predicate-expressions.adoc#type-predicate-vector[type predicate expressions] to verify `VECTOR` type values.
58-
59-
See also:
60-
61-
* xref:values-and-types/ordering-equality-comparison.adoc#ordering-and-comparison[Equality, ordering, and comparison of value types -> Ordering vector types]
62-
* xref:values-and-types/property-structural-constructed.adoc#vector-type-normalization[Property, structural, and constructed values -> Vector type normalization]
6348

6449
[[construct-vector-values]]
6550
== Construct vector values
@@ -88,26 +73,6 @@ RETURN vector
8873
8974
====
9075

91-
92-
[IMPORTANT]
93-
====
94-
Running a query that returns a `VECTOR` value via a link:{neo4j-docs-base-uri}/create-applications/[driver] version < 6.0 does not yield a `VECTOR`, but rather a placeholder `MAP` value.
95-
A warning will also be attached.
96-
97-
.Result of returning a `VECTOR` with a driver older than 6.0
98-
[source]
99-
----
100-
+----------------------------------------------------------------+
101-
| n.vector |
102-
+----------------------------------------------------------------+
103-
| {originalType: "VECTOR(1, INTEGER64)", reason: "UNKNOWN_TYPE"} |
104-
+----------------------------------------------------------------+
105-
warn: One or more values returned could not be handled by this version of the driver and were replaced with placeholder map values. Please upgrade your driver!
106-
03N95 (Neo.ClientNotification.UnknownType)
107-
----
108-
====
109-
110-
11176
.Create a `VECTOR` value using parameters
11277
====
11378
@@ -143,10 +108,11 @@ RETURN vector
143108
[[store-vector-properties]]
144109
== Store vector values as properties
145110

146-
To store a `VECTOR` value as a node or relationship property, use the `vector()` function together with a write clause.
111+
To store a `VECTOR` value as a node or relationship property, use the `vector()` function and a write clause.
147112

148113
[NOTE]
149-
Storing `VECTOR` values on an on-prem instance requires the database to be on link:{neo4j-docs-base-uri}/operations-manual/current/database-internals/store-formats/#store-format-overview[block format].
114+
Storing `VECTOR` values on requires the database to be on link:{neo4j-docs-base-uri}/operations-manual/current/database-internals/store-formats/#store-format-overview[block format].
115+
This is the default on Aura instances.
150116

151117
.Create a node and a `VECTOR` property
152118
====
@@ -200,22 +166,96 @@ RETURN n.vectorProp AS vectorProp
200166
201167
====
202168

203-
[NOTE]
204-
It is not possible to store lists of `VECTOR` values.
205169

170+
[[drivers-fallback]]
171+
== Vectors and client libraries (drivers)
172+
173+
Working with vectors via link:{neo4j-docs-base-uri}/create-applications/[Neo4j's client libraries] results in a different behavior depending on the library version.
174+
175+
- *Versions >= 6.0* -- Vectors are fully supported and mapped into client types (see the _Data types_ page of each language manual).
176+
- *Versions < 6.0* -- Vectors can be created, attached, and manipulated in queries via Cypher functions, but cannot be returned nor created in the application. +
177+
It is possible to create and store values as shown in the xref:store-vector-properties[Store vector values as properties] examples, but _returning_ a `VECTOR` results in a placeholder `MAP` value and a warning.
178+
+
179+
.Result of returning a `VECTOR` with a driver older than 6.0
180+
[source]
181+
----
182+
+----------------------------------------------------------------+
183+
| n.vector |
184+
+----------------------------------------------------------------+
185+
| {originalType: "VECTOR(1, INTEGER64)", reason: "UNKNOWN_TYPE"} |
186+
+----------------------------------------------------------------+
187+
warn: One or more values returned could not be handled by this version of the driver and were replaced with placeholder map values. Please upgrade your driver!
188+
03N95 (Neo.ClientNotification.UnknownType)
189+
----
190+
191+
192+
[[type-coercion]]
193+
== Type coercion
194+
195+
_Coercion_ is the action of forcing entries of a different (implicit) type into a vector with a different coordinate type.
206196

207-
[[genai-plugin-vector-indexes]]
208-
== Vector embeddings, the GenAI plugin, and vector indexes
197+
When the coordinate type is the same as the type of the given elements, no coercion is done.
198+
When the coordinate type differs, coercion may be done or an error may be raised depending on the situation.
209199

210-
Storing vector embeddings as `VECTOR` properties with a defined coordinate type has the following benefits:
200+
*An error is raised* if a value does not fit into the coordinate type.
201+
If the coordinate type is an `INTEGER` type and all the coordinate values are `INTEGER` values, then an error will be raised if and only if one of the coordinate types does not fit into the size of the specified type.
202+
The same applies for `FLOAT` vector types: if the elements are all `FLOAT` values then an error will only be raised if one value does not fit into the specified type.
211203

212-
* `VECTOR` values are stored on Neo4j's link:{neo4j-docs-base-uri}/operations-manual/current/database-internals/store-formats/#store-format-overview[block format], ensuring efficient retrieval and computation for operations like similarity search or distance calculations.
213-
* Defining a coordinate type with the `vector()` function allows `VECTOR` values to be stored more efficiently.
214-
Additionally, reducing a vectors coordinate type (e.g., from `INTEGER16` to `INTEGER8`) reduces storage requirements and improves performance, provided all values remain within the range supported by the smaller type.
204+
[source, cypher, test-fail]
205+
----
206+
RETURN VECTOR([128], 1, INT8)
207+
// 22N28: data exception - overflow error. The result of the operation 'vector()' has caused an overflow.
208+
// 22003: data exception - numeric value out of range. The numeric value 128 is outside the required range.
209+
----
210+
211+
*Coercion (i.e. lossy conversion) is allowed* when:
215212

216-
For information about how to store embeddings generated by Neo4j as `VECTOR` values with the xref:genai-integrations.adoc[GenAI plugin], see:
213+
- The list contains `INTEGER` values and the specified vector type is of a `FLOAT` type.
214+
Precision will be lost for values at the higher end of the range (see the link:https://docs.oracle.com/javase/specs/jls/se21/html/jls-5.html[Java type specification]), but an error will be raised only if the value were to overflow/underflow. +
215+
+
216+
[source, cypher]
217+
----
218+
RETURN VECTOR([987374677], 1, FLOAT32)
219+
// vector([9.8737466E8], 1, FLOAT32 NOT NULL)
220+
----
221+
- The list contains `FLOAT` values and the specified type is of an `INTEGER` type.
222+
Information may be lost, as all values after the decimal point will be truncated, but an error will be raised only if the value were to overflow/underflow. +
223+
+
224+
[source, cypher]
225+
----
226+
RETURN VECTOR([1.2], 1, INT)
227+
// vector([1], 1, INTEGER NOT NULL)
228+
----
229+
230+
231+
[[supertypes]]
232+
== Supertypes
233+
234+
`VECTOR` is a supertype of `VECTOR<TYPE>(DIMENSION)` types.
235+
The same applies for `VECTOR` types with only a coordinate type or a dimension:
236+
237+
- `VECTOR` with only a defined dimension is a supertype of all `VECTOR` values of that dimension, regardless of the coordinate type.
238+
For example, `VECTOR(4)` is a supertype of `VECTOR<FLOAT>(4)` and `VECTOR<INT8>(4)`.
239+
- `VECTOR` with only a defined coordinate type is a supertype of all `VECTOR` values with that coordinate type, regardless of the dimension.
240+
For example, `VECTOR<INT>` is a supertype of `VECTOR<INT>(3)` and `VECTOR<INT>(1024)`.
241+
242+
All of these supertypes can be used in xref:expressions/predicates/type-predicate-expressions.adoc#type-predicate-vector[type predicate expressions].
243+
For more information, see:
244+
245+
* xref:values-and-types/ordering-equality-comparison.adoc#ordering-and-comparison[Equality, ordering, and comparison of value types -> Ordering vector types]
246+
* xref:values-and-types/property-structural-constructed.adoc#vector-type-normalization[Property, structural, and constructed values -> Vector type normalization]
247+
248+
249+
[[lists-embeddings-vector-indexes]]
250+
== Lists, vector embeddings, and vector indexes
251+
252+
`VECTOR` and xref:values-and-types/lists.adoc[`LIST`] values are similar and can both be indexed and searched through using xref:indexes/semantic-indexes/vector-indexes.adoc[vector indexes], but have a few key differences:
253+
254+
- Elements in a `LIST` can be accessed individually, whereas operations on a `VECTOR` must operate on the entire `VECTOR`: it is not possible to access or slice individual elements.
255+
- Storing vector embeddings as `VECTOR` properties with a defined coordinate type allows them to be stored more efficiently.
256+
Moreover, reducing a vector's coordinate type (e.g., from `INTEGER16` to `INTEGER8`) downsizes storage requirements and improves performance, provided all values remain within the range supported by the smaller type.
257+
258+
For information about how to store embeddings as `VECTOR` values with the xref:genai-integrations.adoc[GenAI plugin], see:
217259

218260
* xref:genai-integrations.adoc#single-embedding[Generate a single embedding and store it]
219261
* xref:genai-integrations.adoc#multiple-embeddings[Generate multiple embeddings and store them]
220-
221-
Embeddings stored as `VECTOR` properties can be indexed and searched semantically using xref:indexes/semantic-indexes/vector-indexes.adoc[vector indexes].

0 commit comments

Comments
 (0)