|
10 | 10 |
|
11 | 11 | :l2-norm: image:l2.svg["l2"]-norm |
12 | 12 |
|
13 | | -[role=beta] |
14 | 13 | [[indexes-vector]] |
15 | 14 | = Vector search index |
16 | 15 |
|
17 | | -_Vector search indexes were released as a public beta in Neo4j 5.11._ |
| 16 | +_Vector search indexes were released as a public beta in Neo4j 5.11 and general availability in Neo4j 5.13._ |
18 | 17 |
|
19 | 18 | This chapter describes how to use vector indexes to perform an approximate nearest neighbor search. |
20 | 19 |
|
@@ -64,9 +63,13 @@ Returns the requested number of approximate nearest neighbor nodes and their sim |
64 | 63 | | `SHOW INDEXES WHERE type = "VECTOR"` |
65 | 64 | | Lists all vector indexes, see the xref:indexes-for-search-performance.adoc#indexes-list-indexes[`SHOW INDEXES`] command for details. There is no vector index filter built into `SHOW INDEXES`. |
66 | 65 |
|
| 66 | +| Set vector property. |
| 67 | +| {link-procedures-reference}#procedure_db_create_setNodeVectorProperty[`db.create.setNodeVectorProperty`] |
| 68 | +| label:beta[] label:new[Introduced in 5.13] Update a given node property with the given vector in a more space-efficient way than directly using xref:clauses/set.adoc#set-set-a-property[`SET`]. Replaces {link-procedures-reference}#procedure_db_create_setVectorProperty[`db.create.setVectorProperty`]. |
| 69 | + |
67 | 70 | | Set vector property. |
68 | 71 | | {link-procedures-reference}#procedure_db_create_setVectorProperty[`db.create.setVectorProperty`] |
69 | | -| Update a given node property with the given vector in a more space-efficient way than directly using xref:clauses/set.adoc#set-set-a-property[`SET`]. |
| 72 | +| label:beta[] label:deprecated[] It is replaced by {link-procedures-reference}#procedure_db_create_setNodeVectorProperty[`db.create.setNodeVectorProperty`] |
70 | 73 |
|
71 | 74 | |=== |
72 | 75 |
|
@@ -267,46 +270,57 @@ Removed 1 index. |
267 | 270 |
|
268 | 271 | ====== |
269 | 272 |
|
| 273 | +[role=beta] |
270 | 274 | [[indexes-vector-set]] |
271 | 275 | == Set a vector property on a node |
272 | 276 |
|
273 | 277 | Valid vectors for use in the index must have components finitely representable in {ieee-754} _single_ precision. |
274 | | -They are represented as properties on nodes with type `LIST<FLOAT>`. |
275 | | -The recommended way of setting a vector property is using the link:{link-procedures-reference}#procedure_db_create_setVectorProperty[`db.create.setVectorProperty`] procedure. |
276 | | -This procedure validates the input and sets the property as an array of {ieee-754} single precision values. |
| 278 | +They are represented as properties on nodes with the type `LIST<FLOAT>`. |
| 279 | +As of Neo4j 5.13, you can set a vector property using the {link-procedures-reference}#procedure_db_create_setNodeVectorProperty[`db.create.setNodeVectorProperty`] procedure. |
| 280 | +It validates the input and sets the property as an array of {ieee-754} single precision values. |
| 281 | +This beta procedure replaces {link-procedures-reference}#procedure_db_create_setVectorProperty[`db.create.setVectorProperty`]. |
| 282 | + |
| 283 | +.Signature for `db.create.setNodeVectorProperty` |
| 284 | +[source,syntax] |
| 285 | +---- |
| 286 | +db.create.setNodeVectorProperty(node :: NODE, key :: STRING, vector :: LIST<FLOAT>) |
| 287 | +---- |
277 | 288 |
|
278 | | -.Signature for `db.create.setVectorProperty` |
| 289 | +.Signature for `db.create.setVectorProperty` label:deprecated[] |
279 | 290 | [source,syntax] |
280 | 291 | ---- |
281 | 292 | db.create.setVectorProperty(node :: NODE, key :: STRING, vector :: LIST<FLOAT>) :: (node :: NODE) |
282 | 293 | ---- |
283 | 294 |
|
284 | | -Usually you want to define your embeddings as Cypher parameters and call `db.create.setVectorProperty` as in the following example: |
| 295 | +The following example shows how to define embeddings as Cypher parameters by matching a node and setting its vector properties using `db.create.setNodeVectorProperty`: |
285 | 296 |
|
286 | 297 | .Set a vector via `db.create.setVectorProperty` |
287 | 298 | [source,cypher] |
288 | 299 | ---- |
289 | 300 | MATCH (n:Node {id: $id}) |
290 | | -CALL db.create.setVectorProperty(n, 'propertyKey', $vector) |
291 | | -YIELD node RETURN node; |
| 301 | +CALL db.create.setNodeVectorProperty(n, 'propertyKey', $vector) |
| 302 | +RETURN node |
292 | 303 | ---- |
293 | 304 |
|
294 | | -The example above matches one node and updates its embedding, but it's also possible to use a list parameter containing several MATCH criterias and embeddings, to update multiple nodes in an `UNWIND` clause. |
| 305 | +Furthermore, you can also use a list parameter containing several `MATCH` criteria and embeddings to update multiple nodes in an `UNWIND` clause. |
295 | 306 | This is ideal for creating and setting new vector properties in the graph. |
296 | 307 |
|
297 | | -You can also set a vector property on a node using the xref:clauses/set.adoc#set-set-a-property[`SET`] command: |
| 308 | +You can also set a vector property on a node using the xref:clauses/set.adoc#set-set-a-property[`SET`] command as in the following example: |
298 | 309 |
|
299 | 310 | .Set a vector property via `SET` |
300 | 311 | [source,cypher] |
301 | 312 | ---- |
302 | 313 | MATCH (node:Node {id: $id}) |
303 | 314 | SET node.propertyKey = $vector |
304 | | -RETURN node; |
| 315 | +RETURN node |
305 | 316 | ---- |
306 | 317 |
|
307 | | -However, Cypher stores the provided `LIST<FLOAT>` as a primitive array of {ieee-754} _double_ precision values. |
308 | | -As a result, it takes up approximately twice as much space and it's not recommended for properties that are used in a vector index. |
309 | | -Existing properties can be re-set using `db.create.setVectorProperty` to minimize store size, but there is a cost in the transaction log size until they are rotated away. |
| 318 | +However, Cypher stores the provided `LIST<FLOAT>` as a primitive array of {ieee-754} _double_ precision values. |
| 319 | +This takes up almost twice as much space compared to the alternative method, where you use the `db.create.setNodeVectorProperty` procedure. |
| 320 | +As a result, using `SET` for a vector index is not recommended. |
| 321 | + |
| 322 | +To reduce the storage space, you can reset the existing properties using `db.create.setNodeVectorProperty`. |
| 323 | +However, this comes with the cost of an increase in the transaction log size until they are rotated away. |
310 | 324 |
|
311 | 325 | [[indexes-vector-similarity]] |
312 | 326 | == Supported similarity functions |
@@ -391,13 +405,24 @@ For example, you cannot have one xref:indexes-vector-similarity-euclidean[Euclid |
391 | 405 | [[index-vector-issues]] |
392 | 406 | == Known issues |
393 | 407 |
|
394 | | -The vector search index is a beta feature. |
395 | | -The below table lists the known issues in its current implementation. |
| 408 | +As of Neo4j 5.13, the vector search index is no longer a beta feature. |
| 409 | +The following table lists the known issues and the version in which they were fixed: |
396 | 410 |
|
397 | 411 | [%header,cols="5a,d"] |
398 | 412 | |=== |
399 | 413 | | Known issues | Fixed in |
400 | 414 |
|
| 415 | +| Querying for a _single_ approximate nearest neighbor from an index would fail a validation check. Passing a `null` value would also provide an unhelpful exception. |
| 416 | +| Neo4j 5.13 |
| 417 | + |
| 418 | +| Vector index queries throw an exception if the transaction state contains changes. This means that writes may only take place *after* the last vector index query in a transaction. |
| 419 | + |
| 420 | +[TIP] |
| 421 | +==== |
| 422 | +To work around this issue if you need to run multiple vector index queries and make changes based on the results, you can run the queries in a `+CALL { ... } IN TRANSACTIONS+` clause to isolate them from the outer transaction's state. |
| 423 | +==== |
| 424 | +| Neo4j 5.13 |
| 425 | + |
401 | 426 | | xref:clauses/listing-procedures.adoc[`SHOW PROCEDURES`] does not show the vector index procedures: |
402 | 427 |
|
403 | 428 | * {link-procedures-reference}#procedure_db_create_setVectorProperty[`db.create.setVectorProperty`] |
|
0 commit comments