Skip to content

fix(search): a full-text index whose indexing query reasons rebuilds on sync - #2248

Merged
bplatz merged 1 commit into
mainfrom
fix/bm25-sync-reasoning
Nov 3, 2026
Merged

bplatz merged 1 commit into
mainfrom
fix/bm25-sync-reasoning

Conversation

@bplatz

@bplatz bplatz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

A full-text index whose query reasons rebuilds on sync

An incremental BM25 sync re-indexes only the subjects whose tracked properties changed. That is sound only when the indexing query's patterns name every property it depends on. A query with reasoning ("reasoning", or opts.reasoning) can depend on properties its patterns never name. With "reasoning": "rdfs" and a query for ?x a ex:Doc, asserting ex:Memo rdfs:subClassOf ex:Doc makes every existing memo a document. The property analysis took the patterns as complete, so the sync went incremental, found no tracked change, and left the memos out of the index.

The analysis now treats reasoning (any mode, or query-time rules) as incomplete, so such a query rebuilds in full on every sync, as * and nested projections already do. "reasoning": "none" stays incremental.

Test: sync_with_reasoning_rebuilds_when_the_schema_changes. On main the sync takes the incremental path, and with no tracked change it advances the watermark without touching the index.

… patterns

An indexing query with reasoning (`reasoning`, or `opts.reasoning`) can
depend on properties its patterns never name: asserting ex:Memo
rdfs:subClassOf ex:Doc makes every memo a document. The property
analysis took the patterns alone as complete, so an incremental sync
missed such a change and left the new documents out.

The analysis now marks reasoning (any mode, or query-time rules) as
incomplete, so syncs rebuild in full, as for `*`. `"reasoning": "none"`
stays complete.
@bplatz bplatz added bug Something isn't working as expected area:query Query execution, planning, fast paths, overlay, result formatting labels Nov 3, 2026
@bplatz
bplatz requested a review from a team November 3, 2026 14:18

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bplatz this is right, and at a design level no pushback from me: under any reasoning mode the dependency set isn't subject-local, so declining to a full rebuild, the same answer * and depth already get, is the sound call. Worth noting for anyone reading later: vector sync goes through the same PropertyDeps::analyze (vector.rs:487), so it picks this up too, and the vector docs point at the BM25 shape rules, so the docs change reaches both. I also checked that a ledger's f:reasoningDefaults can't make an indexing query reason behind the analysis's back; the indexing query runs straight through parse_query/execute, so the query's own keys are the whole story. On overlap, this and my #2190 both add tests to it_graph_source_bm25.rs, in different places, and they merge cleanly, so either order works.

Full review below:


✅ Approve.

Nice catch, @bplatz. This is one of the worst kinds of bug for a search index: nothing errors, and the index just quietly stops admitting documents that reasoning says belong. The fix is one flag in DepsWalker, built on the parser's own parse_reasoning, so "reasoning", opts.reasoning and query-time rules are all caught and "none" stays incremental. The integration test asserts both that the sync went full and that the memo's term reached the index, which is the right pair to pin.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ extends the existing completeness analysis and reuses parse_reasoning; shared by BM25 and vector sync.
  • Performance (speed first, memory second): ✔ runs once per sync on the stored query, not per row; no engine hot path. An index whose query reasons now rebuilds on every sync, which is the deliberate price of correctness (as for *), logged at warn. No performance-degradation risk to any query that was correct before.
  • Deployment targets: ✔ n/a — fluree-db-query/fluree-db-api sync logic, reached by the server and by any embedder (including one inside AWS Lambda), but it only changes which existing sync path is taken; no new task, cache or filesystem assumption.
  • Testing: ✔ unit coverage of every spelling plus "none", and an end-to-end test in grp_graphsource; both run in CI's nextest; the end-to-end test is red with the fix reverted.
  • Conventions: ✔ self-describing subject with a body; the docs shape list updated with the reason.

Verified locally at branch HEAD: both new tests pass; with only the fix hunk reverted, both fail (the sync takes the incremental path); restored, the five sync* BM25 tests pass. Every consumer of the analysis (BM25 and vector sync) and the indexing query's reasoning source traced.

Approving so you can merge when ready.

}
match query
.as_object()
.map(crate::parse::options::parse_reasoning)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise. I like that this asks parse_reasoning rather than re-reading reasoning/rules itself. It means the analysis honors the same top-level-or-opts precedence execution does (#1863, #1883), so the two can't drift apart the way a hand-rolled key check eventually would.

@bplatz
bplatz merged commit 829d335 into main Nov 3, 2026
19 checks passed
@bplatz
bplatz deleted the fix/bm25-sync-reasoning branch November 3, 2026 23:03
bplatz added a commit that referenced this pull request Nov 4, 2026
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255,
#2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210,
#2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next.

Resolutions:
- Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the
  dictionary's coverage watermark sit on next's graph slots and per-graph
  OrdMaps. A commit's reification links count toward coverage. Planner
  stats from segment sums decline under annotations, whose link deltas
  only the walk counts, and otherwise carry the indexed link counts.
- Stats-view identity: the index root's id reaches the snapshot through
  next's root decoder (`decode` takes the id, as `take_snapshot_metadata`
  does). `LedgerState::load_record` has a decoding-root form beside
  `load_decoding_root`.
- Transact: #2184's parallel-relationship check runs in next's link
  cascade, counting the `rdf:reifies` links on the retracted edge that the
  transaction does not retract itself. Main's bundle `edge_reifiers` is
  dropped, and `subjects_with_prior_rows` and
  `enforce_single_target_reifiers` stay deleted. The upsert pre-check
  takes main's dictionary probe and bounded seek.
- Query: geo search resolves the graph's POST tree once at open (pooled
  graphs keep their filter), an empty manifest when there is none.
  `branch_or_none` reads the dedicated branch, and the batched joins keep
  next's pooled lanes. The stats-view key hashes the root id.
- Indexer: `apply_dict_novelty` and `compact_forward_streams` take the
  cycle's compaction budget, so the term dictionary keeps its reserved
  share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit`
  rewrites next's 20-byte types records.
- Disk cache: main's in-flight write registration, with an empty entry
  still read as crash debris that a write replaces. The process-wide
  eviction walk stays removed.
- Graph import (#2232): fenced CAS and publishes, the seed carries the
  record's namespace and fence, 32-bit graph ids and next's loaders. An
  import into a graph of an existing ledger refuses triple terms and edge
  annotations: the splice merges no triple-term dictionary yet.
- Iceberg: `create_iceberg_graph_source` goes with main (a source needs a
  mapping); the R2RML path keeps next's `model_instance`.
- CLI: main's shared import flags without the leaflet flags; `graph
  import` routes through next's process-wide server routing, and
  `upload_source_import` serves next's `Destination`. Doc sources read a
  ledger through the command's open instance.
- Tests: sibling ledger ids become distinct names, `genesis_ledger` is
  awaited, Cypher state dumps include each relationship's `rdf:reifies`
  link, and the graph-import arena test checks the refusal instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:query Query execution, planning, fast paths, overlay, result formatting bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants