Repository navigation
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
Conversation
…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.
11 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1879
A text field that sets
highlight_offsetsstores 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 RustTextOptioncould set it (investigation):TextOptionmessage had no field for it.field_option_to_protodropped it andfield_option_from_protoset the default, so a schema written through the server lost it.field_option_jsoninto the coreFieldOptionand converts it to proto, so it accepted the key and dropped it on the way.create schemawizard did not ask for it, and the five bindings fixed it tofalse.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:TextOptiongetsoptional bool highlight_offsets = 8. It is a tri-state liketerm_vectors: unset is the engine's default,false.laurus-server/src/convert/schema.rs:field_option_to_protosetsSome(o.highlight_offsets).field_option_from_protoreadsunwrap_or(default).field_option_to_proto, now carries the option too.laurus-server/src/gateway/convert.rs:TEXT_OPTION_KEYSgets the key.json_to_proto_field_optionreads it withjson_optional_bool, so a non-boolean is a 400, as for the other boolean keys.proto_field_option_to_jsonwrites 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 forposition_increment_gaponly for a multi-valued field in the same way.The five bindings'
add_text_field: a last parameter, defaultfalse, so positional callers keep working.highlight_offsets=FalsehighlightOffsets?, afterpositionIncrementGaphighlightOffsets?, afterpositionIncrementGaphighlight_offsets: falsebool $highlightOffsets = false, after$positionIncrementGapDocs, in English and Japanese:
TextOptionfields, and a paragraph on the tri-state. The paragraph notes thatUpdateFieldreplaces the whole option, so leaving the key out turns the option off withoutreindex. It also notes that an older server ignores the field.PATCH.commands.md: the wizard's text options.Tests
highlight_offsets_round_trips_through_proto_and_unset_defaults_to_false(convert/schema.rs, new)trueandfalseround-trip through the proto. An unset field reads asfalse.term_vectorsbeside it keeps its own value.create_index_keeps_highlight_offsets(tests/http_boolean_key_validation_test.rs, new)GET /v1/schemagives backtrueas set, andfalsefor a field that left it out.highlight_offsetsjoins the text keys ofFIELD_OPTION_BOOLEAN_KEYSandTEXT_KEYS. So a non-boolean is rejected onPOST /v1/index,POST /v1/schema/fieldsandPATCH.nullis the same as omitting it, andtrueandfalseround-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 asSome(true), andfalseasSome(false).test_highlight_offsets.py, Node.jshighlight_offsets.spec.mjs, Rubytest_highlight_offsets.rb, PHPLaurusTest.php)highlight_offsets = trueto itsschema.toml. One created withfalse, or without it, writesfalse.add_text_field_sets_highlight_offsets(laurus-wasm/src/schema.rs, new)TextOptionhas the value passed, andfalsewhen it is left out.The CLI wizard. No test drives its prompts. It was run under a pseudo-terminal (Python's
pty):highlight_offsets = true.Stored?answered no, it did not ask, and wrotehighlight_offsets = false.RED. Each element was disabled in turn, the tests run, and the sources restored and compared:
field_option_to_protodrops the fieldfield_option_from_prototakes the defaultTEXT_OPTION_KEYSlacks the keyproto_field_option_to_jsondoes not write itOn
mainthe 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 onde2f1797):cargo fmt --all -- --check--all-targets --features embeddings-all -- -D warningslaurus-wasmclippy forwasm32-unknown-unknown,--testsscripts/check-rustdoc.pyscripts/check-ci-filters.py,check-job-timeouts.pyand their testsscripts/check-binding-snippets.pylaurustests (embeddings-all,pq-fastscan)laurus-server,laurus-mcp,laurus-clitests (embeddings-all)CI
Run 47488888416 on
a506343b: 26 jobs passed and none failed.Test lauruswas skipped, as the change does not touch the core crate.Test laurus-server(Linux x86_64, Linux aarch64, Windows) ran the conversion round trip andcreate_index_keeps_highlight_offsets.Test laurus-mcp(Linux x86_64 and aarch64) ran the MCP test.Test laurus-pythonandTest laurus-nodejs(Linux x86_64 and aarch64) ran their new tests.Test laurus-wasmranadd_text_field_sets_highlight_offsets.Not done
commands.mdlists only some of them; this adds onlyhighlight_offsets. The missing ones aredoc_values,multi_valuedand the analyzer.highlight_offsetson a field that is not indexed and stored. The core lets it have no effect there, and that stays.field_option_to_proto), not the tool over rmcp, as no gRPC server runs in MCP's tests.