Skip to content

feat: take the text field option highlight_offsets in the gRPC API, the HTTP gateway, MCP, the CLI wizard and the five bindings, which used to fix it to false - #1901

Merged
mosuka merged 1 commit into
mainfrom
feat/highlight-offsets-front-ends
Dec 5, 2026

Conversation

@mosuka

@mosuka mosuka commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #1879

A text field that sets highlight_offsets stores its tokens, and a search highlights it from them instead of analyzing each hit's text again (Issues #596 and #1880). Only a schema file and the Rust TextOption could set it (investigation):

  • gRPC: the TextOption message had no field for it. field_option_to_proto dropped it and field_option_from_proto set the default, so a schema written through the server lost it.
  • MCP: it reads field_option_json into the core FieldOption and converts it to proto, so it accepted the key and dropped it on the way.
  • The HTTP gateway rejected the key.
  • The CLI and the bindings: the create schema wizard did not ask for it, and the five bindings fixed it to false.

Now every front end takes it and round-trips it. Nothing breaks: the proto gets an optional field, and each binding gets a parameter at the end.

Changes

  • laurus-server/proto/laurus/v1/index.proto: TextOption gets optional bool highlight_offsets = 8. It is a tri-state like term_vectors: unset is the engine's default, false.

  • laurus-server/src/convert/schema.rs:

    • field_option_to_proto sets Some(o.highlight_offsets).
    • field_option_from_proto reads unwrap_or(default).
    • MCP, which goes through field_option_to_proto, now carries the option too.
  • laurus-server/src/gateway/convert.rs:

    • TEXT_OPTION_KEYS gets the key.
    • json_to_proto_field_option reads it with json_optional_bool, so a non-boolean is a 400, as for the other boolean keys.
    • proto_field_option_to_json writes it.
  • laurus-cli/src/commands/create.rs: the wizard asks "Store tokens for highlighting?" (default no) for an indexed and stored field, the only kind the option takes effect on. It asks for position_increment_gap only for a multi-valued field in the same way.

  • The five bindings' add_text_field: a last parameter, default false, so positional callers keep working.

    Binding Parameter
    Python keyword highlight_offsets=False
    Node.js highlightOffsets?, after positionIncrementGap
    WASM highlightOffsets?, after positionIncrementGap
    Ruby keyword highlight_offsets: false
    PHP bool $highlightOffsets = false, after $positionIncrementGap
  • Docs, in English and Japanese:

    • The gRPC API: the TextOption fields, and a paragraph on the tri-state. The paragraph notes that UpdateField replaces the whole option, so leaving the key out turns the option off without reindex. It also notes that an older server ignores the field.
    • The HTTP gateway: its boolean keys, and the same note for PATCH.
    • The CLI's commands.md: the wizard's text options.
    • Each binding's API reference, and the PHP README.
    • "Stored tokens for highlighting": how each front end sets the option, in place of "do not take it yet".

Tests

Test What it checks
highlight_offsets_round_trips_through_proto_and_unset_defaults_to_false (convert/schema.rs, new) true and false round-trip through the proto. An unset field reads as false. term_vectors beside it keeps its own value.
create_index_keeps_highlight_offsets (tests/http_boolean_key_validation_test.rs, new) Through the gateway and the server, GET /v1/schema gives back true as set, and false for a field that left it out.
The gateway's boolean-key tests (changed) highlight_offsets joins the text keys of FIELD_OPTION_BOOLEAN_KEYS and TEXT_KEYS. So a non-boolean is rejected on POST /v1/index, POST /v1/schema/fields and PATCH. null is the same as omitting it, and true and false round-trip.
field_option_json_keeps_highlight_offsets_on_the_way_to_the_server (laurus-mcp, new) {"Text": {"highlight_offsets": true}}, read as MCP reads it, reaches the proto as Some(true), and false as Some(false).
Each binding's new test (Python test_highlight_offsets.py, Node.js highlight_offsets.spec.mjs, Ruby test_highlight_offsets.rb, PHP LaurusTest.php) An index created with the parameter writes highlight_offsets = true to its schema.toml. One created with false, or without it, writes false.
add_text_field_sets_highlight_offsets (laurus-wasm/src/schema.rs, new) The built schema's TextOption has the value passed, and false when it is left out.

