Opensearch compatible tokenization#39
Conversation
lnkuiper
left a comment
There was a problem hiding this comment.
Thanks! Just two minor comments:
|
|
||
| static bool IsOpenSearchStandardIntraTokenPunctuation(UChar32 codepoint) { | ||
| return codepoint == '\'' || codepoint == '.' || codepoint == '_'; | ||
| } |
There was a problem hiding this comment.
This only treats ASCII ' as intra-token punctuation. As a result, common text such as It’s and l’amour is split into It, s / l, amour, whereas OpenSearch’s standard tokenizer preserves It’s as one token. Could we implement the relevant UAX #29 apostrophe handling (at least U+2019), and add coverage for it?
# name: test/temp.test
# group: [fts]
require fts
query T
SELECT token
FROM unnest(fts_tokenize_opensearch_standard('It’s')) AS t(token)
----
It’s|
|
||
| set(EXTENSION_BASE_FOLDER "src") | ||
| set(SNOWBALL_BASE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/third_party/snowball") | ||
| set(DUCKDB_ICU_BASE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/duckdb/extension/icu") |
There was a problem hiding this comment.
This compiles against ICU headers from FTS’s pinned duckdb submodule, but below we link duckdb_icu_* object targets from the host DuckDB build. That mixes two DuckDB/ICU revisions with no compatibility guarantee. Can we source both headers and objects consistently from the host build (or consistently from the submodule)?
Part of: https://github.com/duckdblabs/duckdb-internal/issues/9855
This PR adds Opensearch-compatible tokenizer mode:
PRAGMA create_fts_index( 'docs', 'id', 'body', tokenizer = 'opensearch_standard' );The current
regextokenizer mode remains the standard for backwards compatibility reasons.regexmode works with Unicode already, but is not compatible with Opensearch/Lucene tokenization, mostly w.r.t. to Japanese/Chinese alphabets. In particular, the current tokenizer keeps CJK runs such as 東京大学に行く or 北京大学 as whole tokens, while OpenSearch’s standard tokenizer emits Han and Hiragana characters as individual tokens.The new
opensearch_standardmode uses the ICU extension to align with OpenSearch:And because I am curious, emoji's are now also better handled than with the
regexmode:is tokenized more like:
We're not fully Opensearch compatible just yet. That requires a couple more pieces, in particular around folding/normalization mode and
strip_accents, but that will be addressed in a follow-up PR.