Skip to content

Status

Experimental. The API is not stable and nothing here is wired into a database engine yet. What may change.

Experimental. The sources come from the first experiment and were imported unchanged except for the test wrappers and the small edits listed under "Import notes". Measurements of the experiment live in a private harness and are not published yet. This repository has no benchmark numbers. It has a harness for new measurements of the tier (BENCHMARKS.md), and no result file yet.

What exists

Each part has the test programs of the experiment, wrapped as JUnit 5 tests that CI runs on JDK 21 and 25 (see README). The fast tests also run on arm64: Linux with JDK 21 and 25, macOS with JDK 21 (none of these jobs is a required check). They also run on Windows x64 with JDK 21 (fast tests (Windows x64, JDK 21); not a required check). The slow tests run on x86-64 Linux only, not on Windows.

Part What exists Tests
Flat tier FlatIndex with NONE, SQ8, and BINARY scans, compaction, serialize and load, scalar twin kernels Correctness program, threaded program (5 s fast, 20 s and 60 s slow), correctness again with the scalar twins
Kernels on the JVM With the Vector API, x86-64 vectorizes the fp32 dot and squared L2, the int8 dot, the SQ8 dots, and block16. On aarch64 the fp32 kernels use VKernels and those other four use the 128-bit forms of NKernels (Kernels.JVM_NARROW), because VKernels has no fast form for 128-bit lanes (its int8 dot ran 138 times slower than scalar in CI). Hamming is scalar. A JVM with 128-bit lanes that is not aarch64 uses the scalar twins for those four. Not done: AVX-512 and SVE JvmQuantRoutingTest (the routing and the agreement with the scalar twins), KernDiffTest; the smoke mode jvm-vector on arm64 Linux checks the routing and fails when the int8 dot takes more than 10 times the scalar twin (#52)
Graph tier GraphIndex (concurrent HNSW, delete, consolidate, optional SQ8), SealedGraph, seal and fromSealed in memory, SealedGraph.serialize and load (one segment file, CRC32C per section) Functional program (quick mode), threaded program with background consolidate (5 s fast, 60 s slow for fp32 and SQ8), latency during consolidate (slow), segment round trip and damage tests, the functional, threaded, and segment programs again with the scalar twins, a differential test of the vector and scalar graph kernels, and a test that builds and searches a tier in a JVM without the Vector API module
IVF IvfIndex as a standalone index: lazy training, background retrain with atomic swap, drift detection, compaction Single-threaded program at n = 6000 (fast, vector and scalar) and n = 20000 (slow), drift program (slow), threaded program (5 s fast, 10 s slow)
Tier TieredIndex: exact tail, sealed graph segments, merge, tombstones with a version floor, apply(batch) and awaitCapacity, rebuildFrom (also with an epoch and a snapshot position), checkpoint and open for a settled tier (segments plus a manifest per generation, format), and open with a record source (epoch check, durable prefix, liveness check, replay) The tier program, one test at a time (fast), the 10 s threaded test (slow), reopen, manifest and crash-step tests (fast), the record-id reuse tests (see below), the batch tests (see below)
Native image Two image variants, built by the workflow, none a required check. The scalar image (job native image smoke, native image smoke (arm64 Linux) on arm64 Linux, and native image smoke (macOS arm64) on macOS arm64, GraalVM Community 21.0.2): the library and the program NativeSmoke (in src/smoke) are compiled, run once on a JVM without the Vector API module, built into a native image, and the image is run; the program checks that the scalar kernels are in use and that no jdk.incubator.vector class is present. The vector image (jobs native image smoke (vector, x86-64 Linux), (vector, arm64 Linux), and (vector, macOS arm64), plus native image smoke (vector, Windows x64), GraalVM Community 25.0.2, built with --add-modules jdk.incubator.vector -H:+VectorAPISupport): in an image every kernel with a Vector API form (the fp32 dot and squared L2, the int8 dot, the SQ8 dots, and block16) uses it through NKernels, with a species fixed at build time (256 bits on x86-64, 128 bits on aarch64), and hamming, which has no Vector API form, stays scalar; the program checks that Kernels.VECTOR and Kernels.NATIVE_VECTOR are true in the image, that NKernels was initialized at build time, the lanes, and that every kernel returns the bits of its NKernels method and agrees with its scalar twin. Results in an image can differ from the JVM by rounding. Both variants print informational SPEED lines, one per kernel. In both the program builds a flat index (three metrics in fp32, and SQ8 with each of its four kernels), an IVF index, a graph index, and a tier (fp32 and SQ8), and compares every answer with an exact scan after adds, background seals, a tail, deletes, sealNow, id reuse, mergeNow, and deletes after the merge NativeSmoke in the jobs; a failed check, a recall below the bar (0.9 for fp32, 0.8 for SQ8, 1.0 for the exact flat scan), or a failed image build fails the job

The wrappers assert two things per program: zero failed checks, and at least the number of checks the program reported in earlier runs of the experiment. The program code itself is not changed in a way that weakens an assertion.

Record-id reuse and tombstones

A host database frees a record id and later gives it to a new record, so the tier sees delete(id) followed by add(id, newVector). The version floor of TieredIndex keeps the old copies of an id hidden while the new vector is visible. Tests cover this (#5). They use a model that holds the current vector of every id and keeps the older vectors, so a resurrected vector is recognised by its score.

Cases, each on a fresh index:

Case What it does
a_tail The old copy sits in the active tail: delete 30 percent, re-add 80 percent of them with new vectors, delete and re-add again, then seal
a2_tail_and_segments The old copies sit in one segment and in the tail: delete, re-add, seal, merge
b_sealed The old copies sit in sealed segments: delete, re-add (the new vector in the tail, the old one below the floor), seal beside the old copies, delete and re-add again, seal, merge
c1_reuse_in_merge Re-add, and delete then re-add, inside a running merge of the segments that hold the old copies; then again after the merge
c2_delete_in_merge Delete, delete then re-add, delete then re-add then delete, replace, and brand-new ids, all inside a running merge; no delete may be lost when the merged segment is swapped in
e_floor_chain One set of ids goes through four generations, each in its own segment, so the floor moves up four times; then a merge
s_seal_window Operations inside the publish window of a seal, with the frozen tail holding every old copy (before the swap) and right after the swap, using setSealHooks
f_fuzz_background Slow variant only: the background worker seals and merges while one writer reuses, replaces and deletes ids and one reader searches all the time; a hit counts only for an id that was untouched for the whole search

Every checkpoint searches plain, with the id alone allowed, and under Freshness.SEALED_ONLY, with the current vector and with an older vector of the id as the query. A deleted id, an older vector's score, a repeated id, a wrong score, or a reused id at rank 1 for its old vector fails the run. size() and stats().live() are compared with the model, and the floor map must be empty after a full merge in the deterministic cases. A merge window or seal window that is not reached fails the run, it is never skipped.

The tests are RidReuseTest (fast: n = 3000, dimension 32 and 128, two seeds, all deterministic cases, no reader thread), RidReuseLongTest and RidReuseBigLongTest (slow: all cases including the background case, with a concurrent reader that counts a hit only for an id untouched while the search ran; n = 3000 with three seeds on three configurations, and n = 20000), RidReuseSwapRaceTest (fast, about one second: a search paused inside its allow predicate while mergeNow() swaps and cleans up the floor), RebuildSwapRaceTest (fast: two searches paused inside their allow predicate while rebuildFrom swaps the rebuilt state in), and RidReuseMutantTest and RidReuseMutantLongTest. The probe itself is RidReuseProbe.

The probe found a race between a search and a merge swap (#26): a search that started before the swap could return an id that was deleted before it started, or an older vector of an id that was deleted and added again, because the merge removed the floor entries that the old segments still needed. The fix: a search counts itself on the view it reads, a view that a swap replaces while searches run on it is held, and the floor entries that a segment of a held view needs stay until those searches are done (the worker, awaitIdle, mergeNow, sealNow and checkpoint drop them then). The query path still takes no lock and starts no thread: it does one atomic add and one atomic subtract per search. RidReuseSwapRaceTest holds a search inside the first call of its filter, runs mergeNow(), lets the search go on, and checks the answer and that the entry is dropped afterwards; it failed on the code before the fix.

rebuildFrom had the same race on the recovery path (#28): it cleared the floor map before it swapped the rebuilt view in, so a search that was running on the old view could see a hidden copy as valid. It now swaps through the same publish call as a merge and settles the floor the same way, so the entries stay until the searches of the old view are done. RebuildSwapRaceTest holds one search with the vector of a deleted id and one with the older vector of an id that was added again, runs rebuildFrom with the live records, lets both go on, and checks the answers and that the floor map is empty after awaitIdle.

A probe that cannot fail is not a test, so the mutant tests check that it fails on a broken tier. The test reads TieredIndex.java, applies one single-line change (the anchor must occur exactly once), compiles the copy with the JDK compiler API into a temporary directory, and runs the probe in a class loader that prefers that directory. TieredIndex.java itself has no test hook. This needs a JDK, not a JRE: without a compiler the mutant tests are skipped with a message, and they fail when the CI environment variable is set.

Mutant Change The probe must report
X0 none (control) a clean run
M1 add removes the floor entry of the id instead of raising it staleHits above 0, in b_sealed
M2 delete takes a version but writes no floor entry lostDeletes above 0, in b_sealed
M3 cleanupFloor drops every entry after a merge a wrong answer in c2_delete_in_merge

Id epoch and replay

The host names its numbering of ids with an epoch (#7, ID-EPOCH-AND-REPLAY.md). rebuildFrom(Supplier<Snapshot>, long) rebuilds from the host's snapshot without the write lock: the library records the writes that arrive during the build and applies them after the swap, adds at or below the snapshot position skipped. checkpoint stores the epoch and the high-water id (the largest id a segment holds) in the manifest, which already had the two fields, so the format version is the same. open(dir, dim, metric, config, RecordSource) discards persisted state of another epoch (a cold index), drops held ids above the id the host recovered and makes that durable before it returns, hides ids that the host no longer holds, and adds the host's live records above the high-water id to the tail.

The tests use FakeHost, a host that holds the records, mints increasing ids, and forgets its unflushed transactions in a simulated crash: EpochReplayTest (deterministic, fast), EpochReplayStressTest (a crash and reopen loop with random fault points, and a host thread that writes while the tier is rebuilt; three seeds, fast), and EpochReplayLongTest (the same, longer, slow). Not covered: power loss, a crash inside the replay itself, a crash inside the publish that open makes when it drops rows, a check of the id order, and a delete that the library persisted and the host then forgot (the host flushes its deletes before it lets the library checkpoint).

Atomic batches

TieredIndex.apply(batch) applies the adds and then the deletes of one host transaction under one hold of the write lock, and a search sees all of the batch or none of it (#10). Applying the same batch again changes nothing visible. awaitCapacity(deadlineNanos) is the separate back pressure check: apply never waits for the worker and does not look at the hard tail limit, so one batch can take the tail above it.

The tail and the floor map change in place, so one volatile write of a new view cannot cover a batch. A batch counter does: it is odd while a batch is applied and even otherwise. A search waits while it is odd and reads it again after its scan, and when it changed, the scan is thrown away and run again. The query path still takes no lock and creates no thread: one volatile read before the scan, one fence and one read after it. A search that meets a batch waits for it (the length of one batch), and a stream of batches that follow each other faster than one scan takes can starve a search.

The tests are ApplyBatchTest (fast) and ApplyStressTest (slow). ApplyBatchTest checks that the whole batch is visible after apply returns, that a batch with a bad vector changes nothing, that applying a batch again changes nothing visible (also after a seal), that a search held inside its first allow call while a batch is applied answers from the state before the batch or the state after it and never from a mixture (once with the old id in the tail and once with the old id in a segment), that apply does not wait for a worker that is inside a seal, and the behavior of awaitCapacity at the hard tail limit. ApplyStressTest runs updater threads that move groups of ids from one generation to the next in batches while searcher threads check that a group always shows exactly its ids of one generation, on a tail and on a tier that seals and merges all the time.

Graph self-search recall

The graph index is approximate, so a search for a vector that is equal to an inserted one can miss it (#38). Measured at the default ef (100): at 100,000 to 200,000 vectors the graph index misses a query equal to an inserted vector at about 1.2e-4 to 4.0e-4 per probe (1,600,000 probes in each of four modes, 188 to 636 misses per mode). Every one of the 1,260 misses that were diagnosed was reachable from the entry point on layer 0, and a search at ef 1000 found 1,254 of them. At the size of the threaded program (below 67,000 vectors) there was 1 miss in 112 runs of 3,360 probes. These are measurements of the default ef, not a guarantee, and the rate rises with the size of the index.

The threaded program (GraphConcurrencyTest) therefore checks read-your-writes in two parts. Exact membership: right after add returned, the id must be in the index, with no tolerance. It is read through the id-to-ordinal map and the node state (GraphIndex.containsForTest, a package-private accessor for tests), not through a search. Self-search: a recall check that searches for the vector just inserted at ten times the default ef (1000) and fails on more than 1 miss per run (3,360 probes in the 60 s program). Each run prints one line, RYW membership checks=N missing=0 selfSearchMisses=K of M. GraphReadYourWritesTest (fast) covers both parts on 3,000 vectors with a tolerance of 0, and checks that the probe reports an id that is not in the index.

What does not exist yet

  • Serialization of IVF and of the flat tail. FlatIndex has its own serialize and load. The graph segments and a settled tier have the first cut (SEGMENT-FORMAT.md): copy-based reads, no memory mapping, no tail replay, no non-empty tombstones (checkpoint refuses a tier with a tail, a floor entry, or hidden copies), every section verified at open. When open fails, the host falls back to rebuildFrom.
  • Engine integration. Nothing here is wired into ArcadeDB or any other engine.
  • IVF as a segment type of the tier. IvfIndex is standalone.
  • Native-image coverage beyond the smoke job. The program does not write or read segment files (checkpoint, open), does not call rebuildFrom, and uses no concurrent writers; the image is built on Linux (x86-64 and arm64) and on macOS arm64 in CI, and on Windows x64 in the vector job only (there is no scalar image job on Windows), and it is not published.
  • A stable API. 0.1.0 is the first release. Until 1.0 a breaking change to the supported surface needs a new minor version (API.md). The version rule, the steps and the Maven Central details are in RELEASING.md.
  • Published measurements. The experiment's own measurements are in a private harness. The harness Bench (BENCHMARKS.md) is in the repository and the CI job bench smoke runs it at 10,000 vectors, but no result file is committed yet.
  • The longer mode of the graph test program (a recall curve at n = 20000) is not wired into the JUnit tests.

Import notes

  • The Java package is ai.humem.tiervec, the name of the library. It was renamed from the package of the first import before the first release, so it is not a breaking change. The system property that forces the scalar twins is ai.humem.tiervec.scalar.
  • Comments and Javadoc in the sources were rewritten in plain words: the experiment-internal names (requirement ids, fix numbers, rule names) are gone, and no code changed in that edit.
  • The graph test helper T was renamed GraphT, because the flat tests have their own T and both now live in one module and one package.
  • The test helpers got an exitOnFailure flag (default true, so a program run alone still ends the JVM on failure), and the end of each program's main is guarded by it. A JUnit wrapper sets it to false and reads the counters instead, because a System.exit would end the surefire JVM.
  • The micro-benchmark FlatMicro and the benchmark harness of the experiment are not part of this repository. Bench and NativeSmoke are new programs written for it, not imports.
  • One edit to a main source, GraphIndex.java (issue #3, found by the slow CI job): consolidate(), repairOrphans and seal() size their bitsets and arrays from a snapshot of nextOrd, and a concurrent add can publish a node allocated after the snapshot as the entry point (or, in repairOrphans, return one from its search), so the node index fell past the end. bit now reads an index past the end as not set, repairOrphans sizes its arrays to cover the entry point, and seal() ignores an entry point from after its snapshot. GraphConsolidateRaceTest builds that view without threads. It was pushed alone first and failed the fast job on the unfixed code.