Files
miti99bot/src/modules/doantu/index.js
T
tiennm99 8bf2499914 refactor(doantu): swap ConceptNet for Workers AI bge-m3 embeddings
Mirror the semantle migration but with @cf/baai/bge-m3 — BAAI's
multilingual embedding model — because the English-only BGE variants
can't produce meaningful Vietnamese vectors (their tokenizer shreds
diacritics into noisy byte-level subwords).

bge-m3 is trained across 194 languages incl. Vietnamese and is
actually cheaper in Neurons (1,075 vs 1,841 per M tokens for
bge-small-en-v1.5). Vocab check reuses the local Viet22K wordlist as
an in-memory Set — O(1) OOV detection, no upstream call.

Also add a test file for the module (mirrors semantle coverage plus
Vietnamese-specific cases: diacritics, multi-syllable compounds).
2026-04-22 23:53:36 +07:00

49 lines
1.5 KiB
JavaScript

/**
* @file Doantu module — Vietnamese semantle.
*
* Targets from a curated local wordlist (duyet/vietnamese-wordlist Viet22K —
* same list doubles as the vocabulary for OOV detection). Similarity scores
* come from cosine distance between `@cf/baai/bge-m3` multilingual embeddings
* produced by the `env.AI` binding. All commands are `protected` — listed
* in /help but hidden from Telegram's native / autocomplete menu.
*/
import { createClient } from "./api-client.js";
import { handleDoantu, handleGiveup, handleStats } from "./handlers.js";
/** @type {import("../../db/kv-store-interface.js").KVStore | null} */
let db = null;
/** @type {ReturnType<typeof createClient> | null} */
let client = null;
/** @type {import("../registry.js").BotModule} */
const doantuModule = {
name: "doantu",
init: async ({ db: store, env }) => {
db = store;
client = createClient(env.AI);
},
commands: [
{
name: "doantu",
visibility: "protected",
description: "Đoán từ — Vietnamese semantic word guessing (unlimited tries)",
handler: (ctx) => handleDoantu(ctx, { db, client }),
},
{
name: "doantu_giveup",
visibility: "protected",
description: "Reveal the current doantu answer (auto-starts a fresh round)",
handler: (ctx) => handleGiveup(ctx, { db, client }),
},
{
name: "doantu_stats",
visibility: "protected",
description: "Show your doantu stats",
handler: (ctx) => handleStats(ctx, { db, client }),
},
],
};
export default doantuModule;