From da3301614b6a11779fcd335dd6b67086c0a2b563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:19:47 +0100 Subject: [PATCH 1/4] first --- .../managing-indexes.adoc | 2 +- .../search-performance-indexes/using-indexes.adoc | 5 +++-- .../semantic-indexes/full-text-indexes.adoc | 11 +++++++++-- .../indexes/semantic-indexes/vector-indexes.adoc | 14 ++++++-------- modules/ROOT/pages/indexes/syntax.adoc | 5 +++++ 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc b/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc index acb4fcb33..4f751f7ba 100644 --- a/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc +++ b/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc @@ -1049,7 +1049,7 @@ The following statement will attempt to drop the index named `node_range_index_n [source,javascript, indent=0] ---- { - "name": "range_index_param" + "name": "node_range_index_name" } ---- diff --git a/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc b/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc index aab706148..e101bd399 100644 --- a/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc +++ b/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc @@ -346,7 +346,7 @@ This is especially beneficial when dealing with complex, large geo-spatial data, [[composite-indexes]] == Composite indexes -It is possible to create an index on a single property or multiple properties. +It is possible to create a range index on a single property or multiple properties. The latter are called composite indexes and can be useful if queries against a database frequently filter on _all_ the properties indexed by the composite index. The following example first creates a composite index on `PointOfInterest` nodes for the properties `name` and `type`, and then queries the graph using the xref:patterns/concepts.adoc#shortest-path[shortestPath function] to determine both the path length (in terms of traversed relationships in the graph) and geographical distance between the `Zoo School` and its nearest `tennis pitch` (note that there are 32 unique `PointOfInterest` `tennis pitch` nodes in the graph): @@ -360,6 +360,7 @@ CREATE INDEX composite_index FOR (n:PointOfInterest) ON (n.name, n.type) .Query with a filter on both properties indexed by the composite index [source,cypher] ---- +PROFILE MATCH (tennisPitch: PointOfInterest {name: 'tennis', type: 'pitch'}) WITH tennisPitch MATCH path = shortestPath((tennisPitch)-[:ROUTE*]-(:PointOfInterest {name: 'Zoo School'})) @@ -1005,7 +1006,7 @@ The order in which the properties are defined when creating a composite index im * A Cypher query can use several indexes if the planner deems it beneficial to the performance of a query. -* * Neo4j indexes do not store `null` values, and the planner must be able to rule out any entities with properties containing `null` values in order to use an index. +* Neo4j indexes do not store `null` values, and the planner must be able to rule out any entities with properties containing `null` values in order to use an index. There are several strategies to ensure the use of indexes. * The columns `lastRead`, `readCount`, and `trackedSince` returned by the `SHOW INDEX` command can be used to identify redundant indexes that take up unnecessary space. diff --git a/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc b/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc index 769ed3cf6..21875e4c2 100644 --- a/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc +++ b/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc @@ -31,13 +31,20 @@ CREATE (nilsE:Employee {name: "Nils-Erik Karlsson", position: "Engineer", team: == Create full-text indexes Full-text indexes are created with the `CREATE FULLTEXT INDEX` command. -An index can be given a unique name when created, which is used to reference the index when querying or dropping it. +It is recommended to to give the index a name when it is created. If no name is given when created, a random name will be assigned to the full-text index. -When creating a full-text index, you need to specify the labels/relationship types and property names it should apply to. + +The `CREATE FULLTEXT INDEX` command is optionally idempotent. +This mean that its default behavior is to throw an error if an attempt is made to create the same index twice. +If `IF NOT EXISTS` is appended to the command, no error is thrown and nothing happens should an index with the same name or same schema and index type already exist. +It may still throw an error if conflicting constraints exist, such as constraints with the same name or schema and backing index type. +As of Neo4j 5.16, the index name can also be given as a parameter, `CREATE FULLTEXT INDEX $name FOR ...`. [TIP] Creating a full-text index requires the link:{neo4j-docs-base-uri}/operations-manual/{page-version}/authentication-authorization/database-administration/#access-control-database-administration-index[`CREATE INDEX` privilege]. +When creating a full-text index, you need to specify the labels/relationship types and property names it should apply to. + This statement creates a full-text index named `namesAndTeams` on each `name` and `team` property for nodes with the label `Employee` or `Manager`: .Create a full-text index on a node label and property combination diff --git a/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc b/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc index a37e482a8..f2f17abc7 100644 --- a/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc +++ b/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc @@ -11,7 +11,7 @@ :l2-norm: image:l2.svg["l2"]-norm [[indexes-vector]] -= Vector search index += Vector search indexes _Vector search indexes were released as a public beta in Neo4j 5.11 and general availability in Neo4j 5.13._ @@ -93,10 +93,6 @@ A vector index is a single-label, single-property index for nodes. A vector index needs to be configured with both the dimensionality of the vector (`INTEGER` between `1` and `2048` _inclusive_), and the measure of similarity between two vectors (case-insensitive `STRING`). For details, see xref:#indexes-vector-similarity[]. -[NOTE] -==== -More details about the syntax descriptions can be found link:{neo4j-docs-base-uri}/operations-manual/{page-version}/database-administration/syntax/#administration-syntax-reading[here]. -==== .Syntax for creating vector indexes [options="header", width="100%", cols="5a, 3"] @@ -296,8 +292,6 @@ A vector index is dropped by using the xref:indexes/search-performance-indexes/m Dropping a vector index requires link:{neo4j-docs-base-uri}/operations-manual/{page-version}/authentication-authorization/database-administration/#access-control-database-administration-index[the `DROP INDEX` privilege]. -Dropping a vector index requires link:{neo4j-docs-base-uri}/operations-manual/{page-version}/authentication-authorization/database-administration/#access-control-database-administration-index[the `DROP INDEX` privilege]. - .+DROP INDEX+ ====== @@ -343,7 +337,7 @@ db.create.setVectorProperty(node :: NODE, key :: STRING, vector :: LIST) The following example shows how to define embeddings as Cypher parameters by matching a node and setting its vector properties using `db.create.setNodeVectorProperty`: -.Set a vector via `db.create.setVectorProperty` +.Set a vector via `db.create.setNodeVectorProperty` [source,cypher] ---- MATCH (n:Node {id: $id}) @@ -459,6 +453,10 @@ The following table lists the known issues and the version in which they were fi |=== | Known issues | Fixed in +| Vector indexes cannot be assigned autogenerated names. + +| Neo4j 5.15 + | There is no Cypher syntax for creating a vector index. [TIP] diff --git a/modules/ROOT/pages/indexes/syntax.adoc b/modules/ROOT/pages/indexes/syntax.adoc index 777ef49de..52cf1d6b7 100644 --- a/modules/ROOT/pages/indexes/syntax.adoc +++ b/modules/ROOT/pages/indexes/syntax.adoc @@ -4,6 +4,8 @@ This page contains the syntax for creating, listing, and dropping the indexes available in Neo4j. It also contains the signatures for the procedures necessary to call in order to use full-text and vector indexes. +More details about the syntax can be found in the link:{neo4j-docs-base-uri}/operations-manual/{page-version}/database-administration/syntax/[Operations Manual -> Cypher syntax for administration commands]. + [[create-index]] == CREATE INDEX @@ -263,6 +265,9 @@ The `query` vector refers to the `LIST` in which to search for the neighb [[drop-index]] == DROP INDEX +The `DROP INDEX` command can drop indexes of all types using their name. +The name of the index can be found using the `SHOW INDEXES` command, given in the output column `name`. + The `DROP INDEX` command is optionally idempotent. This means that its default behavior is to throw an error if an attempt is made to drop the same index twice. With `IF EXISTS`, no error is thrown and nothing happens should the index not exist. From 8a00febdcc8c3dd4b4f408bd3b1c9a5d786f3267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:40:37 +0100 Subject: [PATCH 2/4] composite --- .../indexes/search-performance-indexes/using-indexes.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc b/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc index e101bd399..21f28a242 100644 --- a/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc +++ b/modules/ROOT/pages/indexes/search-performance-indexes/using-indexes.adoc @@ -346,7 +346,7 @@ This is especially beneficial when dealing with complex, large geo-spatial data, [[composite-indexes]] == Composite indexes -It is possible to create a range index on a single property or multiple properties. +It is possible to create a range index on a single property or multiple properties (text and point indexes are single-property only). The latter are called composite indexes and can be useful if queries against a database frequently filter on _all_ the properties indexed by the composite index. The following example first creates a composite index on `PointOfInterest` nodes for the properties `name` and `type`, and then queries the graph using the xref:patterns/concepts.adoc#shortest-path[shortestPath function] to determine both the path length (in terms of traversed relationships in the graph) and geographical distance between the `Zoo School` and its nearest `tennis pitch` (note that there are 32 unique `PointOfInterest` `tennis pitch` nodes in the graph): @@ -539,7 +539,7 @@ These rules can be important when creating composite indexes, as some checks are For instance, it is generally more efficient for the planner to perform an equality check on a property than an existence check. Depending on the queries and the application, it may, therefore, be cost-effective to consider the order in which properties are defined when creating a composite index. -Additionally, it bears repeating that composite indexes can only be used if a predicate filters on all the properties indexed by the composite index, and that composite indexes can only be created for range indexes (point and text indexes are single-property only). +Additionally, it bears repeating that composite indexes can only be used if a predicate filters on all the properties indexed by the composite index, and that composite indexes can only be created for range indexes. [[range-index-backed-order-by]] == Range index-backed ORDER BY From 4b8ff635ee6895dd323bb975b16e978d5c937c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:13:38 +0100 Subject: [PATCH 3/4] remove name bullet point --- .../ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc b/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc index f2f17abc7..7c41bfe98 100644 --- a/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc +++ b/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc @@ -431,9 +431,6 @@ The requested _k_ nearest neighbors may not be the exact _k_ nearest, but close * For large requested nearest neighbors, _k_, close to the total number of indexed vectors, the search may retrieve fewer than _k_ results. -* The index must have a unique name. -There is no provided method for an autogenerated name. - * Only one vector index can be over a schema. For example, you cannot have one xref:indexes-vector-similarity-euclidean[Euclidean] and one xref:indexes-vector-similarity-cosine[cosine] vector index on the same label-property key pair. From 70b03d862a37a38f6678641870bb29d3b9b7407c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:56:46 +0100 Subject: [PATCH 4/4] post review update --- .../indexes/search-performance-indexes/managing-indexes.adoc | 4 ++-- .../pages/indexes/semantic-indexes/full-text-indexes.adoc | 5 +---- .../ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc b/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc index 4f751f7ba..e484fcfae 100644 --- a/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc +++ b/modules/ROOT/pages/indexes/search-performance-indexes/managing-indexes.adoc @@ -1043,13 +1043,13 @@ If an index with that name exists it is removed, if not the command fails. _This feature was introduced in Neo4j 5.16._ -The following statement will attempt to drop the index named `node_range_index_name` using a parameter for the index name. +The following statement will attempt to drop the index named `range_index_param` using a parameter for the index name. .Parameters [source,javascript, indent=0] ---- { - "name": "node_range_index_name" + "name": "range_index_param" } ---- diff --git a/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc b/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc index 21875e4c2..cf199c306 100644 --- a/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc +++ b/modules/ROOT/pages/indexes/semantic-indexes/full-text-indexes.adoc @@ -36,8 +36,7 @@ If no name is given when created, a random name will be assigned to the full-tex The `CREATE FULLTEXT INDEX` command is optionally idempotent. This mean that its default behavior is to throw an error if an attempt is made to create the same index twice. -If `IF NOT EXISTS` is appended to the command, no error is thrown and nothing happens should an index with the same name or same schema and index type already exist. -It may still throw an error if conflicting constraints exist, such as constraints with the same name or schema and backing index type. +If `IF NOT EXISTS` is appended to the command, no error is thrown and nothing happens should an index with the same name or a full-text index on the same schema already exist. As of Neo4j 5.16, the index name can also be given as a parameter, `CREATE FULLTEXT INDEX $name FOR ...`. [TIP] @@ -69,8 +68,6 @@ This statement creates a full-text index named `communications` on the `message` CREATE FULLTEXT INDEX communications FOR ()-[r:REVIEWED|EMAILED]-() ON EACH [r.message] ---- -Full-text indexes follow the same xref:indexes/index.adoc#naming-rules-and-recommendations[naming rules and best-practices] as search-performance indexes. - [[tokenization-analyzers]] === Tokenization and analyzers diff --git a/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc b/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc index 7c41bfe98..e867a33a1 100644 --- a/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc +++ b/modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc @@ -342,7 +342,7 @@ The following example shows how to define embeddings as Cypher parameters by mat ---- MATCH (n:Node {id: $id}) CALL db.create.setNodeVectorProperty(n, 'propertyKey', $vector) -RETURN node +RETURN n ---- Furthermore, you can also use a list parameter containing several `MATCH` criteria and embeddings to update multiple nodes in an `UNWIND` clause.