You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cypher's supports a `VECTOR` type that can be stored as properties on nodes and relationships.
6
6
`VECTOR` properties can be utilized for efficient semantic retrieval with the Neo4j's xref:indexes/semantic-indexes/vector-indexes.adoc[vector indexes] and xref:genai-integrations.adoc[GenAI plugin].
7
7
8
-
8
+
[[construct-vector-values]]
9
9
== Construct vector type values
10
10
11
11
To construct a `VECTOR` type value, use the xref:functions/vector.adoc#functions-vector[`vector()`] function.
@@ -24,34 +24,219 @@ The `vectorValue` must be of the same length as the given `dimension` and contai
24
24
For example a `VECTOR` with a dimension of `3` has three values, which might represent vector embeddings.
25
25
* `coordinateType`: a vector-only coordinate `INTEGER` or `FLOAT` type, determining the data type for each of the values in `vectorValue`.
26
26
If `vectorValue` contain elements that are not of the specified coordinate type, they will be coerced to that coordinate type if possible.
27
-
This includes the potential of lossy conversion in cases where a larger type, e.g. `INTEGER64` does not fit into the specified type, e.g. `FLOAT32`.
27
+
This includes the potential of lossy conversion in cases where a larger type, e.g. `INTEGER64` does not fit into the specified type, e.g. `FLOAT32`.
28
+
For details of all available coordinate types, see xref:values-and-types/vector.adoc#vector-super-and-coordinate-types[vector coordinate types] below.
28
29
29
-
The following expression constructs a three-dimensional vector with integer values:
30
+
The following query constructs a three-dimensional vector with `INTEGER` values.
31
+
It returns the `VECTOR` itself, and the xref:functions/scalar.adoc#functions-valuetype[`valueType()`] function is used to information about its type.
| [1, 2, 3, 4, 5] | "VECTOR<INTEGER8 NOT NULL>(5) NOT NULL"
90
+
91
+
2+d|Rows: 1
92
+
|===
93
+
94
+
Both `dimension` and `coordinateType` are optional when using the `vector()` function.
95
+
96
+
* If `coordinateType` is omitted, the type will be determined by Cypher.
97
+
If the `LIST` used as `vectorValue` is mixed containing exclusively `INTEGER` values, then the largest of those types will be set as the `coordinateType`.
98
+
For example, `LIST<INTEGER64 | INTEGER32` generates a `VECTOR` value with a `coordinateType` of `INTEGER64`.
99
+
If the `vectorValue` contains both `FLOAT` and `INTEGER` values, then the `coordinateType` will be that of the largest `FLOAT` present in `vectorValue`.
100
+
For example, `LIST<INTEGER64 | FLOAT64` generates a `VECTOR` value with a `coordinateType` of `FLOAT64`.
101
+
102
+
* If `dimension` is omitted, it is calculated by taking the size of the `vectorValue`.
103
+
For example a `LIST` with 1024 elements generates a `VECTOR` value with the `dimension` `1024`.
104
+
105
+
.Construct a `VECTOR` value omitting both `dimension` and `coordinateType`
To calculate the size of a `VECTOR` value, use either the xref:functions/scalar.adoc#functions-size[`size()`] function or the xref:functions/vector.adoc#functions-vector_dimension_count[`vector_dimension_count()`] function
146
+
(Unlike `size()`, `vector_dimension_count` will return `null` for any non-`VECTOR` values`).
147
+
148
+
.Calculate `VECTOR` size with `size()`
149
+
[source, cypher]
150
+
----
151
+
RETURN size(vector([1, 2, 3], 3, INTEGER)) AS size
To store a `VECTOR` value as a node or relationship property, use the `vector()` function together with a write clause.
42
184
185
+
.Create a node and assign a `VECTOR` property
186
+
[source, cypher]
187
+
----
188
+
CREATE (n:Label)
189
+
SET n.vectorProp = vector([1,2,3], 3, INTEGER))
190
+
RETURN n.vectorProp AS vectorProp
191
+
----
43
192
44
-
== Vector types, the GenAI plugin, and vector indexes
193
+
.Parameters
194
+
[source, parameters]
195
+
----
196
+
{
197
+
"floatList": [1.3, 2.4, 3.1, 4.4, 5.9]
198
+
}
199
+
----
45
200
201
+
.Store a `VECTOR` property using a parameter
202
+
[source, cypher]
203
+
----
204
+
CREATE (n:Label)
205
+
SET n.vectorProp = vector($floatList, 5, FLOAT)
206
+
RETURN n.vectorProp AS vectorProp
207
+
----
46
208
47
-
== Vectors and lists
209
+
[[genai-plugin-vector-indexes]]
210
+
== Vector values, the GenAI plugin, and vector indexes
48
211
212
+
The `VECTOR` type can be used for more efficient handling of
49
213
50
-
Since Vectors are described as having multiple dimensions, they look a bit like the constructed value type LIST<...>. However, all vector operations operate on the entire vector. Operations on individual components of a vector instance are not defined. We therefore conclude that vectors are predefined value types.
51
214
52
215
216
+
[[vector-super-and-coordinate-types]]
217
+
== Vector supertypes and vector coordinate types
218
+
219
+
Though the `dimension` and `coordinateType` can be omitted when creating a `VECTOR` value with the `vector()` function, it is not possible to construct a `VECTOR` value without a dimension or a coordinate type.
220
+
As such, `VECTOR` should be considered a supertype (which can be checked for in a xref:expressions/predicates/type-predicate-expressions.adoc#type-predicate-vector[type predicate expressions]) to which all combinations of `VECTOR<TYPE>(DIMENSION)` are a part.
221
+
222
+
This logic continues for `VECTOR` values that define only a coordinate type or a dimension; a `VECTOR` with only a defined dimension represents all vectors of that dimension regardless of the type (e.g. `VECTOR<INTEGER8>` is a supertype of `VECTOR<INTEGER8>(3)` and `VECTOR<INTEGER8>(1024)`, and a `VECTOR` with only a defined coordinate type represents all vectors of that coordinate type regardless of the dimension (e.g. `VECTOR(3)` is a supertype of `VECTOR<FLOAT>(3)` and `VECTOR<INTEGER8>(3)`).
Whilst it is not possible to store a typeless, dimensionless vector, it is possible to use that type in a type predicate expression for example; RETURN x IS :: VECTOR which should evaluate to true as long as x is a vector, regardless of its coordinate type or dimension. Due to this, we consider VECTOR to be a supertype of all VECTOR types. This logic continues for vectors that define only a type or a dimension, a VECTOR with only a dimension represents all vectors of that dimension regardless of the type, and a VECTOR with only a type represents all vectors of that type regardless of the dimension.
239
+
== Vectors and lists
240
+
241
+
242
+
Since Vectors are described as having multiple dimensions, they look a bit like the constructed value type LIST<...>. However, all vector operations operate on the entire vector. Operations on individual components of a vector instance are not defined. We therefore conclude that vectors are predefined value types.
0 commit comments