Loading Data
Load All Instances
Section titled “Load All Instances”@Componentclass PersonService @Autowired constructor( private val graphObjectManager: StatelessGraphObjectManager) { fun getAllPeople(): List<PersonCareer> { return graphObjectManager.loadAll<PersonCareer>() }}Load by ID
Section titled “Load by ID”fun getPerson(uuid: String): PersonCareer? { return graphObjectManager.load<PersonCareer>(uuid)}On every store the id’s text is read as the @NodeId field’s type first, and found as a save writes it: load<Order>("5") finds an Order whose Long id is 5, and "2024-01-02" finds a LocalDate id. Text that is no value of the type, such as "abc" for a Long id, finds nothing, and a String id is the text given. A delete by id, a patch and a NodeRef find their node the same way.
On Oracle, Postgres and SQLite, a node whose id another writer stored as a temporal value (date('2026-01-05'), say) is found only by
that value, kind and text, so the class that loads it must declare an id that a save writes back the same. A load refuses
it, by name, where the class doesn’t, rather than give an object whose save would make a second node
(#860, #861):
- an id declared a
String, a number, aBoolean, aUUIDor an enum:Day's @NodeId id is declared a String, but the node whose id is '2026-01-05' holds it as a date: declare id as a date to load it. - an id declared a
java.timetype (or aDate) of another kind or precision:Day's @NodeId id is declared a LocalDate, but the node whose id is '2026-01-05T10:11:12' holds it as a localdatetime, which a LocalDate can't save back: declare id as a LocalDateTime to load it.A date is held by aLocalDate, a local datetime by aLocalDateTime, a datetime at UTC by anOffsetDateTime, anInstantor aZonedDateTime(by aDateto the millisecond), a local time by aLocalTime, a time by anOffsetTime, a duration of time only (PT26H) by aDuration, and one of months and days only (P1Y2M,P3D) by aPeriod. A datetime at another offset, and a duration of days and time (P1DT2H) or of months and time, are held by none: Jackson reads a datetime at UTC, aDurationis written in hours, never in days, and aPeriodholds no time. Declare thoseAny.
Every read that maps a node does so: a load, a search, a view’s root and related nodes, a path, a grouped read’s key and
update’s load. An id declared Any is not refused: it is loaded as the value’s text, and a save, saveAll, update or a
view’s save binds it as the value the node holds while it is the very text the load gave, as do a load, delete,
patchAll or relate by it; an id changed since, or given afresh as the same text, is written as it is given.
count returns a Long and is consistent with loadAll — it counts exactly the objects loadAll would return for the same type and filter. There are three overloads, mirroring loadAll/deleteAll:
// 1. Count everything of a type (reified, or pass Issue::class.java)val total: Long = graphObjectManager.count<Issue>()
// 2. Count with a simple WHERE filter (aliases match loadAll: `n` for fragments,// the root fragment field name for views)graphObjectManager.count<Issue>("n.state = 'open'")
// 3. Count with the type-safe DSL (generated per-view extension injects the query object)graphObjectManager.count<RaisedAndAssignedIssue> { where { query.issue.state eq "open" }}The codegen emits INSTANCE-injecting extensions for every DSL-spec method — loadAll<T> { },
deleteAll<T> { }, count<T> { }, and loadNearest<T>(…) { } (the last only for @VectorIndex-ed
views). The reified count<T>() / loadNearest<T>(…) and the explicit ::class.java overloads also
remain (the latter for Java).
Fragments are a straight node count of the fragment’s labels.
Views count only roots that satisfy the view’s required relationships — non-optional, non-collection @GraphRelationships — so the result equals loadAll(...).size, not a naive node count. For example, RaisedAndAssignedIssue requires raisedBy (a single, non-null RAISED_BY):
graphObjectManager.count<Issue>() // 3 — every Issue nodegraphObjectManager.count<RaisedAndAssignedIssue>() // 2 — only Issues with a RAISED_BY edgeAn Issue with no RAISED_BY is a valid Issue node but is not a RaisedAndAssignedIssue, so it is excluded — just as loadAll would exclude it. Optional (nullable) and collection relationships place no such constraint.
From Java, the same three overloads apply (use .count(Issue.class) etc.); the DSL overload takes the generated query object and a lambda.
Vector Search (loadNearest)
Section titled “Vector Search (loadNearest)”loadNearest runs an approximate nearest-neighbour search and returns the hits paired with a
normalized similarity score. Like loadAll, it works on both a @GraphView — searching the
root fragment’s embedding and returning the fully-projected view — and a plain @NodeFragment,
searching and returning the bare nodes:
// Search a view: ranks PropositionViews by their root proposition's embeddingval views: List<Scored<PropositionView>> = graphObjectManager.loadNearest<PropositionView>(queryEmbedding, topK = 20)
// Search a fragment: ranks bare PropositionNodesval nodes: List<Scored<PropositionNode>> = graphObjectManager.loadNearest<PropositionNode>(queryEmbedding, topK = 20)The embedding to search is identified by a @VectorIndex annotation on the searched fragment (the
view’s root fragment, or the fragment itself) —
inferred when the fragment declares one embedding, or named explicitly to pick among
several. @VectorIndex is the query-side declaration of “this embedding is searchable” and is
independent of how the index is created: it works whether you create the index from the annotation
(SchemaCatalog.fromFragments(...)) or from an explicit spec (SchemaCatalog.of(VectorIndexSpec(...)));
in the latter case, add the annotation to the fragment as well — it carries no creation side effects
on its own. Drivine refuses a catalog spec over a fragment field that has no @VectorIndex, naming the
class, the field and the spec: without the annotation FalkorDB writes the field as a plain list and
loadNearest finds no index. The check runs when SchemaManager applies the catalog and when the
fragment class is first used. A spec for a label no fragment maps is not checked.
@NodeFragment(labels = ["Proposition"])data class PropositionNode( @NodeId val id: String, val text: String, @VectorIndex(similarity = SimilarityFunction.COSINE) val embedding: List<Float>? = null,)
@GraphViewdata class PropositionView( @Root val proposition: PropositionNode, @GraphRelationship(type = "HAS_MENTION", direction = Direction.OUTGOING) val mentions: List<Mention>,)// Single embedding on the root fragment → inferred, no property argumentval hits: List<Scored<PropositionView>> = graphObjectManager.loadNearest<PropositionView>(queryEmbedding, topK = 20)
hits.forEach { println("${it.score} → ${it.value.proposition.text}") }
// Disambiguate when a node carries several embeddings, and/or floor by similaritygraphObjectManager.loadNearest<PropositionView>("titleEmbedding", queryEmbedding, topK = 20, threshold = 0.8)Each result is a Scored<T>(value, score); the score is normalized to similarity, higher = more
similar on every engine, so ordering and threshold mean the same thing regardless of backend.
It is in [0, 1]: (1 + cos) / 2 for a cosine index, and 1 / (1 + d²) for a Euclidean one, where
d is the distance. So a cosine of 0.6 scores 0.8, and 2 * score - 1 gives the cosine back.
Changed on FalkorDB and Memgraph. Before this release FalkorDB gave the cosine itself (-1 to 1) and
1 / (1 + d), and Memgraph the absolute value of the cosine, so opposite vectors scored as high as equal ones; Memgraph’s Euclidean score was already1 / (1 + d²). Both now give the scores above, as Neo4j, Postgres, Oracle and SQLite do. A cosine score rises fromcosto(1 + cos) / 2, and a FalkorDB Euclidean score falls from1 / (1 + d)to1 / (1 + d²)wheredis over 1 (and rises where it is under), so athresholdchosen against the old scores keeps more or fewer results than before: convert a cosine thresholdtto(1 + t) / 2.
topK is the index’s k, not a guaranteed result count. When searching a view, its
required relationships (and the optional threshold) are applied after the K-nearest search,
so a candidate that ranks in the top K but fails the filter is dropped — meaning loadNearest can
return fewer than topK results. The same holds for a root with more than one label: the index is
on its first label, so a node with that label alone is a candidate, and is dropped. So is a node of a
partitionLabel’s index that lacks any of the root’s labels. A fragment with one label, searched
without a partition, has no such filter, so it returns the full top K (minus any threshold cut).
k is also the search beam width — this is the surprising part. On Lucene-backed engines the
result queue is the HNSW candidate queue, so k does not merely truncate a ranked list; it decides
how much of the graph the search explores. A small k can miss a vector that is genuinely nearest.
This is measurable, not theoretical: on a 9K-vector index, a vector verified as true global rank 3 was
not returned at any k ≤ 100, and came back at rank 3 at k = 200. Neo4j exposes no separate
ef_search, so raising k is the only query-time lever on recall.
Use searchK to widen the search without widening the result:
// search with a beam of 200, return the best 40 that survive the filtergraphObjectManager.loadNearest<PropositionView>(dsl, queryEmbedding, topK = 40, searchK = 200) { where { proposition.contextId eq ctx }}searchK is what the index is asked for; topK becomes a LIMIT applied after the filter, so
over-fetching actually recovers rows the filter would otherwise have thinned away. Omit it and the
emitted query is unchanged. searchK < topK throws — it can only lose results.
On Neo4j, over-fetching also re-ranks the beam by exact similarity before trimming: where the index quantizes, its own score is computed against quantized vectors and does not order identically to exact similarity, so trimming by it discards true matches the beam already found. Whether an index quantizes depends on the engine build unless you pin it.
Filtered searches dilute. Because predicates apply after the index yields, a scoped caller gets
roughly k × selectivity rows — at 22% selectivity, asking for 40 returns about 9 — and those
survivors are the globally-nearest that happen to be in scope, not the nearest within scope. searchK
mitigates this. See 0.0.79-vector-search-k.md.
Searching a partition (partitionLabel). When the same property is indexed per partition — one
vector index per corpus, tenant, or other scope — name the partition and the search runs inside it,
pre-filtered by construction, so k is no longer diluted by the filter:
persistenceManager.indexes.ensure(VectorIndexSpec("Corpus_abc", "embedding", 1536))
graphObjectManager.loadNearest( PropositionNode::class.java, null, queryEmbedding, topK = 40, threshold = null, searchK = null, partitionLabel = "Corpus_abc",)The label changes only which index is located: where { } and the projection are unaffected. A node
the partition’s index yields comes back only when it has every one of the fragment’s labels, here
:Proposition, so a node of the partition that is no Proposition is dropped. The index name re-derives as
${label}_${property}_vector, matching what VectorIndexSpec would create — so a fragment whose
@VectorIndex pins an explicit name cannot be partitioned, and says so.
See 0.0.79-vector-partitioning.md.
Backends without a native vector index (Amazon Neptune) throw UnsupportedOperationException.
Pinning the physical index. Only dimensions and similarity_function are always emitted;
everything else about the physical index is the engine’s choice, and engine defaults change between
versions — so the same declaration can produce a different index on different servers. Pin the HNSW
graph shape portably on the annotation, and anything engine-specific on a VectorIndexSpec:
@VectorIndex(similarity = SimilarityFunction.COSINE, hnswM = 32, hnswEfConstruction = 200)val embedding: List<Float>? = null
// engine-specific options — Neo4j quantization, FalkorDB efRuntime — in a catalog specSchemaCatalog.of( VectorIndexSpec("Proposition", "embedding", 1536, engineOptions = listOf(Neo4jVectorOptions(quantizationEnabled = false))),)An unpinned parameter stays the engine’s to choose and is never reported as drift; a pinned one the engine contradicts is. The effective configuration is logged after every index creation either way. See 0.0.79-vector-index-tuning.md.
Filtering with where { }. A where { } block AND-s caller predicates into the same
post-search filter, so you can combine vector similarity with property predicates and
relationship quantifiers in one statement:
// nearest propositions in this context that mention entity X (reified form generated per @VectorIndex view)graphObjectManager.loadNearest<PropositionView>(queryVector, topK = 20) { where { proposition.contextId eq ctx proposition.status eq "active" mentions.any { resolvedId eq entityId } // any{} / none{} over a projected relationship }}The codegen emits this loadNearest<T>(vector, topK, threshold) { where { } } extension for each
@VectorIndex-bearing view (its root fragment). The filtered form works on a bare fragment too,
given the fragment’s generated query object — filter its own properties directly:
// filtered vector search over a bare @NodeFragmentgraphObjectManager.loadNearest<ChunkNode, _>(ChunkNodeQueryDsl.INSTANCE, queryVector, topK = 20) { where { query.containerSectionId eq "sec-1" }}The predicate is applied after the K-nearest search, so it really does prune — a node that ranks
in the top K but fails the predicate is dropped, and topK remains the index’s k (the result may
contain fewer rows). Property predicates filter the projected root; relationship quantifiers
(any{}/none{}) filter the projected relationship collection (any(m IN mentions WHERE …)).
Multiple any{} AND together — “mentions all of these entities” is one any{} per id. Referencing
a relationship the view does not project is an error.
Nearest Neighbours Within a Set (loadNearestAmong)
Section titled “Nearest Neighbours Within a Set (loadNearestAmong)”loadNearestAmong answers, for each of a set of ids, “which of the other ids in this set are
nearest to it?” — the batched form of calling loadNearest once per id with that node’s own
embedding and keeping only the hits inside the set. It runs as one statement that each store answers
natively, so it needs no store-specific Cypher:
val neighbours: Map<String, List<Scored<String>>> = graphObjectManager.loadNearestAmong<PropositionNode>(batchIds, topK = 5, threshold = 0.8)
neighbours["p-1"] // [Scored("p-7", 0.97), Scored("p-3", 0.91)]-
Keys are the ids whose root node has the embedding, in the order the ids were given. An id with no embedding, or no node, is not a key; an id whose neighbours were all dropped maps to an empty list. On Oracle, Postgres and SQLite each id is read as
loadreads an id’s text, as the@NodeIdfield’s type, and found through the index over the id; a key or a value is the text the id was given as, though the store holds other text of it, as2030-01-01T10:00:00for aLocalDateTimegiven as2030-01-01T10:00. On Neo4j, Memgraph and FalkorDB the ids reach the search as text, so only aString,UUIDor enum@NodeIdis searched; any other is refused withUnsupportedOperationException. An embedding of another size than the index’s is measured against none of a different size: on Postgres or Oracle with a vector index made it is not a key, and on Neo4j and FalkorDB the search fails, as their index search refuses a vector of another size, given asearchK. With nosearchK(below), which asks no index, it is measured against none of another size on Neo4j too; FalkorDB refuses a pair of two sizes there as well. -
Values are up to
topKother ids from the set — never the id itself — most similar first, each with the same normalized scoreloadNearestgives that pair on the same store, so the two agree. Two that score exactly alike come in the@NodeIdtype’s own order (a text by its code points, a number by its value, a temporal by its time, aUUIDor an enum by its text), whatever order the ids were given in, except on FalkorDB through its index, where the index’s own order decides (with nosearchK, below, no index is asked, so the type’s order holds there too). Those belowthresholdare dropped. By cosine, on Oracle, Postgres and SQLite, an embedding all of zeros, which has no direction, is left out, as a key and as a value, as Neo4j’s index leaves it out. -
For each pair once, pass
neighbours = AmongNeighbours.AFTER: each id keeps only the ids after it in the@NodeIdtype’s own order, as above, so a pair comes back once, under the id that comes first, and the last id maps to an empty list. The direction is kept before each id’stopKare cut, so no pair is lost where an id’s nearest all come before it, as it would be by dropping, after the search, each pair already seen. With nosearchK, every pair of the set is measured, through no index, on every store, so the answer is exact and its cost grows with the square of the number of ids. Given asearchK, each id asks the index for that many where one is made, and a pair is found only where the index gives the later id among the earlier one’ssearchKnearest, so pairs can be missed, and the shared module says so in the log at DEBUG. The default,AmongNeighbours.ALL, keeps every other id, so a pair can come back under each of its ids.graphObjectManager.loadNearestAmong<PropositionNode>(batchIds, topK = 5, neighbours = AmongNeighbours.AFTER)From Java, give every argument:
loadNearestAmong(PropositionNode.class, batchIds, 5, AmongNeighbours.AFTER, null, null, null). There is no shorter form taking the neighbours, as one would make a call such asloadNearestAmong(cls, ids, 5, null)ambiguous. -
It works on a
@NodeFragmentand on a@GraphView(searching the root fragment’s embedding), and resolves the embedding from@VectorIndexasloadNearestdoes; passpropertywhen there are several. A view’s relationships play no part: the set is named by id.
With no searchK, the answer is exact on every store. Every pair of the set is measured, through
no index, so the cost grows with the square of the number of ids, and the answer does not depend on
the store or on whether a vector index has been made. On FalkorDB this search runs under a timeout of its own, as
FalkorDB’s image ends any query after a second (drivine4j#868).
A searchK asks the index instead. Where the store searches through an approximate index — Neo4j,
FalkorDB, Memgraph, and Postgres or Oracle once a vector index has been made — the index is asked for
searchK candidates per id, and the “among the set”, self, root label, threshold and, for each pair
once, “after it” filters apply to those. An id whose nearest mostly lie outside the set can get fewer
than topK back, so a selective set — a few ids among many indexed nodes — needs a larger searchK.
That such an answer is the index’s, approximate, is logged at DEBUG (under
org.drivine.query.VectorSearchPlanner on the graph engines, org.drivine.backend.sql.SqlViewSelect on
Postgres and Oracle). Where the store measures every node instead (SQLite, and Postgres or Oracle with
no vector index made) only the set is measured and searchK changes nothing.
| Store | How it is answered, given a searchK |
|---|---|
| Neo4j | UNWIND the ids, db.index.vector.queryNodes from each seed’s embedding, rescored exactly with vector.similarity.* |
| FalkorDB | UNWIND the ids, db.idx.vector.queryNodes from each seed’s embedding |
| Memgraph | UNWIND the ids, vector_search.search from each seed’s embedding |
| Postgres | one SQL statement: each seed’s nearest through the pgvector index, or, with none made, measured against the other seeds |
| Oracle | one SQL statement: each seed’s nearest through the vector index (CROSS APPLY … FETCH APPROX), or, with none made, every pair of seeds measured and ranked |
| SQLite | one SQL statement: every pair of seeds measured and ranked (exact) |
| Neptune | refused with UnsupportedOperationException, as loadNearest is |
Full-Text Search (loadMatching)
Section titled “Full-Text Search (loadMatching)”loadMatching is the full-text mirror of loadNearest: it finds the topK nodes most relevant to a
text query and returns them as scored, typed results — normalized to a consistent [0, 1] similarity
across engines, with no consumer Cypher and no per-engine score wrangling.
// bare @NodeFragmentval hits: List<Scored<ChunkNode>> = graphObjectManager.loadMatching<ChunkNode>("graph databases", topK = 20)
// with a floor on the normalized relevancegraphObjectManager.loadMatching<ChunkNode>("graph databases", topK = 20, threshold = 0.5)
// a @GraphView searches its root fragment's text index and returns the projected viewgraphObjectManager.loadMatching<ChunkView>("graph databases", topK = 20)The index is resolved from a @FullTextIndex on the searched fragment (property-level for a single
field, or class-level @FullTextIndex(properties = ["title", "body"]) for a multi-property index) — the
same annotation the schema feature uses to create it. threshold defaults to 0.0 (keep everything).
topK bounds the index call as well as the rows returned: the scores are normalized over the hits
the index yields that have every one of the root’s labels, so the index is asked for its best topK
hits, and an ordinary query that matches most of a corpus costs no more than those. A node with the
indexed label alone is no root, so it is dropped before the scores are scaled, and the best hit a
search can return scores 1.0 on every store. Each result is a Scored<T>(value, score), most relevant
first, with polymorphic dispatch (a loadMatching<SealedBase> returns each hit as its concrete subtype).
The query string is passed through to the engine’s full-text language (Lucene syntax on Neo4j:
AND/OR/"phrase"/field:term); raw user input is not escaped for you. Backends without a native
full-text index throw UnsupportedOperationException.
Filtering with where { } works exactly like loadNearest — full-text relevance plus property
predicates in one query, on a view or a bare fragment:
graphObjectManager.loadMatching<ChunkNode>("graph databases", topK = 20) { where { query.containerSectionId eq "sec-1" }}The predicate, like a view’s required relationships and a root’s labels beyond the first (the one
the index is on), is applied after the index yields; the labels are checked before the scores
are scaled, the predicate and relationships after. Where any of them filters, the index is asked for topK × FullTextSearchLimits.FILTERED_OVER_FETCH (10) hits
and the filter keeps the best topK of those, so a filter that passes fewer than one in ten of the
best hits can return fewer than topK rows while the index holds more that pass it. The DEBUG line
GraphObjectManager logs for a short result says how many hits the index was asked for.
Engine note: full-text search runs on Neo4j (
db.index.fulltext), FalkorDB (db.idx.fulltext, by label), and Memgraph (text_search, GA — no experimental flag needed).

