Skip to content

feat: Implement standard tokenizer based on UAX29#547

Open
egolearner wants to merge 1 commit into
alibaba:mainfrom
egolearner:standard-tokenizer-uax29-opt
Open

feat: Implement standard tokenizer based on UAX29#547
egolearner wants to merge 1 commit into
alibaba:mainfrom
egolearner:standard-tokenizer-uax29-opt

Conversation

@egolearner

Copy link
Copy Markdown
Collaborator

Summary:

  • Replace the previous general-category tokenizer with Unicode 17 UAX #29 word-boundary tables generated from official Unicode data.

  • Add the Unicode table generator and generated C++ lookup table.

  • Implement Lucene-style token selection for alphanumeric, numeric, ideographic, hiragana, katakana, hangul, southeast Asian, regional indicator, and common emoji sequences.

  • Keep the public Token contract as text, UTF-8 byte offset, and consecutive position, and validate max_token_length in the Lucene range [1, 1048576].

  • Optimize hot paths with ASCII classification tables, page-indexed Unicode range lookup, lightweight UTF-8 decoding, a thread-local codepoint property cache, compact word-break classes, and non-ASCII dispatch fast paths.

  • Extend tokenizer tests and keep the Unicode WordBreakTest token projection exact.

Differences from Elasticsearch standard tokenizer:

  • zvec does not expose Lucene token type attributes; token type is internal only.

  • zvec offsets are UTF-8 byte offsets, while Elasticsearch/Lucene offsets follow Java character offset semantics.

  • Unicode data is pinned to 17.0.0, so behavior can differ from Elasticsearch versions built with another Lucene or Unicode data version.

  • The emoji handling covers common keycap, modifier, regional-indicator, and Extended_Pictographic ZWJ sequences, but it is not a full copy of Lucene's TR51 emoji grammar.

  • Invalid UTF-8 is skipped at the tokenizer layer; Elasticsearch normally receives already-decoded Java strings.

Summary:

- Replace the previous general-category tokenizer with Unicode 17 UAX alibaba#29 word-boundary tables generated from official Unicode data.

- Add the Unicode table generator and generated C++ lookup table.

- Implement Lucene-style token selection for alphanumeric, numeric, ideographic, hiragana, katakana, hangul, southeast Asian, regional indicator, and common emoji sequences.

- Keep the public Token contract as text, UTF-8 byte offset, and consecutive position, and validate max_token_length in the Lucene range [1, 1048576].

- Optimize hot paths with ASCII classification tables, page-indexed Unicode range lookup, lightweight UTF-8 decoding, a thread-local codepoint property cache, compact word-break classes, and non-ASCII dispatch fast paths.

- Extend tokenizer tests and keep the Unicode WordBreakTest token projection exact.

Differences from Elasticsearch standard tokenizer:

- zvec does not expose Lucene token type attributes; token type is internal only.

- zvec offsets are UTF-8 byte offsets, while Elasticsearch/Lucene offsets follow Java character offset semantics.

- Unicode data is pinned to 17.0.0, so behavior can differ from Elasticsearch versions built with another Lucene or Unicode data version.

- The emoji handling covers common keycap, modifier, regional-indicator, and Extended_Pictographic ZWJ sequences, but it is not a full copy of Lucene's TR51 emoji grammar.

- Invalid UTF-8 is skipped at the tokenizer layer; Elasticsearch normally receives already-decoded Java strings.
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.

1 participant