Repository navigation
Conversation
b142608 to
cf5a90a
Compare
|
Please find a better name for it. |
|
Workflow [PR], commit [d822bd8] Summary: ❌
AI ReviewSummaryThis PR adds a new PR Metadata
Findings
💡 Nits
Final VerdictStatus:
LLVM Coverage ReportMeasured on commit d822bd8.
Changed lines: Changed C/C++ lines covered: 214/219 (97.72%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
asciiCJK_v2 tokenizer based on StringZilla UAX #29 word segmentationsplitByWordBoundaries tokenizer based on StringZilla UAX #29 word segmentation
| /// argument entries only relevant to those tokenizers, are dropped too. | ||
| FunctionDocumentation::Arguments arguments_like = arguments; | ||
| arguments_like[arg_tokenizer] = {"tokenizer", "The tokenizer to use. Valid arguments are `splitByNonAlpha`, `splitByString`, `asciiCJK`, `ngrams`, `sparseGrams`, and `array`. Optional, if not set explicitly, defaults to `splitByNonAlpha`.", {"const String"}}; | ||
| arguments_like[arg_tokenizer] = {"tokenizer", "The tokenizer to use. Valid arguments are `splitByNonAlpha`, `asciiCJK`, `splitByWordBoundaries`, `ngrams`, and `sparseGrams`. Optional, if not set explicitly, defaults to `splitByNonAlpha`.", {"const String"}}; |
There was a problem hiding this comment.
The tokenizer argument list on this line is now correct, but the public description_like prose below still says tokensForLikePattern supports the same argument sets as tokens and gives splitByString/separators as an example. In the current code buildImpl throws BAD_ARGUMENTS for splitByString, splitByRegexp, array, and japanese, so the function contract is still contradictory. Please align that prose with the actual supported tokenizer set.
a75cba9 to
39e25f5
Compare
splitByWordBoundaries tokenizer based on StringZilla UAX #29 word segmentationasciiCJK_v2 tokenizer using StringZilla UTF-8 decoding
…rd segmentation Splits text into words with the Unicode Text Segmentation (UAX ClickHouse#29) word boundary rules of the StringZilla library and drops the segments made of whitespace, punctuation and symbols. Unlike `asciiCJK`, words of all scripts are kept whole (`café`, `한국어`, `1,000,000`), and it is 2-5x faster than the `icu` tokenizer, which implements the same standard. Closes: ClickHouse#111696 Co-Authored-By: Claude Opus 5 <[email protected]>
39e25f5 to
c091edb
Compare
asciiCJK_v2 tokenizer using StringZilla UTF-8 decodingstringzilla tokenizer using StringZilla UTF-8 decoding
…zilla-tokenizer Adapt to master: `stringzilla` joins the tokenizers whose terms never contain a zero byte in `tokenizerSplitsAtZeroByte`, the replacement of the removed `zero_padding_tolerated_tokenizers` list. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| With `match_tokens = true`, note that search needles in text search functions are tokenized with the index's own tokenizer, so a plain string needle that does not itself match `regexp` yields no tokens and therefore no results. Needles passed as arrays to text search functions are not tokenized, and are therefore recommended for use with regexp tokenizers. | ||
| - `asciiCJK` splits strings into tokens using Unicode word boundary rules (similar to [Unicode Text Segmentation (UAX #29)](https://unicode.org/reports/tr29/)). ASCII alphanumeric characters and underscores form tokens with connectors (ASCII `:` for letters, `.` and `'` for same-type characters). Non-ASCII Unicode characters, including [CJK](https://en.wikipedia.org/wiki/CJK_characters) characters, become single-character tokens. | ||
| - `stringzilla` splits strings into words using the full [Unicode Text Segmentation (UAX #29)](https://unicode.org/reports/tr29/) word boundary rules, as implemented by the [StringZilla](https://github.com/ashvardanian/StringZilla) library, and drops the segments made of whitespace, punctuation and symbols (including emoji). | ||
| Unlike `asciiCJK`, words in all scripts are kept whole: for example, `café naïve` becomes `['café', 'naïve']` rather than `['caf', 'é', 'na', 'ï', 've']`, `한국어` and `テキスト` are one token each, and `1,000,000` is one token. |
There was a problem hiding this comment.
The implementation and docs here make it explicit that Chinese ideographs and Hiragana still tokenize to single characters, so the current changelog entry overstates the feature by saying the tokenizer keeps words "in all scripts" whole. Because the changelog is the user-facing upgrade contract, please narrow that wording to match the shipped behavior instead of promising dictionary-style segmentation for scripts that stringzilla still leaves as single-character tokens.
|
@phulv94 Before we proceed, we need to understand if the |
|
I ran two comparisons against 1. Unicode UAX #29 conformanceSource:
No case shows a different boundary. All 396 differing cases are about keeping vs 2. Real text3.55M lines of the ClickHouse docs (304 MB, multilingual):
All 18 ASCII differences are runs of underscores ( Conclusion
On the nameAgreed, |
|
Thanks for checking.
I actually don't understand what these statements mean for the question whether Stringzilla is a drop-in replacement for ICU. But maybe the next point is more important:
The Conclusion looks inconsistent the measurements, there are differences for non-CJK languages. My hope was that we could use one as drop-in-replacement for the other so we wouldn't need to introduce yet-another tokenizer. Since Stringzilla is heavily under development, its algorithm may change in future. Also, tokenization performance is not a huge performance problem at the moment. So I suggest to close this PR for now and possibly come back to it later. |
Closes: #111696
Adds the
stringzillatokenizer for text indexes and thetokensfamily of functions. It splits text into words with the Unicode Text Segmentation (UAX #29) word boundary rules of the StringZilla library, and drops the segments made of whitespace, punctuation and symbols. StringZilla is already vendored and compiled; this PR only linksdbmsagainst it.A note on the issue:
asciiCJKdoes not use ICU. It is a hand-written scanner that emits every non-ASCII codepoint as its own token, using a single lead-byte lookup, and it cannot be made faster with StringZilla (see the benchmarks below). The ICU-based tokenizer isicu(locale), and that is what this tokenizer offers an alternative to: the same UAX #29 standard, 2-5x faster.Tokens compared to the existing tokenizers:
asciiCJKstringzillaicu('en')café naïvecafénaïvecafénaïvecafénaïve한국어 テキスト한국어テキスト한국어テキスト中文,分词中文,分词中文分词中文分词(dictionary)1,000,00010000001,000,0001,000,000emoji 😀 👨👩👧emoji😀👨👩👧emojiemojiChinese ideographs and Hiragana stay single-character tokens, because UAX #29 does not segment them without a dictionary;
chinese,japaneseandicuremain the choices for that.Implementation notes:
StringZillaTokenizerhas the same shape asAsciiCJKTokenizerand is dispatched inforEachTokenthroughdetail::forEachTokenImpl.asciiCJKis not touched.nextInStringwalks the UAX C++ client #29 segments with StringZilla's batching iterator (64 segments per kernel call, as its Python and Java bindings do), kept per thread like the ICU iterator ofIcuTokenizer, because the tokenizer object is shared between threads. The segments tile the input, so the separator segments are skipped: those starting with a delimiter persz_utf8_delimitersafter optional underscores. This covers\r\n, whitespace runs, emoji sequences and_idvs__. Fetching one segment per call instead of batching is ~18x slower.LIKE,startsWith,endsWith,match,multiSearchAnyandmap*Likeare supported. UAX C++ client #29 joins words across punctuation (1,000,foo.bar) but never across whitespace, so a token next to a wildcard, or next to the open side of a substring, is used for index lookups only when whitespace separates them. ForLIKE '%,000 rows loaded%'onlyrowsis looked up. The sharedwordBoundarySubstring*helpers used byasciiCJKonly drop tokens touching the edge, which would miss rows for such patterns, so this tokenizer has its own helper.stringLikeToTokens/stringLikeToBloomFiltertokenize each literal of a pattern once, so pattern analysis is linear in the pattern length, and the text between%,_and\is copied in runs found withfind_first_symbols.Performance, Apple Silicon (NEON), 100,000 generated rows, median of 7 runs, seconds:
asciiCJKstringzillaicu('en')tokens, ASCIItokens, CJKtokens, mixedstringzillais 2.3-5.1x faster thanicu, which implements the same UAX #29 rules, and slower thanasciiCJK, which looks up no Unicode properties at all. x86 with AVX-512 uses different StringZilla kernels and was not measured locally.Tests:
05218_stringzilla_tokenizer:tokensandtokensForLikePatternedge cases (scripts, emoji, invalid UTF-8, escapes, long inputs).05219_stringzilla_text_index: search functions return the same rows with and without the index,EXPLAINgranule skipping, and tokenization that is stable across batch boundaries and thread counts.gtest_StringZillaTokenizer:nextInStringLikeandstringLikeToTokensreturn the same tokens.tests/performance/tokenizer_stringzilla.xml.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
stringzillatokenizer for text indexes and thetokensfamily of functions. It splits text into words by the Unicode (UAX #29) word boundary rules, so words in all scripts are kept whole (e.g.café,한국어,1,000,000). It implements the same standard as theicutokenizer and is 2-5x faster.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/120973]