Repository navigation
feat(BM25): embedded BM25 full-text search over the standard query path + a bm25 CLI - #1543
Conversation
aaj3f
left a comment
There was a problem hiding this comment.
@christophediprima thank you for another excellent PR!
This fixes a real and gap — embedded BM25 was documented as the default deployment mode while being unreachable over HTTP — and it fixes it at the right altitude, filling the existing ContextConfig.bm25_provider slot exactly where the R2RML providers are already threaded rather than bolting in a parallel dispatch. The choice of the "legacy" provider over the "preferred" one is also correct, since only index-provider mode can enforce view policy on a hit, though the code comment credits the wrong reason. The CLI is a genuinely thin wrapper that reimplements nothing, and the docs are honest about what still does not work.
My one set of requests is not to the design; it is that the majority of the library change is untested. Mutation testing shows both dataset_query.rs sites can be reverted to None with the entire suite still green — and that is the path the PR itself names as serving POST /v1/fluree/query. Add a multi-ledger dataset test and a policy-enforced variant (I confirmed both are ~60 lines and do go red on mutation), gate bm25 drop behind --force like its Iceberg sibling, and this is a clear approve.
Adherence to repo commitments:
- Patterns/abstractions:
⚠️ Extends the existingBm25IndexProviderslot correctly and invents no parallel construct — but leavesFromQueryBuilder::with_index_providers()as a stub that hard-errors while the capability it advertises now works without it (query/builder.rs:151). - Performance (speed first, memory second): ✔️ No hot-path regression.
FlureeIndexProvideris one&Flureereference with no allocation, stored once per query in a struct already built once per query, and read only by theIndexSearchoperator. Noted for the record: omittingf:searchLimityieldstop_k(usize::MAX), which scores the whole corpus viascore_all()with no WAND early termination (scoring.rs:400-405) — pre-existing, but newly reachable from the public route. - Testing: ✖️ The new test is correctly wired into
grp_graphsource.rs:16-17and does run, but covers only 1 of 3 wiring sites (proven by per-site mutation). No policy test on the newly opened path; no server-level HTTP test; no CLI test for 253 new lines.
Blocking on the dataset-path test, the policy test, and the bm25 drop --force gate before merge.
…pt-in Addresses @aaj3f's review on fluree#1543. **Tests.** The review asked for one multi-ledger dataset test to cover both `dataset_query.rs` sites. Per-site mutation shows that is not enough: a multi-ledger `from` does not select between the two sites, the builder method does. query_connection / query_from().execute_formatted() -> execute_dataset_internal_with_r2rml -> execute_dataset_into_with_r2rml query_from().execute_tracked() -> execute_dataset_tracked -> execute_dataset_tracked_with_r2rml So the suggested test leaves the tracked site green. Three tests now cover the three wiring sites 1:1 — each mutation to `bm25_provider: None` fails exactly one of them, verified with a forced recompile per experiment: dataset_query.rs:705 -> bm25_embedded_search_via_dataset_path dataset_query.rs:855 -> bm25_embedded_search_via_tracked_dataset_path view/mod.rs macro -> the two plain-route tests Plus a policy regression test on the plain `query_connection` route: a control proves both docs match, then an `f:onProperty ex:title` policy scoped to Alice-authored docs keeps doc1 and drops doc2's hit. It sits on the plain route rather than the dataset path deliberately — with >1 active graph `conservative_multi_graph` hides every hit under any policy, so a dataset-path assertion degrades to "nothing came back", which passes just as well if enforcement broke. **`GraphSourceMode::IndexProviders` deleted.** It advertised the capability this change enables while `validate()` rejected it outright, so after this PR the API told users the opposite of the truth in both directions. Removed the variant, the validate arm, `set_index_providers()`, and all five `with_index_providers()` methods (`query/builder.rs` x3, `graph_query_builder.rs` x2 — the review cited one). Zero callers in the repo. Technically a public-API removal, but every call already hard-errored, so no working caller can break. **`bm25 drop --force`.** Drop retracts the nameservice record and deletes snapshot blobs with no confirmation, while both siblings gate — `fluree drop` for a ledger and the Iceberg graph-source drop. Same flag, same doc comment, same error wording as `commands/drop.rs`. **Provider comment.** All three sites now record why this uses the "legacy" `bm25_provider` and not the "preferred" `bm25_search_provider`: only index-provider mode can enforce view policy on a hit; search-provider mode fails closed and would return zero rows for every policy-enforced query. The old comment said "parity with query_dataset_with_bm25", which invites exactly the upgrade that breaks it. **Help text.** `-f` claimed "`-` for stdin", which `input.rs` never handled (`read_to_string("-")`). Now describes the implicit stdin that does work. Not addressed: CLI tests for `run_list`, deferred to the follow-up that rewrites it with a TRACKED column; and the `f:searchLimit` -> `score_all` note, which the review flagged for the record rather than as a request. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Thank you — the mutation testing was the useful part of this review, and it turned out to be more useful I added the multi-ledger dataset test you sketched and confirmed it goes red exactly as you predicted.
So the one dataset test leaves the tracked site green. There are now three tests, and each of the three Everything else you asked for:
The only thing I've left alone is the |
…pt-in Addresses @aaj3f's review on fluree#1543. **Tests.** The review asked for one multi-ledger dataset test to cover both `dataset_query.rs` sites. Per-site mutation shows that is not enough: a multi-ledger `from` does not select between the two sites, the builder method does. query_connection / query_from().execute_formatted() -> execute_dataset_internal_with_r2rml -> execute_dataset_into_with_r2rml query_from().execute_tracked() -> execute_dataset_tracked -> execute_dataset_tracked_with_r2rml So the suggested test leaves the tracked site green. Three tests now cover the three wiring sites 1:1 — each mutation to `bm25_provider: None` fails exactly one of them, verified with a forced recompile per experiment: dataset_query.rs:705 -> bm25_embedded_search_via_dataset_path dataset_query.rs:855 -> bm25_embedded_search_via_tracked_dataset_path view/mod.rs macro -> the two plain-route tests Plus a policy regression test on the plain `query_connection` route: a control proves both docs match, then an `f:onProperty ex:title` policy scoped to Alice-authored docs keeps doc1 and drops doc2's hit. It sits on the plain route rather than the dataset path deliberately — with >1 active graph `conservative_multi_graph` hides every hit under any policy, so a dataset-path assertion degrades to "nothing came back", which passes just as well if enforcement broke. **`GraphSourceMode::IndexProviders` deleted.** It advertised the capability this change enables while `validate()` rejected it outright, so after this PR the API told users the opposite of the truth in both directions. Removed the variant, the validate arm, `set_index_providers()`, and all five `with_index_providers()` methods (`query/builder.rs` x3, `graph_query_builder.rs` x2 — the review cited one). Zero callers in the repo. Technically a public-API removal, but every call already hard-errored, so no working caller can break. **`bm25 drop --force`.** Drop retracts the nameservice record and deletes snapshot blobs with no confirmation, while both siblings gate — `fluree drop` for a ledger and the Iceberg graph-source drop. Same flag, same doc comment, same error wording as `commands/drop.rs`. **Provider comment.** All three sites now record why this uses the "legacy" `bm25_provider` and not the "preferred" `bm25_search_provider`: only index-provider mode can enforce view policy on a hit; search-provider mode fails closed and would return zero rows for every policy-enforced query. The old comment said "parity with query_dataset_with_bm25", which invites exactly the upgrade that breaks it. **Help text.** `-f` claimed "`-` for stdin", which `input.rs` never handled (`read_to_string("-")`). Now describes the implicit stdin that does work. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
9d80a61 to
2cb737c
Compare
…pt-in Addresses @aaj3f's review on fluree#1543. **Tests.** The review asked for one multi-ledger dataset test to cover both `dataset_query.rs` sites. Per-site mutation shows that is not enough: a multi-ledger `from` does not select between the two sites, the builder method does. query_connection / query_from().execute_formatted() -> execute_dataset_internal_with_r2rml -> execute_dataset_into_with_r2rml query_from().execute_tracked() -> execute_dataset_tracked -> execute_dataset_tracked_with_r2rml So the suggested test leaves the tracked site green. Three tests now cover the three wiring sites 1:1 — each mutation to `bm25_provider: None` fails exactly one of them, verified with a forced recompile per experiment: dataset_query.rs:705 -> bm25_embedded_search_via_dataset_path dataset_query.rs:855 -> bm25_embedded_search_via_tracked_dataset_path view/mod.rs macro -> the two plain-route tests Plus a policy regression test on the plain `query_connection` route: a control proves both docs match, then an `f:onProperty ex:title` policy scoped to Alice-authored docs keeps doc1 and drops doc2's hit. It sits on the plain route rather than the dataset path deliberately — with >1 active graph `conservative_multi_graph` hides every hit under any policy, so a dataset-path assertion degrades to "nothing came back", which passes just as well if enforcement broke. **`GraphSourceMode::IndexProviders` deleted.** It advertised the capability this change enables while `validate()` rejected it outright, so after this PR the API told users the opposite of the truth in both directions. Removed the variant, the validate arm, `set_index_providers()`, and all five `with_index_providers()` methods (`query/builder.rs` x3, `graph_query_builder.rs` x2 — the review cited one). Zero callers in the repo. Technically a public-API removal, but every call already hard-errored, so no working caller can break. **`bm25 drop --force`.** Drop retracts the nameservice record and deletes snapshot blobs with no confirmation, while both siblings gate — `fluree drop` for a ledger and the Iceberg graph-source drop. Same flag, same doc comment, same error wording as `commands/drop.rs`. **Provider comment.** All three sites now record why this uses the "legacy" `bm25_provider` and not the "preferred" `bm25_search_provider`: only index-provider mode can enforce view policy on a hit; search-provider mode fails closed and would return zero rows for every policy-enforced query. The old comment said "parity with query_dataset_with_bm25", which invites exactly the upgrade that breaks it. **Help text.** `-f` claimed "`-` for stdin", which `input.rs` never handled (`read_to_string("-")`). Now describes the implicit stdin that does work. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… path Wire `FlureeIndexProvider` as the `bm25_provider` on the query ExecutionContext built by the dataset and single-graph view paths, so an embedded `f:searchText` graph-source search executes in-process through the normal query route (`POST /v1/fluree/query`) — not only via the dedicated `query_connection_with_bm25` API method. Previously such a query parsed but failed at execution with "BM25 IndexSearch requires ExecutionContext.bm25_search_provider or bm25_provider (not configured)". - `execute_dataset_into_with_r2rml` / `execute_dataset_tracked_with_r2rml` (dataset path) and the `view_context_config!` macro (single-graph path) each create a `FlureeIndexProvider::new(self)` — a zero-cost `&Fluree` wrapper — before building the context and set `bm25_provider: Some(&provider)`, mirroring how the R2RML providers are already threaded. The provider is only consulted by the `IndexSearch` operator, so non-search queries are unaffected. - Vector (`f:queryVector`) is left for a follow-up: its provider impl is `#[cfg(feature = "vector")]` and not in the default server build. Tests: +`bm25_embedded_search_via_plain_query_connection` (runs `f:searchText` through the plain `query_connection` — the path the HTTP route uses — and asserts it returns scored hits). Full bm25 integration suite green; fmt + clippy (-D warnings) clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add `fluree bm25 create/list/sync/drop` — an in-process wrapper over the
Rust-API BM25 graph-source operations (`Bm25CreateConfig` +
`create_full_text_index`, `sync_bm25_index`, `drop_full_text_index`), which
have no HTTP endpoint today. The commands run against local storage (so they
work under `docker exec` against a running server's data directory):
- `create` — build a BM25 index over a source ledger from an index query
- `list` — tabular view (NAME / BRANCH / SOURCE LEDGER / INDEX_T / LEDGER_T /
STALE), same look-and-feel as `fluree list`; `--stale` prints
`name:branch` per line for scripting the sync loop
- `sync` — incremental sync up to the source ledger head (prints the
watermark old -> new and upserted/removed counts)
- `drop` — retract the index and delete its snapshots
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- indexing-and-search/bm25.md: BM25 indexes are managed via the `fluree bm25` CLI (create/list/sync/drop) as well as the Rust API — add a CLI Management section. Clarify that an `f:searchText` query executes over the standard `POST /v1/fluree/query` route (a JSON-LD/FQL feature — NOT available via SPARQL), and that embedded mode is what serves it in-process. - graph-sources/bm25.md: embedded search over the query API is now wired (path 1, no search service needed); only the remote-delegation half (server -> fluree-search-httpd via SearchDeploymentConfig) remains the documented near-term gap. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The bm25 CLI commit added `pub mod bm25;` after `pub mod export;` in fluree-db-cli/src/commands/mod.rs. rustfmt's default `reorder_modules` sorts module declarations, so `cargo fmt --all -- --check` failed in both the `fmt` and `testsuite-sparql` CI jobs. Move the declaration to its alphabetical position (after `pub mod auth;`). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…pt-in Addresses @aaj3f's review on fluree#1543. **Tests.** The review asked for one multi-ledger dataset test to cover both `dataset_query.rs` sites. Per-site mutation shows that is not enough: a multi-ledger `from` does not select between the two sites, the builder method does. query_connection / query_from().execute_formatted() -> execute_dataset_internal_with_r2rml -> execute_dataset_into_with_r2rml query_from().execute_tracked() -> execute_dataset_tracked -> execute_dataset_tracked_with_r2rml So the suggested test leaves the tracked site green. Three tests now cover the three wiring sites 1:1 — each mutation to `bm25_provider: None` fails exactly one of them, verified with a forced recompile per experiment: dataset_query.rs:705 -> bm25_embedded_search_via_dataset_path dataset_query.rs:855 -> bm25_embedded_search_via_tracked_dataset_path view/mod.rs macro -> the two plain-route tests Plus a policy regression test on the plain `query_connection` route: a control proves both docs match, then an `f:onProperty ex:title` policy scoped to Alice-authored docs keeps doc1 and drops doc2's hit. It sits on the plain route rather than the dataset path deliberately — with >1 active graph `conservative_multi_graph` hides every hit under any policy, so a dataset-path assertion degrades to "nothing came back", which passes just as well if enforcement broke. **`GraphSourceMode::IndexProviders` deleted.** It advertised the capability this change enables while `validate()` rejected it outright, so after this PR the API told users the opposite of the truth in both directions. Removed the variant, the validate arm, `set_index_providers()`, and all five `with_index_providers()` methods (`query/builder.rs` x3, `graph_query_builder.rs` x2 — the review cited one). Zero callers in the repo. Technically a public-API removal, but every call already hard-errored, so no working caller can break. **`bm25 drop --force`.** Drop retracts the nameservice record and deletes snapshot blobs with no confirmation, while both siblings gate — `fluree drop` for a ledger and the Iceberg graph-source drop. Same flag, same doc comment, same error wording as `commands/drop.rs`. **Provider comment.** All three sites now record why this uses the "legacy" `bm25_provider` and not the "preferred" `bm25_search_provider`: only index-provider mode can enforce view policy on a hit; search-provider mode fails closed and would return zero rows for every policy-enforced query. The old comment said "parity with query_dataset_with_bm25", which invites exactly the upgrade that breaks it. **Help text.** `-f` claimed "`-` for stdin", which `input.rs` never handled (`read_to_string("-")`). Now describes the implicit stdin that does work. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The bm25 commands shipped with no tests while `tests/integration.rs` covers essentially every other command group. Seven end-to-end tests through the real binary, in the same `assert_cmd` + temp-dir style. The two worth calling out, both pinning logic in `run_list`: - **Staleness.** A commit after the index is built must flip STALE to YES and make `--stale` emit the alias, and `sync` must clear it again. That is the loop a maintenance job runs, so it should not be able to regress silently. - **The branchless dependency alias.** `bm25 create --ledger docs` persists the dependency verbatim as `docs`, while ledger records are keyed `docs:main`, so the lookup only matches through the implicit-`:main` retry. Removing that retry makes exactly this test fail (verified) — without it `LEDGER_T` renders `-`, the index reports itself never-stale, and a `--stale`-driven maintenance loop skips it forever. Plus: empty-list message, the fresh-index listing, `drop` refusing without `--force` and succeeding with it, and the two `create` input rejections (a name containing ':' and malformed JSON). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2cb737c to
a3ff253
Compare
Adds a third read-only MCP tool, `fql_query`, alongside `sparql_query` and
`get_data_model`. It runs a SELECT-style Fluree FQL (JSON-LD) body through
`run_jsonld_subquery` — the same connection path the HTTP /v1/fluree/query route
uses, which wires the BM25 index provider — so an embedded `f:searchText`
full-text block executes in-process. BM25 is FQL-only, so this is the tool that
gives an agent full-text / graph-aware-RAG retrieval that `sparql_query` cannot.
- Forces `opts.identity` from the MCP token (non-spoofable); rejects non-SELECT
and `from`-less bodies. Returns the same byte-budgeted Agent JSON envelope as
`sparql_query`, governed by the same --mcp-agent-json-max-bytes /
--mcp-query-timeout-ms settings.
- Tests (mcp_agent_json): fql_agent_json_envelope_shape,
fql_requires_authenticated_identity, fql_rejects_non_select_and_missing_from.
- Docs: new docs/query/mcp.md ("Querying over MCP"); cross-linked from the query
README, the SPARQL/JSON-LD pages, the AI overview, and the MCP config reference.
Stacks on the iceberg-materialize (fluree#1422) + bm25-search (fluree#1543) branches; kept on
the fork for now.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…pt-in Addresses @aaj3f's review on fluree#1543. **Tests.** The review asked for one multi-ledger dataset test to cover both `dataset_query.rs` sites. Per-site mutation shows that is not enough: a multi-ledger `from` does not select between the two sites, the builder method does. query_connection / query_from().execute_formatted() -> execute_dataset_internal_with_r2rml -> execute_dataset_into_with_r2rml query_from().execute_tracked() -> execute_dataset_tracked -> execute_dataset_tracked_with_r2rml So the suggested test leaves the tracked site green. Three tests now cover the three wiring sites 1:1 — each mutation to `bm25_provider: None` fails exactly one of them, verified with a forced recompile per experiment: dataset_query.rs:705 -> bm25_embedded_search_via_dataset_path dataset_query.rs:855 -> bm25_embedded_search_via_tracked_dataset_path view/mod.rs macro -> the two plain-route tests Plus a policy regression test on the plain `query_connection` route: a control proves both docs match, then an `f:onProperty ex:title` policy scoped to Alice-authored docs keeps doc1 and drops doc2's hit. It sits on the plain route rather than the dataset path deliberately — with >1 active graph `conservative_multi_graph` hides every hit under any policy, so a dataset-path assertion degrades to "nothing came back", which passes just as well if enforcement broke. **`GraphSourceMode::IndexProviders` deleted.** It advertised the capability this change enables while `validate()` rejected it outright, so after this PR the API told users the opposite of the truth in both directions. Removed the variant, the validate arm, `set_index_providers()`, and all five `with_index_providers()` methods (`query/builder.rs` x3, `graph_query_builder.rs` x2 — the review cited one). Zero callers in the repo. Technically a public-API removal, but every call already hard-errored, so no working caller can break. **`bm25 drop --force`.** Drop retracts the nameservice record and deletes snapshot blobs with no confirmation, while both siblings gate — `fluree drop` for a ledger and the Iceberg graph-source drop. Same flag, same doc comment, same error wording as `commands/drop.rs`. **Provider comment.** All three sites now record why this uses the "legacy" `bm25_provider` and not the "preferred" `bm25_search_provider`: only index-provider mode can enforce view policy on a hit; search-provider mode fails closed and would return zero rows for every policy-enforced query. The old comment said "parity with query_dataset_with_bm25", which invites exactly the upgrade that breaks it. **Help text.** `-f` claimed "`-` for stdin", which `input.rs` never handled (`read_to_string("-")`). Now describes the implicit stdin that does work. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
aaj3f
left a comment
There was a problem hiding this comment.
All three blocking asks are fixed, and I verified each by mutation rather than by reading the response.
(A) Dataset-path test coverage — verified fixed. The round-1 gap was that both dataset_query.rs wiring sites had zero coverage. Per-site mutation now gives a clean 1:1 matrix, each experiment run after touching the source with a confirmed recompile: reverting dataset_query.rs:705 to bm25_provider: None fails exactly bm25_embedded_search_via_dataset_path (3 passed, 1 failed); reverting :855 fails exactly bm25_embedded_search_via_tracked_dataset_path (3 passed, 1 failed); reverting view/mod.rs:113 fails exactly the two plain-route tests (14 passed, 2 failed). The author's diagnosis that a multi-ledger from does not select between the two dataset sites — the builder method does — is correct, and execute_tracked() is indeed the only route to execute_dataset_tracked_with_r2rml.
(B) Policy regression test — verified fixed, and the placement reasoning is right. Short-circuiting search_hit_readable (fluree-db-query/src/search_readability.rs:37) to return Ok(true) turns bm25_embedded_search_enforces_policy_via_plain_query_connection red, so the test pins the actual enforcement mechanism rather than an incidental empty result. Your conservative_multi_graph reasoning also checks out against the code, and it is in fact stronger than stated: search_readability.rs:74-76 hides every hit when any of >1 active graphs carries a policy, and dataset_query.rs:171-172 short-circuits a single-ledger from to the view path — so the dataset path is only ever reachable with >1 ledger, and a selective-enforcement assertion there is impossible to write, not merely weak. The plain route is the only placement that can carry a real assertion. I confirmed the resulting behavior empirically (control 2 rows, policy 0 rows on a two-ledger query); the one gap left is that this limitation isn't documented, which I've raised as an optional item.
(C) bm25 drop --force — verified fixed, exact-pattern. The flag (cli.rs:1195-1197) carries the same /// Required flag to confirm deletion doc comment as both siblings (cli.rs:388 for drop, :2656 for iceberg drop), and the enforcement in commands/bm25.rs:236-241 reproduces commands/drop.rs:15-19 verbatim, error type and message shape included. bm25_drop_requires_force asserts the refusal, that the index survives the refusal, and that --force succeeds.
(D) with_index_providers() deletion — verified complete. git grep for with_index_providers, IndexProviders, and set_index_providers returns zero hits across all tracked files, so nothing dangles. Clippy is clean both with --all-features --all-targets and under default features, confirming the GraphSourceMode variant removal doesn't break the non-iceberg build. Removing a builder mode whose entire behavior was to return an error is the right call over making it work.
Also verified: (E) the provider-slot comment is present at all three sites and its claim is accurate (bm25/operator.rs:248-257); (F) the help-text fix is correct — input.rs:43 opens - as a literal file, so the old "- for stdin" was wrong while the implicit stdin path at :31-33 does work; (G) the seven CLI tests pass by name and have teeth — inverting the staleness comparison (commands/bm25.rs:89) fails both staleness tests, and removing only the :main retry (:87) fails exactly bm25_list_resolves_a_branchless_dependency_alias, matching your stated PR claim precisely.
Recommend merge once the two one-line docs touch-ups and the trailer removal are done — none of them gate the code, which is correct and now genuinely well covered.
Two review follow-ups from @aaj3f, both documentation-only. The CLI reference table documented `fluree bm25 drop --index <gs>`, which now hard-errors with "use --force to confirm deletion of '<gs>'". This was self-inconsistency introduced inside the PR: the docs commit shipped the table two commits before the `--force` gate landed, so a reader copy-pasting from the docs hit the error on their first try. The second is a pre-existing limitation this PR newly makes reachable from `POST /v1/fluree/query`. `conservative_multi_graph` (fluree-db-query/src/search_readability.rs:72-73) hides every hit when a multi-graph scope carries a policy, because per-flake readability cannot be resolved across graphs — and the single-ledger fast path means the dataset route is only ever entered with more than one ledger, so that conservative branch is the only one a policy-enforced dataset search can take. It is fail-closed and so not a leak, but it is silent: the same query returns rows with policies off and zero rows with them on, with no error to explain the difference. Now stated in the Querying section. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
e43a720 to
231b428
Compare
|
It looks like all of the outstanding issues have been addressed so I am merging. Thanks @christophediprima! |
…conflict-free review Single conflict: fluree-db-api/src/lib.rs — convergent cfg-orphan fix. Both #1566 and the audit side moved build()'s #[cfg(native)] doc block below with_secret_resolver (kept iceberg-gated). The cfg fix is byte-identical on both sides; resolved the lone doc-wording hunk to main's #1566 text, so the merged file equals origin/main's api/lib.rs (zero diff, no audit feature lost). hash_join.rs, optional.rs, planner.rs auto-merged (disjoint hunks: audit #1477 fast-path vs main cypher #1553).
Adds a third read-only MCP tool, `fql_query`, alongside `sparql_query` and
`get_data_model`. It runs a SELECT-style Fluree FQL (JSON-LD) body through
`run_jsonld_subquery` — the same connection path the HTTP /v1/fluree/query route
uses, which wires the BM25 index provider — so an embedded `f:searchText`
full-text block executes in-process. BM25 is FQL-only, so this is the tool that
gives an agent full-text / graph-aware-RAG retrieval that `sparql_query` cannot.
- Forces `opts.identity` from the MCP token (non-spoofable); rejects non-SELECT
and `from`-less bodies. Returns the same byte-budgeted Agent JSON envelope as
`sparql_query`, governed by the same --mcp-agent-json-max-bytes /
--mcp-query-timeout-ms settings.
- Tests (mcp_agent_json): fql_agent_json_envelope_shape,
fql_requires_authenticated_identity, fql_rejects_non_select_and_missing_from.
- Docs: new docs/query/mcp.md ("Querying over MCP"); cross-linked from the query
README, the SPARQL/JSON-LD pages, the AI overview, and the MCP config reference.
Originally written on the iceberg-materialize (fluree#1422) + bm25-search (fluree#1543) stack
and kept on the fork; both are now in this branch's base, but the rebuild of
tadaweb/main onto upstream/main never replayed this commit, so it is restored here
verbatim from archive/iceberg-materialize-bm25-pre-rebuild.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Two related, independent changes that make Fluree's BM25 full-text search usable without a second process or the Rust API:
f:searchTextnow executes over the normal query route (POST /v1/fluree/query), not only via the dedicatedquery_connection_with_bm25API method or the standalonefluree-search-httpdservice.fluree bm25CLI to create, list, sync, and drop BM25 indexes (the only management surface that ships today is the Rust API — there is no HTTP endpoint for index management).Both are self-contained and could land independently; they are grouped here because they are the two halves of "use BM25 from a running Fluree server."
1. Embedded BM25 over
/v1/fluree/queryA query with an
f:searchText/f:graphSourcewhere-clause parses correctly (the JSON-LD parser lowers it to aPattern::IndexSearch) but, on the standard query route, failed at execution withBM25 IndexSearch requires ExecutionContext.bm25_search_provider or bm25_provider (not configured). The query is valid; the execution context that route builds simply never wired a BM25 provider. The only code that wired one wasquery_connection_with_bm25/query_dataset_with_bm25, whose sole callers were tests — the server never called them — so embedded search was unreachable over HTTP. (The docs describe embedded search as the default deployment mode and flag the missing in-server wiring as a "near-term gap".)Fix. Wire
FlureeIndexProvideras thebm25_provideron theExecutionContextat the sites the HTTP route funnels through:execute_dataset_into_with_r2rmlandexecute_dataset_tracked_with_r2rml(the dataset path used byPOST /v1/fluree/query), and the sharedview_context_config!macro (the single-graph view path), for parity. Each creates aFlureeIndexProvider::new(self)— a zero-cost&Flureewrapper — declared before the context so it outlives the borrow, mirroring exactly how the R2RML providers are already threaded through those same sites. The provider is only consulted by theIndexSearchoperator, so non-search queries are unaffected; this is the same providerquery_dataset_with_bm25already used, just made available on the standard path.Verified end-to-end.
POST /v1/fluree/querywith a BM25 search block now returns ranked?doc/?scorebindings instead of a 400 — confirmed on a real index ("nature"→ two profiles, scored 3.78 and 2.68). A new integration test,bm25_embedded_search_via_plain_query_connection, runsf:searchTextthrough the plainquery_connection(the path the HTTP route uses) and asserts scored results — it would have returned the "not configured" error before this change.Not covered (deliberately): SPARQL. The
f:search block is recognized only by the JSON-LD parser (parse/node_map.rs); the SPARQL parser never constructs aPattern::IndexSearch, so a SPARQL query with those predicates matches them as ordinary triples and silently returns nothing. Adding SPARQL search is a separate parser/lowering change influree-db-sparql. Vector (f:queryVector) is also out of scope here: its provider impl is#[cfg(feature = "vector")]and not in the default server build, so wiring it would be dead code in the shipped binary — a one-line follow-up once that feature is enabled.2.
fluree bm25CLIBM25 index management is Rust-API-only (
Bm25CreateConfig+create_full_text_index,sync_bm25_index,drop_full_text_index) with no HTTP route. This adds a thin CLI wrapper that runs in-process against local storage, so it works underdocker execagainst a running server's data directory (native storage uses per-file locks, not a whole-store exclusive lock).fluree bm25 create --name <n> --ledger <l> -f <index-query.json>— build a BM25 index over a source ledger from an indexing query.fluree bm25 list [--stale]— tabular view (NAME / BRANCH / SOURCE LEDGER / INDEX_T / LEDGER_T / STALE), the same look-and-feel asfluree list.--staleprintsname:branchper line so a maintenance loop can be scripted:for i in $(fluree bm25 list --stale); do fluree bm25 sync --index "$i"; done.fluree bm25 sync --index <gs>— incremental sync up to the source ledger's head; prints the watermarkold -> newand upserted/removed counts (falls back to a full resync when no affected subjects are detected).fluree bm25 drop --index <gs>— retract the index in the nameservice and delete its snapshot blobs.Tests
Full BM25 integration suite green (
fluree-db-api --test grp_graphsource, incl. the newbm25_embedded_search_via_plain_query_connection);cargo fmt --checkandclippy -D warningsclean on bothfluree-db-apiandfluree-db-cli. The branch is based on currentmainand compiles + tests against it (not just the fork's older base).