feat(search): Korean morphological tokenizer on the workerd search API - #7
Merged
Conversation
…arch API
Wire garu-orama-tokenizer into the Orama search so Korean queries match by
morpheme instead of whitespace: `먹다` matches `먹었다`/`먹지`, `학교` matches
`학교에서`. It's composed with Orama's default tokenizer as a union, so English
and other non-Korean search is unchanged.
garu-ko normally fetches/reads its WASM+model at runtime, which the Cloudflare
Workers (workerd) runtime forbids. Instead:
- import the 341KB WASM as a pre-compiled module and instantiate it with
`initSync({ module })` (workerd allows instantiating a compiled module; only
compiling from bytes at runtime is banned);
- inline the ~1MB model as bytes via a small Vite plugin;
- alias garu-ko's non-exported internals and pin garu-ko + @orama/orama so the
layout we depend on is version-locked, with a build-time existence guard.
All garu code is dynamically imported so its weight lands in a lazy chunk loaded
only on the first search. The failed-init cache is reset so a transient
cold-start error can't permanently poison an isolate.
Verified on the workerd runtime (dev Miniflare + prod build): Korean
morphological matching works, English is unchanged, the client bundle stays
clean (server-only), and the Worker is ~2.4MB gzipped (under the limits).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhaZ2zL7bAqT3c8mRWTSs9
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
webview-bundle-website | 06995e1 | Commit Preview URL Branch Preview URL |
Jul 01 2026, 01:56 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Korean morphological tokenizer (
garu-orama-tokenizer) to the docs search, running server-side on the Cloudflare Workers (workerd) runtime.What it does
Korean is now tokenized by real morphological analysis instead of whitespace, so queries match across inflections and particles:
먹다먹었다,먹었습니다,먹지학교학교에서,학교를,학교가English (and any other) search is unchanged — the Korean tokenizer is composed with Orama's default tokenizer as a union of both token sets.
The workerd challenge
garu-konormallyfetch()es (browser build) orfs.readFiles (node build) its WASM + model at runtime — neither works in workerd. So instead:initSync({ module }). workerd allows instantiating a compiledWebAssembly.Moduleat request time; only compiling from bytes at runtime is banned, which this path avoids.garu-koand@orama/oramaare pinned, with a build-time existence guard so a version bump that relocates files fails loudly.All garu code is dynamically imported so its weight lands in a lazy chunk loaded only on the first search, not at Worker startup. A failed init resets its cache so a transient cold-start error can't permanently poison an isolate.
Verified (dev Miniflare + prod build)
먹다→먹었습니다,학교→학교에서)Note
First search per isolate does a one-time WASM instantiate + model parse (a few ms of CPU). Fine on a Paid plan (30 s CPU); on the Free plan (10 ms/request) this could risk error 1102 — the deploy config (
workers_dev: false, observability) indicates Paid, so this should be a non-issue, but worth confirming.🤖 Generated with Claude Code
https://claude.ai/code/session_01HhaZ2zL7bAqT3c8mRWTSs9
Summary by cubic
Adds a Korean morphological tokenizer to the docs search on the workerd API so queries match stems across particles and inflections. English and other languages are unchanged.
New Features
garu-orama-tokenizerwith Orama’s default tokenizer (union of tokens) for Korean-aware matching.Dependencies
garu-ko@0.9.7,garu-orama-tokenizer@0.4.1; pin@orama/orama@3.1.18.garu-kointernals; build-time guard for expected files.src/garu-runtime.d.tsfor internalgarubindings.Written for commit 06995e1. Summary will update on new commits.