[perf] CJK queries longer than 6 chars time out (30s) in heavy mode: Orama fuzzy tolerance applied to char+bigram tokens
Summary
In heavy mode (MEMORIX_ORAMA_HYDRATION_THRESHOLD raised so Orama is hydrated), any Chinese query longer than 6 characters takes ~44s and hits the 30s Search timeout guard in memorix_search (default quality=balanced). The cost is entirely inside oramaSearch; the embedding call is 0.1–0.2s.
Related: #374 (lazy-mode silent vector write gap — separate, but both affect the same heavy/lazy decision).
Environment
- memorix 1.10.2 (npm latest as of 2026-11-04)
- Windows 11, Node v24.15.0
- Embedding: Ollama
qwen3-embedding:8b, 4096d (MEMORIX_EMBEDDING=api) MEMORIX_ORAMA_HYDRATION_THRESHOLD=100000000(heavy, Orama hydrated)- Corpus: 13,448 observations / 15 projects
- Transport: HTTP MCP (
memorix_search,quality=balanced)
Repro
MEMORIX_PERF=1 memorix background start # embedding enabled + heavy threshold
Then call memorix_search with:
query: "向量提供者为什么"(7 CJK chars)quality: "balanced"
Result:
Error: Search timeout after 30000ms. Try a simpler query or check if the service is responsive.
Server-side perf marks (stderr):
[search-perf] tier=heavy: 0ms
[search-perf] queryExpansion: 0ms
[search-perf] embedding: 121ms
[search-perf] preSearch: 129ms
[search-perf] oramaSearch: 44346ms
[search-perf] rerank(skipped,tier=heavy): 44347ms
Isolation
| Query | quality | tolerance | latency |
|---|---|---|---|
向量禁用 (4 CJK chars) |
balanced | 1 | 3.4–5.0s |
向量提供者为 (6 CJK chars) |
balanced | 1 | 5.0s |
向量提供者为什么 (7 CJK chars) |
balanced | 2 | ~44s → timeout |
memorix vector provider disabled because hook timeout embeddings were too slow (11 words) |
balanced | 2 | 2.7s |
向量提供者为什么被禁用 |
fast | none (exact) | 0.1s |
The boundary is exactly the length > 6 → tolerance 2 switch. Non-CJK queries are not affected, so the vector scan / hybrid path itself is cheap.
Root cause
src/store/orama-store.ts (searchObservations; bundled at dist/cli/index.js:188687 / dist/index.js:9392 in 1.10.2):
...hasQuery && quality !== "fast" ? { tolerance: originalQuery.length > 6 ? 2 : 1 } : {}
Memorix installs a custom tokenizer (createSearchTokenizer) that emits every CJK character plus every adjacent bigram in addition to the default tokens. A 7-char Chinese query therefore produces ~13 query tokens; each is fuzzy-matched with edit distance 2 against a large token index (13k docs × 7 properties), which explodes the candidate/traversal space. English queries have far fewer, longer tokens and stay fast.
Suggested fix
Make tolerance CJK-aware, e.g.:
const cjkHeavy =
(originalQuery.match(/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g) || []).length /
originalQuery.length > 0.3;
...
...hasQuery && quality !== "fast"
? (cjkHeavy ? {} : { tolerance: originalQuery.length > 6 ? 2 : 1 })
: {}
Rationale: the CJK tokenizer already provides char + bigram tokens, so exact matching retains most of the recall; fuzzy Levenshtein adds little for CJK but costs orders of magnitude more. Alternatively, cap the number of fuzzy tokens or skip fuzzy matching for queries whose CJK ratio exceeds a threshold.
Local workaround (verified)
Omitting tolerance for CJK-heavy queries (same logic as above):
| Query | before | after |
|---|---|---|
向量提供者为什么 (7 CJK) |
44s / timeout | 67–73ms |
memorix 的向量提供者为什么被禁用了 我们后来又是怎么恢复的 (25 CJK) |
timeout | 207ms |
| 30+ CJK chars | timeout | 385ms |
Hybrid search still returns active results at default limit (6 results, elapsedMs: 278), so semantic recall is preserved.
Additional note
The 30s withTimeout guard rejects the request but does not abort the underlying search2() work: the client observed ~45s per call, and an immediately repeated identical query still cost ~45s, suggesting the abandoned promise keeps occupying the event loop / index. If the timeout is meant to protect latency, it may be worth cancelling the underlying search or caching its result.
Fixed in main via PR #376. CJK-heavy queries no longer enable fuzzy tolerance over the character and bigram tokenizer output, avoiding the traversal explosion that caused 30-second timeouts. The change is included in tag v1.10.3.