Repository navigation
fix: vector retraction round-trips across rebuild, overlay, and incremental publish paths - #1221
Conversation
SPOT-scan + value comparison in the binary_scan overlay so vector retractions cancel the correct row across rebuild and pre-rebuild paths.
aaj3f
left a comment
There was a problem hiding this comment.
Seems like a significant fix! One note below that could (but not sure) mean a big perf hit w/ incremental publish, but other than that 👍
There was a problem hiding this comment.
The correctness fixes in this file make sense. My question (specifically re: 4b and 4c) is how much the work/latency increase is on incremental publishes even on commits with no vector data. It seems that even on commits that don't touch any vector data, 4b will reassemble the entire vector arena and 4c will walk SPOT for every vector-type flake. We could always create a follow-up issue w/ an otel bench to see if perf hit is real and, if so, how much it hinges on 4b and 4c. If it is/was real, at the very least we could make 4b/4c conditional on the chunk actually including vectors.
…ded base portion before merging chunk-new entries
SPARQL DELETE WHERE(and anyop=falsevector flake) onf:embeddingVectordata was not cancelling the indexed assertion — across all three indexing
paths (rebuild, novelty-overlay, incremental publish). And even when it
appeared to cancel, it could cancel the wrong row. The bug had multiple
overlapping causes around how vector arena handles are minted, retracted,
and re-resolved.
This PR makes vector retractions round-trip correctly across all three
paths and pins the contract with regression tests for every known
mis-cancellation shape — including the most common production path
(incremental publish, which runs whenever a base index already exists and
the commit gap is small).
Context
A vector fact has two identities:
(s, p, FlakeValue::Vector([..]), dt=embeddingVector, m)(s_id, p_id, o_type=VECTOR_ID, o_key=<arena handle>, o_i)Cancellation matches by indexed identity (
o_kind/o_keytuple). Thetransaction layer was already producing the right logical retraction; the
broken part was translating that into the same indexed identity as the
original assertion. Allocating a fresh arena handle for each retraction
guarantees the
o_keydiffers from the assertion's, and merge cancellationsilently misses.
Fix
1. Resolver fact-identity tracking + dedup (
fluree-db-indexer)SharedResolverState/GlobalDictsgain a new map:The fact-identity key is keyed by subject-name space (not s_id) and
includes the f32 bit pattern of the quantized vector value:
vs. global s_id boundary inherent to the incremental-resolve
pipeline. Both rebuild and incremental paths populate / look up the
same map shape.
f32_bitsbecause(s, p, o_i)alone is not unique:predicate (each gets its own arena handle).
predicate without a list index (all share
o_i = LIST_INDEX_NONE).resolve_object(and its chunk variant) now:present (dedup), otherwise inserts to the arena and records the new
handle.
found, else returns
Ok(None)— a no-op skip rather than abortingthe rebuild.
Returning
Option<RunRecord>letsresolve_opskip emitting records forunmatched retractions (DELETE DATA for never-asserted vectors, historical
no-ops). Other datatypes already encoded unmatched retractions
harmlessly; this brings vectors in line.
2. Overlay fact-identity scan (
fluree-db-query,fluree-db-binary-index)New
BinaryIndexStore::find_vector_handle_by_fact(g_id, s_id, p_id, o_i, value):(s_id, p_id, o_type=VECTOR, o_i).and bit-compares to
valuebefore returning.binary_scan::translate_one_flake_v3_pubshort-circuitsFlakeValue::Vectoroverlay flakes through this lookup so the overlay's
(s_id, p_id, o_type, o_key, o_i)tuple matches the indexed assertionwithout requiring re-publish. The fallback (no matching base row) goes
through the existing materialized-flake path.
g_idis now plumbed intotranslate_one_flake_v3_pub(was implicit atthe for-each-overlay-flake level). Five callers updated:
binary_scan,binary_range,fast_group_count_firsts,fast_path_common,geo_search.store: &Arc<BinaryIndexStore>ripplesthrough
translate_overlay_flakes*andexport.rs::translate_overlay.3. Incremental publish: pre-load base arenas + seed fact map (
fluree-db-indexer)This is the most common production path — once a base index exists and
the commit gap is small, every publish goes through
incremental_resolve,not full rebuild. Pre-fix, the chunk-local fact map only knew assertions
in the new chunk, so retractions of base-asserted vectors silently
no-op'd at incremental publish (the user's DELETE appeared to work
against novelty queries until publish, then reverted).
Two new steps in
incremental_resolve.rs:recorded only
base_vector_counts, we now fetch each manifest'sshard CIDs, decode the VAS1 bytes, and reassemble a
VectorArenaviaload_arena_from_shards. The arena gets seeded intoshared.vectors[g][p]so chunk inserts append to the unified base+chunkarena and return globally-correct handles directly.
vector_fact_handlesfrom base SPOT. New helperseed_vector_fact_handlesconstructs aBinaryIndexStore::load_from_root_v6and SPOT-scans for
o_type=VECTORrows. For each row it decodes(s_ns_code, s_name)via the newBinaryIndexStore::resolve_subject_parts,reads the
f32_bitsfrom the just-loaded arena at the row's handle,and inserts
(s_ns_code, s_name, p_id, o_i, f32_bits) → handleintothe shared fact map.
The VECTOR_ID offset pass is gone — handles are already global because
chunk inserts append to the pre-loaded base. Replaced with a
debug_assert!sanity guard that catches any out-of-range o_key.This also fixes a related dedup gap: re-asserting the same logical
vector fact across commits (assert → publish → assert same) now reuses
the base arena's handle via the seeded fact map, producing one encoded
row instead of two.
4. Arena reverse-lookup primitives (
fluree-db-binary-index)VectorArena::find_handle_by_valueandLazyVectorArena::find_handle_by_value— bit-equality scans that the new
find_vector_handle_by_factuses tocompare candidate rows. Public on the read-side too in case future
diagnostics need it. New
BinaryIndexStore::resolve_subject_parts(s_id) → (u16, String)returns the canonical (ns_code, suffix) pair without joining into IRI,
used by
seed_vector_fact_handlesfor fact-map keying.Tests
Twelve tests in
fluree-db-api/tests/it_vector_corruption_repro.rs, allgreen. New / un-ignored in this PR:
jsonld_context_vector_bare_array_retracts_after_indexing(un-ignored)— post-rebuild round-trip
jsonld_context_vector_bare_array_retracts_via_novelty_overlay—pre-rebuild novelty-overlay round-trip
jsonld_vector_retracts_via_incremental_publish— incrementalpublish path: insert → publish (full rebuild) → DELETE → publish
(incremental) → COUNT == 0
jsonld_context_vector_duplicate_values_retract_one_keeps_other—two subjects, same vector value, retract one keeps the other (rebuild)
jsonld_context_vector_duplicate_values_overlay_retract_one_keeps_other— same case via overlay
jsonld_multi_valued_vectors_retract_one_keeps_other— one subjectwith two different vector values under the same predicate without a
list index; retract one keeps the other (rebuild)
jsonld_multi_valued_vectors_overlay_retract_one_keeps_other— samecase via overlay
sparql_delete_data_unmatched_vector_is_no_op—DELETE DATAfor anever-asserted vector must not abort the transaction
jsonld_re_asserting_same_vector_dedups— assert → publish → assertthe same logical fact again → COUNT == 1; delete → COUNT == 0
(verifies dedup AND that one retraction cancels the deduped row)
New test helper
support::build_and_publish_indexusesbuild_index_for_record(which dispatches to incremental indexing whena base exists). Distinct from
rebuild_and_publish_indexwhich alwaysdoes a full rebuild — the incremental test specifically uses the new
helper to exercise that path.
Operational note
Pre-loading base vector arenas at every incremental publish adds
bounded I/O (one
cs.getper shard CID per (g, p) arena). For ledgerswith no vectors there's no overhead. For ledgers with many vectors,
the cost is proportional to total vector data — typically dwarfed by
SPOT scan and run-record processing. If profiling identifies this as
a hot path, the
seed_vector_fact_handleshelper could grow a slimmer"scan-only" loader that skips the duplicate dict/arena loading inside
BinaryIndexStore::load_from_root_v6.Coverage matrix