Vector index are not part of the standardized OpenCypher specification and should be considered an extension.

Support for vector_index was added to GQLite 1.7.

Create index

Index are created using the CREATE VECTOR INDEX statement:

CREATE VECTOR INDEX index_name ON :label (property_name) OPTIONS { dimension: size, metric: "cosine" }

This will create a vector index for all node with the label label and index their property_name as a vector of dimension size. The metric is optional, supported metrics are cosine, l2 and dot_product.

The SEARCH statement is used to search for nodes in an index, it should be combined with MATCH:

MATCH (n)
SEARCH n IN (VECTOR INDEX index_name FOR [vector] LIMIT N)
RETURN n

This will search for the nodes in the given index which have the closest vector compares to the given vector, with a limit of returning the N closest nodes.

Examples

First we will create a few nodes:

CREATE (:Article { id: 1, embedding: [0.1, 0.1, 0.1], category: "tech" })
CREATE (:Article { id: 2, embedding: [0.9, 0.9, 0.9], category: "sports" })
CREATE (:Article { id: 3, embedding: [0.2, 0.2, 0.2], category: "tech" })
CREATE (:Article { id: 4, embedding: [0.8, 0.8, 0.8], category: "sports" })

Then we create an index:

CREATE VECTOR INDEX article_idx ON :Article (embedding)
OPTIONS { dimension: 3, metric: "cosine" }

And then we can use to match for nodes:

MATCH (n:Doc)
SEARCH n IN (VECTOR INDEX doc_idx FOR [0.1, 0.2, 0.3] LIMIT 1)
RETURN n.title

This will then return:

| n.title | +———+ | doc1 |