Property Indexes

g.v().has_label("person").has("title", "CEO") reads every person vertex and compares its title. On a large graph that dominates the query time even when only a few vertices match. A property index orders the elements of one label by the value of one property, so the same query reads only the matching vertices.

// Declare: the `person` vertices, ordered by `age`.
g.create_index(#{label: "person", key: "age"});

// Served: equality, P.within and ranges on `age` after has_label("person").
g.v().has_label("person").has("age", 29).values("name").to_list();
g.v().has_label("person").has("age", P.between(30, 40)).values("name").to_list();

g.indexes()                                  // the indexes and what they hold

Without label an index is label-less: it holds every vertex (or edge) and also serves g.v().has("name", "josh") without a label. With transform: "each" an index holds every element of a list value, so "all nodes of one owner", g.v().has("_owners", __.unfold().is(o)), reads it. With unique: true an index is a unique constraint: a write that would repeat one of its values fails.

Indexes are declared, never automatic: nothing is indexed until you ask for it, and an index costs memory and a little time on every write of its key (below).

Declare, list, drop

DSLRust (GraphTraversalSource)Python (Graph)
g.create_index(#{key, label?, element?, name?, type?, transform?, unique?}) / g.create_index(..)create_index(name, PropertyIndexDefinition::new(kind, label, key)) (label-less: PropertyIndexDefinition::label_less(kind, key)), .with_type(PropertyIndexType::MemoryOrdered), .with_transform(Some(PropertyIndexTransform::ToLower)) (Each; a chain: PropertyIndexTransform::from_names(["each", "to_lower"])), .with_unique(true)graph.create_index(label, key, element="vertex", name=None, type="memory-ordered", transform=None, unique=False) (label=None: label-less; transform="each", transform=["each", "to_lower"])
g.indexes()list_indexes()graph.indexes()
g.drop_index(name)drop_index(name)graph.drop_index(name)
  • element is "vertex" (the default) or "edge"; label is one vertex or edge label (it need not exist yet), or omitted (()) for a label-less index; key is one top-level property name (a plain name, not a jpath: nested values are not indexed).
  • name defaults to <label>_<key> (<key> for a label-less index), then _edge for an edge index, then _to_lower for an index with the transform to_lower (person_name_to_lower, knows_note_edge_to_lower), _each or _each_to_lower for the each transforms (index__owners_each for a label-less index on _owners), with every character that is not a letter, a digit or _ replaced by _, and index_ in front when it would not start with a letter. It is an identifier like a saved query's name. The DSL, the session, the dev server, MCP and Python use this default; the playground's form shows it as the name's placeholder and follows the Transform choice until a name is typed.
  • type is the index type, "memory-ordered" by default (the only type this version knows).
  • transform is the transform of the index keys: absent (the default) for the values themselves, "to_lower" for case-insensitive search, "each" for the elements of a list, or a chain written as an array of names applied in order: ["each", "to_lower"] (the only chain this version serves; ["to_lower", "each"] is refused).
  • unique (false by default) makes the index a unique constraint; it does not change the default name.
  • One index per (element, label, key, type, transform): a second one under another name fails with a Conflicting property index error that names the first. A plain index and a to_lower index on the same key coexist (their default names differ), and so do a label-less and a per-label index on one key. Declaring the same name again replaces the index (also a per-label index by a label-less one of the same name, and back: index names are one namespace). unique is not part of that identity: to make an index unique, declare it again under its name with unique: true.
  • g.indexes() lists each index (by name) with its label (() for a label-less index), its type, its transform (() without one, a chain as the array of its names), unique, served (whether it is served, with a reason when it is not: see unknown types, repeated values under a unique index and other storages) and its current entries (indexed elements; with each one per distinct element of a list), distinct_values, skipped (elements whose non-null value the index does not hold; with each list elements it does not hold) and bytes (an estimate of its memory).
g.create_index(#{element: "edge", label: "knows", key: "weight"});
g.e().has_label("knows").has("weight", P.gt(0.6)).count().next()

Label-less indexes

An index declared without label holds every element of its kind, unlabeled ones included (a vertex with several labels once):

g.create_index(#{key: "name"});                        // named `name`
g.create_index(#{element: "edge", key: "weight"});     // named `weight_edge`

g.v().has("name", "josh").values("age").to_list();     // no label: reads the index
g.v().has("name", "josh").count().next();              // counted from the index
g.e().has("weight", P.gt(0.5)).count().next()
  • A v()/e() without labels reads it for the same conditions a per-label index serves (below), and so does a MATCH (n {name: $x}) node pattern without a label in GQL (the root scan and a correlated lookup).
  • A source with labels reads it when no per-label index covers its labels, or when it is cheaper by the index statistics (an equality reads about entries / distinct_values of the label-less index, against the sum over the per-label indexes; a tie keeps the per-label ones); the source then keeps only the candidates carrying one of its labels.
  • .profile() names it with any label, also under a labelled source: v(labels: ["person"]).has("name", "josh") [index: vertex name, any label], and with a transform [index: vertex name to_lower, any label].
  • It costs the memory of every element of the kind holding the key; a per-label index on the same key keeps its entries a second time (the advisor points this out).
  • Persistence: it is stored as catalog kind property_index_ext (6) with the critical flag (plain per-label indexes stay kind property_index), so a version that does not know it (0.5.x and older) opens such a store read-only instead of writing it without maintaining the index. The schema check looks at every label of its element kind that declares the key.

Counting from an index

A count() right after a start step whose one condition an index answers exactly is counted from the index without visiting the elements: one equality (a folded has(key, value), has(key, P.eq(..)), the each point has(key, __.unfold().is(..)) or a to_lower point) with a string, boolean, uuid or temporal value, no other condition, and either a label-less index under a start without labels or the index of the start's one label. .profile() shows [count from index]:

v().has("name", "josh").count() [index: vertex name, any label, exact] [count from index]
v().has("_owners", __.unfold().is(P.eq("o1"))).count() [index: vertex _owners each, any label, exact] [count from index]

A number (ranged by its float64 value), null, a range, P.within, a second condition, a label to check or a whole-value condition read from an each index (a superset) falls back to counting the candidates of the index read.

Index types

Every index has a type (the key type): how it keeps its entries, which values it holds and which conditions it serves. This version knows one type, and it is the default:

TypeWhat it isServes
memory-orderedan ordered index kept in memory; its entries are derived from the data and rebuilt whenever the graph is loaded (below)equality, P.within and the ranges (below)

Which value types an index holds (Rust: PropertyIndexType::holds for the type, PropertyIndexTransform::accepts for the transform, both combined by PropertyIndexDefinition::holds, the one place the engine and the front ends take it from):

Value typememory-orderedwith to_lowerwith eachwith ["each", "to_lower"]
null, booleanyesnoyesno
int64, float64yes (ranged by their value as float64)noyesno
string (also a compressed one, by its text)yesyes, by its lowered textyesyes, by its lowered text
uuidyesnoyesno
date, localdatetime, datetime, time, durationyesnoyesno
array (a list)nonoby its elements (the scalar ones, each once)by its string elements, lowered
object (a map)nononono
vectorno (vectors are searched with nearest() and similarity())nonono

A value the index does not hold is skipped: the element is not in the index, and a condition on such a value is answered by a scan, so results never change.

g.create_index(#{label: "person", key: "age", type: "memory-ordered"})   // the default, spelled out
g.create_index(#{label: "person", key: "age", type: "hash"})   // refused: not a type this version knows

Checked against the schema when created

When the graph's stored schema declares the key at the top level of the index's label (a vertex label for a vertex index, an edge label for an edge index) and none of the declared types, null aside, can be held by the index (for the type a vector, a list, a map, or an anyOf of only such; with the transform to_lower every type but string; with each a map, a vector, or a list whose items declare only such; with ["each", "to_lower"] anything but a string or a list of strings), creating the index is refused, with a message that names the label, the key, the declared type and the index type:

// refused: the schema declares `embedding` as a vector
{
  g.set_schema(#{mode: "open", vertices: #{doc: #{schema: #{type: "object", properties: #{
    embedding: #{type: "array", format: "vector", element: "f32"}}}}}});
  g.create_index(#{label: "doc", key: "embedding"})
}
Error: Cannot create a property index on vertex 'doc' key 'embedding': the schema declares
'embedding' as vector<f32>, and an index of type 'memory-ordered' holds none of its values
Help: Vectors are not index keys: search them with nearest() or similarity() (an exact search,
book page "Vectors"), for example g.v().has_label("doc").nearest("embedding", query, 10) for the
10 closest; a vector index type is planned. ...

With to_lower the message says an index of type 'memory-ordered' with the transform 'to_lower' holds none of its values, and the help suggests a plain index or a string property. For a list or a map the help suggests indexing a scalar top-level property instead (an index key is one top-level name; nested fields are not indexed), and for a list the each transform. A list whose items declare no type is fine for each. A declaration with at least one type the index holds (anyOf of a list and a string, ["string", "null"]), a key the schema does not declare, a label it does not declare, and a graph without a schema are all accepted. The schema's mode does not matter (a declaration in mode none counts too). The playground's form shows the refusal under its Key field.

The check runs when an index is created (the DSL, GraphTraversalSource::create_index, Python, the playground, the dev server and MCP), never when a definition is stored as it is: set_definition, apply_change_set, a replay or recovery, a catalog file or a snapshot load keep what they carry. A later schema change never drops an index: an index whose key the schema later declares as a vector stays and simply holds nothing of it.

An index type from a newer version

A store (or a catalog file, a change set) written by a newer Graphersal may hold an index of a type this version does not know. Such a definition is never damage: it is kept in the catalog exactly as read and written back unchanged (its payload byte for byte through the journal, checkpoints, backups, forks and snapshots), but it is not served: no entries are built, the optimizer never reads it, and g.indexes() (and the playground, the dev server and MCP's list_indexes) shows it with served: false and a reason such as index type 'x' is not known to this version. It can be dropped like any index. Creating or redefining an index of an unknown type is refused with an error whose help lists the known types. Indexes of different types may cover the same (element, label, key). A transform this version does not know is handled the same way: kept byte for byte, built and served never, listed with the reason index transform 'x' is not known to this version, refused when created (the field transform). So is an element kind other than vertex and edge (since 0.2.1; g.indexes() shows the name as read, the reason element kind 'x' is not known to this version, refused when created with the field element).

An index can carry a transform (the key transform): its keys are then the transformed values, and it serves a condition that applies the same transform before comparing. This version knows one transform, to_lower, named after the step to_lower(): the index key is the lowered text of a string value, computed by exactly the function the step uses (Rust's str::to_lowercase: Unicode, no locale), so the index and the scan never disagree. The query form is TinkerPop's has(key, traversal): has("name", __.to_lower().is(x)) keeps the elements whose lowered name is x.

g.v("1").property("name", "MARKO").iterate();
g.create_index(#{label: "person", key: "name", transform: "to_lower"});   // person_name_to_lower

// Served: the lowered value against the constants, equality, P.within and the ranges.
g.v().has_label("person").has("name", __.to_lower().is("marko")).values("name").to_list();
g.v().has_label("person").has("name", __.to_lower().is(P.within("josh", "vadas"))).count().next();
g.v().has_label("person").has("name", __.to_lower().is(P.gte("p"))).values("name").to_list();

// The constant is compared AS GIVEN with the lowered value: write it in lower case.
g.v().has_label("person").has("name", __.to_lower().is("Marko")).count().next()   // 0

What is served and what is not:

  • Served: v()/e() with a folded has_label(..) (every label with a to_lower index on the key), followed in the run of pure filters by has(key, __.to_lower().is(P)) with P a value, P.eq, P.within or a range (P.gt/gte/lt/lte/between/inside/outside). .profile() shows [index: vertex person.name to_lower] on the start step; for a range the has step stays in the plan and re-checks every candidate, a point (a value, P.eq, P.within) is answered exactly in a query that does not write: the has step leaves the plan, v(labels: ["person"]).has("name", __.to_lower().is(P.eq("marko"))) [index: vertex person.name to_lower, exact].
  • Not served (a scan, the same result): any other child (__.is("x") without to_lower(), __.to_upper(), __.to_lower(Scope.local), more steps after is(..), P.neq, text predicates), where(__.values("name").to_lower().is(..)), a jpath key, a source without has_label. The constant is never lowered for you: is("Marko") matches nothing.
  • Only strings are in the index; null and a missing key are not. Because to_lower() fails on any other value (an int64 name, a list), such a value must make the query fail as the scan does: while the index has skipped a non-null, non-string value (g.indexes() shows skipped), queries do not read it and scan, with the step's error. Remove or convert those values and the index is served again.
  • A plain index and a to_lower index on the same key coexist: has("name", "Marko") reads the plain one, has("name", __.to_lower().is("marko")) the lowered one. A to_lower index never serves a plain has("name", "marko").
  • Creating one on a key the schema declares as a non-string type only (an integer) is refused with a message naming the transform; a union with string is fine (below).
  • An unknown transform (written by a newer version) is kept byte for byte and listed as not served (below).

Arrays: the each transform

A list value is one value (Graphersal has no multi-properties): has("_owners", "o1") compares the whole list, and "the elements whose list holds o1" is written with TinkerPop's has(key, traversal): has("_owners", __.unfold().is("o1")). An index with the transform each holds one entry per element of a list value, so that query reads it instead of every element:

g.v("1").property("_owners", ["o1", "o2"]).iterate();
g.v("2").property("_owners", ["o2"]).iterate();
g.v("4").property("_owners", "o1").iterate();                  // a scalar: one entry
g.create_index(#{key: "_owners", transform: "each"});           // named index__owners_each

g.v().has("_owners", __.unfold().is("o1")).values("name").to_list();
g.v().has_label("person").has("_owners", __.unfold().is(P.within("o1", "o2"))).count().next();
g.v().has("_owners", "o1").values("name").to_list()           // the whole value: josh only
  • Entries: one per element of a list, an element held twice once (["x", "x"] is one entry); a scalar value gives its one entry, as unfold() emits it; an empty list none. A nested list, a map or a vector inside the list is not a key and counts in skipped (one per such element), and so does a map or a vector value itself.
  • Served exactly: has(key, __.unfold().is(P)) with P a value, P.eq, P.within or a range, whatever the index skipped: what unfold() emits for a skipped value (a nested list, the entries of a map, a vector) never equals or ranges with a scalar constant. For a point of a string, boolean, uuid or temporal value (P.within of such values too) the has step leaves the plan and the start shows it: v().has("_owners", __.unfold().is(P.eq("o1"))) [index: vertex _owners each, any label, exact] (per label [index: vertex Method._owners each, exact]; see Kept exact); a range, a number or null keeps the has step, which re-checks.
  • Served as a superset: a condition on the whole value, has(key, value) and has(key, P), reads an each index when no index without a transform covers the key: the lists holding the value are candidates too, and the re-check of the whole value drops them. A plain index on the same key is preferred for those conditions.
  • The chain ["each", "to_lower"] holds the lowered text of every string element and serves has(key, __.unfold().to_lower().is(P)) ([index: vertex tags each to_lower, any label]), like to_lower only while it skipped nothing (a number in a list makes to_lower() fail, and the scan must report it); a point is then answered exactly, like to_lower's. A to_lower transform never serves a null constant (to_lower() passes a null through, the index holds none).
  • Not served: __.unfold().unfold().is(..), __.to_lower().unfold().. (the wrong order), negations and text predicates, GQL's x IN n.list (a gql:filter expression: a right operand that is not a list is an error there, so it scans).
  • A storage lookup returns each element once even when it holds several values of the slice (["a", "b"] in P.between("a", "c"), or 1 and 1.0); a fused count() is answered from an each index only for one exact point (above).
  • Persistence: an index with each is stored as catalog kind property_index_ext (6) with the critical flag, also with a label, so a version that does not know it opens the store read-only. The payload keeps a single transform as its name and a chain as the array of its names ("transform": ["each", "to_lower"]).
  • Memory: about 4 bytes per element entry after a build for a key with few distinct values (an owner).
  • The advisor recommends transform: "each" for a scanned key holding lists.

Unique indexes

With unique: true an index is a constraint: no two elements of the index hold an equal value of its key. A write that would give an element a value the index already holds for another element fails, and the query (or import, or applied change set) rolls back as a whole:

g.create_index(#{label: "person", key: "name", unique: true});
g.v("2").property("name", "marko").iterate()      // vertex 1 holds "marko" already
Error: The unique index 'person_name' already holds "marko" at 'name' for the vertex '1'
  • Scope: a per-label index is unique within its label (person and software may share a name); a label-less one over the whole element kind (every vertex, or every edge); with transform: "to_lower" the comparison is case-insensitive (logins, e-mail addresses: "Ann" and "ann" collide).
  • Equality is has()'s: an int64 and a float64 of the same value collide (1 and 1.0), two int64s only when they are the same number, a datetime by its instant.
  • null is not part of uniqueness: any number of elements may hold null (or lack the key).
  • Values the index does not hold are exempt as well: a list, a map or a vector under a plain unique index, a non-string under to_lower. They count in skipped, as for any index.
  • Every write path is checked: add_v()/add_e() with their properties, property() on an existing element (also a one-segment jpath), merge_v()/merge_e() when they create or change, GQL INSERT, SET and MERGE, add_label() and GQL SET n:Label when they bring a vertex into a per-label unique index, GraphSON and GraphML imports, apply_change_set. Nothing of the failing unit stays.
  • The check is immediate, at each write, never deferred to the commit. Swapping the values of two elements in one query therefore needs an intermediate value:
g.create_index(#{label: "person", key: "name", unique: true});
// Vertex 2 can take "marko" only after vertex 1 has let it go: through "tmp".
g.v("1").property("name", "tmp").v("2").property("name", "marko").v("1").property("name", "vadas").iterate();
g.v("1").values("name").next()
  • A compacted change set may not apply. ChangeSet::compact() keeps only the net effect, so the intermediate value of such a swap is gone: applying the compacted set with apply_change_set gives the first element the value the second still holds, and the unit is refused with a unique violation (nothing applied). Apply the uncompacted change set instead; a journal replay and a recovery always use the uncompacted, ordered writes.
  • A unique index is an ordinary index for queries: equality, P.within and ranges read it, and a point lookup returns at most one element.
  • Not with each: a unique index cannot use the transform each (a list gives one key per element); the create is refused.
  • Persistence: a unique index is stored as catalog kind property_index_ext (6) with the critical flag, also with a label (a version that does not know it opens the store read-only, so it never writes past the constraint). The payload has "unique": true (absent when false). A journal replay and a recovery apply only writes that were checked when they were committed.

Created over repeated values

Creating a unique index over data that already holds a value twice is refused, and nothing is created. The error names up to 10 repeated values, each with its count and up to 3 example ids, and its help gives the query that lists all of them:

Error: Cannot create the unique index 'User_email': 2 value(s) of 'email' are held by more than one vertex labelled 'User': "a@x" (2 elements: 1, 7), "b@x" (3 elements: 2, 8, 9)
Help: ... List every repeated value with its count: g.v().has_label("User").has("email").group_count().by("email").unfold().where(__.select(Column.values).is(P.gt(1))). ...

With to_lower the query groups by the lowered value (.group_count().by(__.values("email").to_lower())). Give the repeated elements other values (or drop the extra ones), then create the index again.

Stored over repeated values

Storing a definition never checks the data (set_definition, a catalog file, a journal replay, a store load). A unique index whose data holds repeated values (a store written past the constraint, an index stored without the create check) is kept, but neither served nor enforced: g.indexes() lists it with served: false and a reason that starts with duplicates: and names the values, the open of a store writes the system journal event index.unique_duplicates (see System Journal), and the open never fails for it. The fix: remove the repeats, then drop the index and create it again (GraphStorage::unique_index_duplicates returns the report to a host).

What is served

A v()/e() start step reads an index when

  • it is the start of the traversal (or of a child traversal), the optimizer folded a has_label(..) into it, and every folded label has an index on the key: the index of has_label("person"), or of has_label("person", "employee") when both labels have one; or a label-less index covers the key (with or without folded labels);
  • and a has() on the indexed key follows directly (only has(), has_label(), has_id(), has_key(), has_not() in between):
ConditionServed
has(key, value)equality
has(key, P.eq(v)), has(key, P.within(a, b, ..))one slice per value
has(key, P.gt/gte/lt/lte(v))one range
has(key, P.between(a, b)), P.inside(a, b)one range
has(key, P.outside(a, b))two ranges
P.neq, P.without, text predicates, P.typeOf, and/or/not compositesnot served (scan)
a value that is a list or a map (has("tags", ["a"]))not served (scan)
has(key, __.unfold().is(P))by an each index
a point (value, P.eq, P.within) of a string, boolean, uuid or temporal value, without a transform or by eachexactly: no re-check (Kept exact)
has(key, value), has(key, P) with only an each index on the keyby it, as a superset (re-checked)
v().has("title", "CEO") without a labelserved by a label-less index only
a jpath keynot served (scan)

With several served conditions the optimizer picks the most selective index from the index statistics (an equality reads about entries / distinct_values elements of each label, a range about half the entries).

Results are the same as without the index, always: the index returns a superset of the matching elements (numbers are ranged by their value as float64, so 29 and 29.0 are both read), and the start step and the has() step still check every condition on each candidate, except the one condition the index answers exactly, which no longer needs it. The comparison is exactly that of has(): has("age", 29) matches an int64 29 only, has("age", P.eq(29.0)) and the ranges compare numbers across int64 and float64, a string never equals a uuid, null equals only null. Dates and times are index keys with the same rules (Comparing and Sorting): each of date, localdatetime, datetime, time and duration is its own kind (a date never equals a datetime or a string, and a range reads only values of its bounds' type), a datetime is keyed by its instant (12:00Z and 14:00+02:00 are one key), and a duration is keyed by all its fields (P1M and P30D are two keys) and ranged by its length, a month as 30 days, ties broken by the fields: equality, P.within and every range on durations are served. Only the order of the elements may differ (the index reads them by value): use order() when the order matters.

A string operand of has(key, P) is always a value, also inside a child traversal and after an as() of the same spelling (only where(P.eq("a")) names a path label), so P.eq("a") is served wherever the start step is.

See it in .profile()

The start step names the index it reads, and the rule property_index is listed:

$ graphersal -e 'g.create_index(#{label: "person", key: "age"})' \
             -e 'g.v().has_label("person").has("age", P.gt(30)).values("name").profile()'
Traversal Metrics
Step                                                         Call      In     Out       Time    % Dur
=====================================================================================================
v(labels: ["person"]) [index: vertex person.age]                1       0       2   55.666µs     7.53
has("age", P.gt(30))                                            1       2       2   42.625µs     5.77
values("name")                                                  1       2       2    1.834µs     0.25
                                                      TOTAL:             execute:  738.958µs    13.55
=====================================================================================================
Optimizer rules applied: source_filter_pushdown, property_index

The range keeps its has step, which re-checks every candidate. A condition the index answers exactly adds , exact inside the brackets: an equality folded into the start step shows as v(labels: ["person"]).has("title", "CEO") [index: vertex person.title, exact] (the start step does not check it again), and a has step it answers leaves the plan and is shown on the start step:

v().has("_owners", __.unfold().is(P.eq("o1"))) [index: vertex _owners each, any label, exact]
out()

To compare with the scan, turn the rule off for one query: g.with("optimizer.disabled", ["property_index"]) (see Property Index Rule).

Kept exact

An index is maintained on every write: adding and dropping elements (a vertex drop takes its edges out of the edge indexes), writing and removing the key (also through a jpath write that changes it), adding and removing a vertex label (a vertex with several labels is in the index of each of them), changing an edge label. A rolled-back unit restores the index with the data; replay, apply_change_set and a store's recovery rebuild it exactly. A string kept compressed is indexed by its text (the index holds the plain text, so indexing a long compressed field costs the memory compression saved).

Because it is kept exact, the index answers some conditions instead of narrowing them: a point (has(key, value), P.eq, P.within) of a string, boolean, uuid or temporal value read from an index without a transform, the same point inside has(key, __.unfold().is(..)) read from an each index, or inside has(key, __.to_lower().is(..)) / has(key, __.unfold().to_lower().is(..)) read from a to_lower / ["each", "to_lower"] index while it skipped nothing (every value is then a string, to_lower() cannot fail, and nothing writes during a reading query), finds exactly the elements the condition accepts, each once. In a query that does not write (no mutating step at any level), the optimizer then drops the re-check of that one condition: a folded equality is not checked again on the candidates, a has step is removed from the plan, and .profile() marks the access exact. Every query form gains, not only count(): .id().to_list(), .values(..), a traversal from the found elements. Everything else is still checked: the other conditions, the labels when a label-less index serves a start with labels, ranges, numbers (a slice spans int64 and float64), null, a whole-value condition read from an each index (a superset), a to_lower index that skipped a value (it is not read at all), and every condition of a query that writes. The index is trusted on purpose: a wrong entry would show in the result instead of being hidden by a re-check, and the randomized differential tests compare every exact shape with the scan. A custom storage opts in with StorageCapabilities::exact_property_index_lookups.

Persistence

An index is a catalog definition (kind property_index, or property_index_ext with the critical flag for a label-less index, a unique index and an index with each, like saved queries and compression rules), so its declaration travels with the graph: the journal (WAL), snapshots, backups, forks, rollbacks and the catalog file. Its entries are never stored: they are rebuilt from the data whenever a graph is loaded, by a store open, a read-only view (also of a past state), a backup open, a recovery, a snapshot load. A read-only view is therefore always consistent with the data it shows. GraphML and GraphSON files carry no catalog, so no index.

Memory

An index keeps each distinct value once (strings longer than 24 bytes on the heap), with about 48 bytes of ordered-map bookkeeping, and the elements holding it as a sorted list of 4-byte element slots: a value held by one element keeps it inline, a value held by many costs about 4 bytes per element after a build and at most about 8 bytes once later writes have grown the list. A key with few distinct values (an owner, a status) is therefore cheap; a near-unique key (a name, a hash) costs about one map entry per element. g.memory_usage() reports the indexes as property_index_bytes (part of total_bytes, so the memory budget sees them), g.indexes() per index. Building an index reads every element of its label once.

Other storages

Indexes are a capability of the storage (StorageCapabilities::property_indexes); the built-in graph has it. On a custom storage without it, create_index fails with unsupported: property indexes; an index definition can still be stored in its catalog (a catalog file loaded into it, say) and is listed with served: false, but no query reads it. A storage that serves indexes implements GraphStorage::property_indexes and the lookups vertices_by_property_index/edges_by_property_index, and for indexes with a transform vertices_by_transformed_property_index/edges_by_transformed_property_index (reporting PropertyIndexStats::skipped, which the optimizer reads before it uses a to_lower index; an each lookup returns each element once, deduplicating an element held under several keys of the slice). The lookups take the label as Option<&str>: None reads the label-less index (PropertyIndexInfo::label is None for one). count_by_property_index (default Ok(None)) answers an exact count from the index for counting from an index; without it the engine counts the lookup's candidates. A storage whose lookups return exactly the matching elements for a point of a string, boolean, uuid or temporal value (an each lookup: the elements whose value is it or a list holding it), never more, claims StorageCapabilities::exact_property_index_lookups; the engine then drops the re-check of such conditions (Kept exact); without it every lookup is treated as a superset (the conformance item exact_property_index_lookups_return_exactly checks a storage that claims it). A storage that serves a unique index lists it with PropertyIndexInfo::unique, refuses every write that would repeat a key with GraphError::UniqueViolation (constructor GraphError::unique_violation) without changing anything, and reports an index stored over repeated values through GraphStorage::unique_index_duplicates instead of serving it (the trait's rustdoc has the contract).

In the playground, the dev server and MCP

  • Playground (WebAssembly and over the dev server): Catalog ▾ ▸ Property indexes lists the indexes with their type, transform, entries, distinct values, elements per value (what an equality reads) and memory (an index that is not served says why), creates one from a form (element, label or any label for a label-less index, key, type, transform: none, to_lower, each or the chain each, to_lower, each with a hint on the query form, a unique box (disabled with each; a unique index carries a unique badge in the list), optional name; the default name is shown as you type and follows the transform; an engine refusal shows under its field) and drops one after a confirmation. The Statistics tab of the Profile panel shows Property indexes with their memory when the graph has some. Indexes travel with the catalog file (Catalog ▾ ▸ Save catalog).
  • Dev server: GET /api/indexes, POST /api/indexes/create {key, label?, element?, name?, type?, transform?, unique?} (label absent or null: label-less; listed with label: null), POST /api/indexes/drop {name} (see the dev server); a create or drop is a commit recorded in the change feed, so open browsers reload. The start block on stderr names the index memory.
  • MCP: the tools list_indexes (also with --mcp-read-only), create_index (with an optional label, omitted for a label-less index, an optional type and transform, enums of the known ones; a chain as the array ["each", "to_lower"], and an optional boolean unique) and drop_index (not offered read-only, where query refuses g.create_index too).

Limits

  • Not indexed: nested values (jpath keys), lists (without each), maps and vectors as values (see index types), labels other than the one declared (an index on person does not serve v().has("title", ..) without has_label; a label-less index does).
  • One index type (memory-ordered): persisted, hash, vector (approximate nearest neighbour) and full-text types are planned and will be additional values of type.
  • Two transforms (to_lower, each) and one chain (["each", "to_lower"]); they serve only the exact children __.to_lower().is(P), __.unfold().is(P) and __.unfold().to_lower().is(P). A to_lower index does not serve a plain has(key, value), and TextP predicates are not served.
  • A unique index checks each write at once (no deferred, commit-time check) and cannot use each; composite (multi-key) unique constraints are not available.
  • order().by(key) does not read the index.