Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index chapter clean up #840

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ 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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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):
Expand All @@ -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'}))
Expand Down Expand Up @@ -538,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
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ 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 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]
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
Hunterness marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -62,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

Expand Down
19 changes: 7 additions & 12 deletions modules/ROOT/pages/indexes/semantic-indexes/vector-indexes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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+
======

Expand Down Expand Up @@ -343,12 +337,12 @@ db.create.setVectorProperty(node :: NODE, key :: STRING, vector :: LIST<FLOAT>)

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})
Hunterness marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -437,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.

Expand All @@ -459,6 +450,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]
Expand Down
5 changes: 5 additions & 0 deletions modules/ROOT/pages/indexes/syntax.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -263,6 +265,9 @@ The `query` vector refers to the `LIST<FLOAT>` 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.
Expand Down