Repository navigation
Description
LSMVectorIndex.findNeighborsFromVector returns an empty list while another thread commits transactions that delete the records nearest to the query and insert new ones near it, if the index uses "quantization": "BINARY", although 3,000 records are live at every instant. vectorNeighbors then answers 0 rows.
This is not the stale-entry case of #9368: the direct index call returns no RID at all (not a few stale ones), and the same program with NONE or INT8 returns k RIDs every time. When no transaction runs, the same search always returns k RIDs.
Repro, one class, no dependencies beyond the engine jars (java VectorBinaryEmpty <empty directory> [BINARY|INT8|NONE]):
import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.RID;
import com.arcadedb.index.TypeIndex;
import com.arcadedb.index.vector.LSMVectorIndex;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
/**
* LSMVectorIndex.findNeighborsFromVector returns an EMPTY list while another thread commits transactions that delete the records nearest to the query and insert new ones near it, although 3,000 records are live at every
* instant. A search with the same arguments when no transaction runs always returns k RIDs.
*
* Usage: java VectorBinaryEmpty <empty directory> [quantization: BINARY (default), INT8 or NONE]
*
* 3,000 vectors (32 dimensions, EUCLIDEAN) with an LSM_VECTOR index. The main thread commits 40 transactions; each one deletes the 100 records nearest to a fixed query vector q and inserts 100 new records near q. A reader
* thread searches the index for q (k = 1, 5 and 10, no filter, no SQL) in a loop and counts the answers by size.
*/
public class VectorBinaryEmpty {
static final int DIM = 32;
static float[] unit(final Random r) {
final float[] v = new float[DIM];
double s = 0;
for (int i = 0; i < DIM; i++) {
v[i] = (float) r.nextGaussian();
s += v[i] * v[i];
}
s = Math.sqrt(s);
for (int i = 0; i < DIM; i++)
v[i] /= s;
return v;
}
static float[] near(final float[] q, final Random r) {
final float[] v = new float[DIM];
double s = 0;
for (int i = 0; i < DIM; i++) {
v[i] = (float) (q[i] + 0.05 * r.nextGaussian());
s += v[i] * v[i];
}
s = Math.sqrt(s);
for (int i = 0; i < DIM; i++)
v[i] /= s;
return v;
}
static double dist(final float[] a, final float[] b) {
double s = 0;
for (int i = 0; i < DIM; i++)
s += (a[i] - b[i]) * (a[i] - b[i]);
return s;
}
public static void main(final String[] args) throws Exception {
System.out.println("engine " + com.arcadedb.Constants.getRawVersion() + " build " + com.arcadedb.Constants.getBuildNumber() + ", java " + System.getProperty("java.vm.version"));
final String quant = args.length > 1 ? args[1] : "BINARY";
final Random r = new Random(500);
final DatabaseFactory factory = new DatabaseFactory(args[0] + "/binaryempty");
if (factory.exists())
factory.open().drop();
final Database db = factory.create();
db.command("sql", "CREATE VERTEX TYPE Product");
db.command("sql", "CREATE PROPERTY Product.pid INTEGER");
db.command("sql", "CREATE PROPERTY Product.embedding ARRAY_OF_FLOATS");
db.command("sql", "CREATE INDEX ON Product (pid) UNIQUE_HASH");
final Map<Long, float[]> live = new HashMap<>();
db.begin();
for (int i = 0; i < 3000; i++) {
final float[] v = unit(r);
db.command("sql", "INSERT INTO Product SET pid = :p, embedding = :e", Map.of("p", (long) i, "e", v)).close();
live.put((long) i, v);
}
db.commit();
db.command("sql", "CREATE INDEX ON Product (embedding) LSM_VECTOR METADATA { \"dimensions\": " + DIM + ", \"similarity\": \"EUCLIDEAN\", \"beamWidth\": 100"
+ (quant.equals("NONE") ? "" : ", \"quantization\": \"" + quant + "\"") + " }");
final LSMVectorIndex lsm = (LSMVectorIndex) ((TypeIndex) db.getSchema().getIndexByName("Product[embedding]")).getIndexesOnBuckets()[0];
final float[] q = unit(new Random(4242));
final int[] ks = { 1, 5, 10 };
int quietEmpty = 0;
for (int t = 0; t < 50; t++)
for (final int k : ks)
if (lsm.findNeighborsFromVector(q, k, 100).size() < k)
quietEmpty++;
System.out.println("quantization " + quant + "; before any writer, searches with fewer than k RIDs: " + quietEmpty + " of 150");
final AtomicBoolean stop = new AtomicBoolean();
final AtomicLong searches = new AtomicLong(), empty = new AtomicLong(), shortOther = new AtomicLong();
final Thread reader = new Thread(() -> {
int step = 0;
while (!stop.get()) {
final int k = ks[step++ % ks.length];
final int got = lsm.findNeighborsFromVector(q, k, 100).size();
searches.incrementAndGet();
if (got == 0)
empty.incrementAndGet();
else if (got < k)
shortOther.incrementAndGet();
}
});
reader.setDaemon(true);
reader.start();
long nextPid = 100000;
for (int round = 0; round < 40; round++) {
final List<Long> pids = new ArrayList<>(live.keySet());
pids.sort(Comparator.comparingDouble(p -> dist(live.get(p), q)));
final List<Long> victims = new ArrayList<>(pids.subList(0, 100));
db.begin();
db.command("sql", "DELETE FROM Product WHERE pid IN :ids", Map.of("ids", victims)).close();
for (final long p : victims)
live.remove(p);
for (int i = 0; i < 100; i++) {
final float[] v = near(q, r);
db.command("sql", "INSERT INTO Product SET pid = :p, embedding = :e", Map.of("p", nextPid, "e", v)).close();
live.put(nextPid++, v);
}
db.commit();
}
stop.set(true);
reader.join();
int afterShort = 0;
for (int t = 0; t < 50; t++)
for (final int k : ks)
if (lsm.findNeighborsFromVector(q, k, 100).size() < k)
afterShort++;
System.out.println("live records at the end: " + live.size());
System.out.println("searches during the commits: " + searches.get() + ", empty answers: " + empty.get() + ", other answers with fewer than k RIDs: " + shortOther.get());
System.out.println("after the last commit, searches with fewer than k RIDs: " + afterShort + " of 150");
db.close();
System.exit(0);
}
}Results, 3 runs each, with BINARY (empty answers / searches during the commits), on the CI-built jars of 9740537 (main) and of 07a18f2 (the head of #9385, which is main plus a fix of the SQL record lookup):
| JVM | 9740537 | 07a18f2 |
|---|---|---|
| Temurin 25 | 19/1812, 25/1901, 42/2095 | 27/1782, 20/1993, 13/2036 |
| Temurin 21 | 33/1583, 40/2145, 15/2235 | 39/1792, 27/2088, 31/2048 |
With NONE and with INT8 (one run each, Temurin 25, on 0ca66d4, an earlier head of #9385) there were 0 empty answers in 2,601 and 2,467 searches. Before the writer starts, 0 of 150 searches return fewer than k RIDs, and 0 of 150 after the last commit.
JVMs: Temurin-25.0.4+7 (build 25.0.4+7-LTS, with -XX:+UseCompactObjectHeaders) and Temurin-21.0.12+8 (build 21.0.12+8-LTS), both with --add-modules=jdk.incubator.vector.
Expected: a search with k = 1, 5 or 10 returns k RIDs while 3,000 records are live. Actual: 1 to 2 percent of the searches return none.
Activity
Merge pull request #9408 from ArcadeData/worktree-issues-9396-9343-9386
lvca commentedon Oct 7, 2026
Fixed in #9408 (26.11.1). With
BINARYquantization the search could drop every candidate because their records had just been deleted by a commit in progress. It now widens the candidate list until k live results are found, asNONEandINT8already did.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix: PromQL /series applies label matchers, sparse tombstones are per…
fix(ArcadeData#9717,ArcadeData#9633,ArcadeData#9615): LSM compaction …
fix: PromQL /series applies label matchers, sparse tombstones are per…
fix(#9717,#9633,#9615): LSM compaction keeps the null strategy, BINAR…