The CLI wizard. No test drives its prompts. It was run under a pseudo-terminal (Python's pty):

  • With an indexed and stored text field, it asked "Store tokens for highlighting?"; answering yes wrote highlight_offsets = true.
  • With Stored? answered no, it did not ask, and wrote highlight_offsets = false.

RED. Each element was disabled in turn, the tests run, and the sources restored and compared:

Element Failed
E1: field_option_to_proto drops the field the round trip, the HTTP test, and the MCP test
E2: field_option_from_proto takes the default the round trip and the HTTP test
E3: TEXT_OPTION_KEYS lacks the key the two gateway boolean-key tests, the HTTP test, and the three HTTP 400 tests
E4: proto_field_option_to_json does not write it the gateway's round-trip test and the HTTP test
E5: all five bindings ignore the parameter (one run) each binding's new test, and nothing else (1 failure in each of Node.js, Ruby, PHP, Python and WASM)
E6: the wizard never asks the pseudo-terminal check: no question, so the stored case timed out

On main the new field and parameters do not exist, so the new tests do not compile or run there. The elements above show what each test holds.

Checks

The CI's checks, run locally on Linux x86_64 (evo-x2) with stable 1.100.1 on a506343b (this change rebased on de2f1797):

Check Result
cargo fmt --all -- --check OK
Workspace clippy, --all-targets --features embeddings-all -- -D warnings OK
laurus-wasm clippy for wasm32-unknown-unknown, --tests OK
scripts/check-rustdoc.py OK
scripts/check-ci-filters.py, check-job-timeouts.py and their tests OK
scripts/check-binding-snippets.py OK
laurus tests (embeddings-all,pq-fastscan) 4,288 passed, 0 failed, 28 ignored
laurus-server, laurus-mcp, laurus-cli tests (embeddings-all) 336, 54 and 89 passed, 0 failed
Node.js, Ruby, PHP, Python and WASM bindings 334, 228 (runs), 233, 360 and 90 passed, 0 failed
markdownlint on the 20 docs 0 warnings

CI

Run 47488888416 on a506343b: 26 jobs passed and none failed. Test laurus was skipped, as the change does not touch the core crate.

  • Test laurus-server (Linux x86_64, Linux aarch64, Windows) ran the conversion round trip and create_index_keeps_highlight_offsets.
  • Test laurus-mcp (Linux x86_64 and aarch64) ran the MCP test.
  • Test laurus-python and Test laurus-nodejs (Linux x86_64 and aarch64) ran their new tests.
  • Test laurus-wasm ran add_text_field_sets_highlight_offsets.
  • Ruby and PHP print no test names. Both their jobs ran 228 runs and 233 tests with none failed, the counts of the local runs with the two new tests each.
  • Binding Snippets passed.

Not done

  • The wizard's other missing text options. The CLI's commands.md lists only some of them; this adds only highlight_offsets. The missing ones are doc_values, multi_valued and the analyzer.
  • Rejecting highlight_offsets on a field that is not indexed and stored. The core lets it have no effect there, and that stays.
  • An MCP test through the tool itself. The MCP test calls the same two steps the tools use (serde, then field_option_to_proto), not the tool over rmcp, as no gRPC server runs in MCP's tests.

…he HTTP gateway, MCP, the CLI wizard and the five bindings, which used to fix it to false

Issue #1879: a text field that sets highlight_offsets stores its tokens,
and a search highlights it from them instead of analyzing each hit's
text again (Issues #596 and #1880). Only a schema file and the Rust
TextOption could set it:

- The gRPC TextOption had no field for it: field_option_to_proto dropped
  it, and field_option_from_proto set the default, so a schema written
  through the server lost it.
- MCP reads field_option_json into the core FieldOption and converts it
  to proto, so it accepted the key and dropped it on the way.
- The HTTP gateway rejected the key, the CLI's create schema wizard did
  not ask for it, and the five bindings fixed it to false.

Now:

- The proto's TextOption has optional bool highlight_offsets = 8, a
  tri-state like term_vectors: unset is the engine's default (false).
  Both conversions carry it, and so does MCP.
- The gateway reads and writes the key of a text option, and rejects a
  non-boolean value as it does for the other boolean keys.
- The wizard asks "Store tokens for highlighting?" (default no) for an
  indexed and stored field, the only kind it takes effect on.
- Each binding's add_text_field takes it as its last parameter, default
  false, so positional callers keep working: highlight_offsets in Python
  and Ruby, highlightOffsets in Node.js, WASM and PHP.
- Docs: the gRPC API, the HTTP gateway, the CLI, each binding's API
  reference and the PHP README list it, and "Stored tokens for
  highlighting" says how each front end sets it.
@mosuka
mosuka merged commit fb2f6ba into main Dec 5, 2026
27 checks passed
@mosuka
mosuka deleted the feat/highlight-offsets-front-ends branch December 5, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: expose the text field option highlight_offsets in the gRPC API, the HTTP gateway, the CLI and the bindings

1 participant