Repository navigation
fix(search): a full-text index whose indexing query reasons rebuilds on sync - #2248
Conversation
… 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.
aaj3f
left a comment
There was a problem hiding this comment.
@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 atwarn. No performance-degradation risk to any query that was correct before. - Deployment targets: ✔ n/a —
fluree-db-query/fluree-db-apisync 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 ingrp_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) |
There was a problem hiding this comment.
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.
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", oropts.reasoning) can depend on properties its patterns never name. With"reasoning": "rdfs"and a query for?x a ex:Doc, assertingex:Memo rdfs:subClassOf ex:Docmakes 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. Onmainthe sync takes the incremental path, and with no tracked change it advances the watermark without touching the index.