Repository navigation
Conversation
|
|
ployts
left a comment
There was a problem hiding this comment.
Found three reproducible issues: the registered Russian tokenizer cannot be constructed through application configuration, the fingerprint change also invalidates default Regex indexes, and normalization bypasses custom Russian stopwords. Details and suggested fixes are attached inline.
Validation on b02a177: the focused existing tokenizer/BM25/keyword-update tests produced 78 passed and 2 skipped. Additional isolated regression checks reproduced all three issues, including stopword filtering with both Snowball and pymorphy3. Basic tokenization smoke checks passed for both backends. Full suite, integration tests, and lint were not run.
| def __init__(self, backend: str = "snowball", **kwargs): | ||
| super().__init__(**kwargs) | ||
| backend = (backend or "snowball").strip().lower() | ||
| if backend not in self.SUPPORTED_BACKENDS: |
There was a problem hiding this comment.
[P1] Separate the normalization engine from the component registry backend
Application._instantiate() selects the class using cfg.backend and then forwards the complete cfg.model_dump() to its constructor. Consequently, configuring components.tokenizer.default.backend=russian calls RussianTokenizer(backend="russian"), which raises ValueError: Unsupported Russian tokenizer backend: 'russian'. Setting it to snowball or pymorphy3 instead fails registry lookup, so neither engine is reachable through the normal application configuration path. Please give the normalization engine a separate option while preserving the registry backend, and add an application-level configuration test; the current tests only instantiate the tokenizer directly.
| # defaults `backend` to "", and an empty value must not alter the | ||
| # fingerprint of tokenizers that never had a backend. | ||
| backend = getattr(self.tokenizer, "backend", None) | ||
| if backend: |
There was a problem hiding this comment.
[P2] Preserve the existing fingerprint for configured Regex tokenizers
Application-created RegexTokenizer instances receive backend="regex" from Application._instantiate(), so this condition is true for the default deployment too. I reproduced the default fingerprint changing from 7748e1d5a050 to 004adcb94b66, even though its token output is unchanged. The persisted index is therefore missed and LocalFileStore._sync_keyword_index_from_chunks() performs a full synchronous rebuild at startup. This affects default Regex users, beyond the intended Jieba/backend migration. Please distinguish token-output engine settings from registry-only backend values and cover an application-created Regex tokenizer; the new standalone test has an empty backend and misses this path.
| if self._normalize is None: | ||
| # Not started yet: behave like the plain regex tokenizer. | ||
| return tokens | ||
| return [self._normalize(token.lower()) if self.CYRILLIC_PATTERN.search(token) else token for token in tokens] |
There was a problem hiding this comment.
[P2] Keep custom stopwords in the same representation as filtered tokens
BaseTokenizer.tokenize() runs _postprocess() after _tokenize_one(), while the loaded stopword set contains the original lowercased words. Normalizing here means an exact custom stopword can survive filtering: with a stopword file containing машины, tokenizing машины returns ['машин'] under Snowball and ['машина'] under pymorphy3, whereas Regex correctly returns []. I reproduced this with both real backends and the default filter_stopwords=True. Please filter original tokens before normalization or normalize the stopword set consistently, and add coverage with filtering enabled.
b02a177 to
ad12cc7
Compare
|
@ployts All three addressed in 1. [P1] The normalization engine is now a separate option
def __init__(self, backend: str = "russian", engine: str = "snowball", **kwargs):
super().__init__(backend=backend, **kwargs)
2. [P2] A plain Regex tokenizer keeps its fingerprint The fingerprint no longer reads Two notes on verification:
3. [P2] Stopwords are folded with the same engine
if self._stopwords:
self._stopwords = {self._fold(word) for word in self._stopwords}Reverting that block leaves Test scope
|
|
The only failing job is That test drives concurrent append batching in the Claude Code session store. Nothing in this PR touches it — the change is confined to the tokenizer and the keyword index ( Three reasons to read it as a flake rather than a regression:
Would someone rerun the py3.12 job when convenient? |
ployts
left a comment
There was a problem hiding this comment.
Re-reviewed ad12cc7. All three findings from the previous review are fixed: application configuration can construct and start both Russian engines, the configured Regex tokenizer retains its original fingerprint, and custom Russian stopwords are filtered with both engines.
One new regression remains: _fold() now lowercases non-Cyrillic tokens even when the caller explicitly requests lower=False. Details and the reproduction are attached inline.
Validation: focused tokenizer/BM25/keyword-update/component-registry/base-component tests produced 128 passed and 2 skipped (optional faiss/zvec dependencies are absent). Independent checks for the previous fixes passed; the new case-preservation regression test failed with both real engines. The same input passed on the previous PR revision. Full suite, integration tests, and lint were not run.
| lowered = token.lower() | ||
| if self._normalize is None or not self.CYRILLIC_PATTERN.search(lowered): | ||
| return lowered |
There was a problem hiding this comment.
[P2] Preserve non-Cyrillic tokens when lower=False
_fold() now lowercases every token before checking whether it contains Cyrillic characters, so the inherited lower=False option no longer preserves Latin token casing. After starting RussianTokenizer(filter_stopwords=False), tokenize(["Python OpenAI"], lower=False) returns [["python", "openai"]]; both RegexTokenizer and the previous PR revision return [["Python", "OpenAI"]]. I reproduced this with both Snowball and pymorphy3. This breaks the public lower option and the promised unchanged behavior for non-Cyrillic text. Please return the original token in the non-Cyrillic branch and leave optional lowercasing to BaseTokenizer._postprocess(); add a regression test with lower=False for both engines.
Russian keyword search misses related word forms when a note and a query use different cases or numbers: a note containing "инструментом" does not match a query for "инструмента". Add a `russian` tokenizer that folds Cyrillic tokens to a shared form, so note and query land on the same index term. It extends RegexTokenizer rather than replacing it, so Latin and CJK tokens behave exactly as before; only Cyrillic words are normalized. Two backends: - snowball (default): the Snowball stemmer. A pure algorithm with no dictionaries, about 0.2 MiB. It returns a *stem*, not a dictionary form -- "система" becomes "систем". That is sufficient for retrieval, but the stem is not a real word and must not be shown to users. - pymorphy3: a morphological analyzer returning the dictionary form, at the cost of a 16 MiB Russian dictionary. Both are optional extras (`reme-ai[russian]` and `reme-ai[russian-full]`), and the tokenizer raises an actionable ImportError when the chosen backend is not installed. Also include `backend` in the BM25 tokenizer fingerprint. A backend changes the tokens a tokenizer emits, so without it, switching between two backends of the same class keeps reading an index the other backend built. The field is only added when the tokenizer declares a non-empty backend: BaseComponent defaults `backend` to "", which must not perturb the fingerprint of tokenizers that never had one. Note for existing jieba users: their index file name changes once, because JiebaTokenizer does declare a backend. That triggers a single rebuild, which is the intended effect -- rjieba and jieba previously shared one index file. Refs agentscope-ai#754
ad12cc7 to
7ec24fc
Compare
|
@ployts Fixed in 1. [P2]
Reverting only that branch reproduces your report on both engines: With the fix, 2. Regression tests for both engines
Verification
On your note about the previous CI run: the only red job was |
What Problem This Solves
Russian keyword search misses related word forms when a note and a query use
different cases or numbers (#754):
RegexTokenizersplits on word boundaries and leaves inflection untouched, soинструментомandинструментаbecome two unrelated index terms.Change
A
russiantokenizer that folds Cyrillic tokens to a shared form.It extends
RegexTokenizerinstead of replacing it, so Latin and CJK tokenskeep exactly today's behaviour; only Cyrillic words are normalized.
Two backends:
snowball(default)snowballstemmerсистема→системpymorphy3pymorphy3+ 16 MiB dictionaryсистема→системаBoth ship as optional extras, so nothing is installed for users who do not ask
for it:
reme-ai[russian]andreme-ai[russian-full]. Selecting a backendwithout its extra raises an ImportError naming the install command.
One caveat, stated up front: the default backend returns a stem, not a
dictionary form —
системаbecomesсистем, which is not a word. That is finefor retrieval, but these tokens must not be shown in the UI. If a future feature
highlights the matched original word, it needs the source text, not the token.
Also included: the fingerprint learns about
backendBM25Index._tokenizer_config()builds the fingerprint that names the indexfile, and it did not include the tokenizer's backend. A backend changes the
tokens a tokenizer emits, so switching between two backends of the same class
kept reading an index the other backend had built.
if backend:rather thanis not Noneis deliberate:BaseComponentdefaultsbackendto"", so a presence check would append the field for everytokenizer and rebuild every existing index for no reason.
This changes the index file name for existing
jiebausers once, becauseJiebaTokenizerdoes declare a backend. They get a single rebuild — theintended outcome, since
jiebaandrjiebapreviously shared one index filedespite emitting different tokens.
Evidence
tests/unit/test_russian_tokenizer.py— 7 passed:test_case_forms_fold_to_one_tokentest_note_and_query_share_a_termtest_non_cyrillic_tokens_are_untouchedRegexTokenizertest_tokenize_before_start_falls_back_to_regexstart()test_unknown_backend_is_rejectedtest_fingerprint_tracks_the_backendtest_tokenizers_without_a_backend_keep_their_configNeighbours —
test_tokenizer.py,test_keyword_index.py,test_bm25_live_length.py,test_keyword_upsert_delta.py: 80 passed.Falsification: replacing
if backend:withif False:turnstest_fingerprint_tracks_the_backendred; restoring returns it to green.pre-commit run --filesover the five touched files: all hooks pass.Not verified
pymorphy3backend is implemented, but its tests are skipped here becausethe 16 MiB dictionary is not installed in this environment. That path was not
exercised end to end.