From 463e728e33a498bf5207476d0135051521c0b13e Mon Sep 17 00:00:00 2001 From: mashbean Date: Fri, 19 Jun 2026 15:46:26 +0800 Subject: [PATCH] feat(moment): route moment spam scoring to dedicated model (fallback short-content) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 短內容共用模型對動態 ~90% 華語誤殺;專用動態模型重訓後驗收 @0.7 誤殺0.8%/召回93% (vs 舊 93.9%/67%)。比照 #4838 留言拆專用:momentService.detectSpam 改用 momentSpamDetectionApiUrl,未設定時 fallback 短內容模型 → 零停機 opt-in。 ops 設 MATTERS_MOMENT_SPAM_DETECTION_API_URL 指向新 endpoint 即啟用。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .env.example | 1 + src/common/environment.ts | 5 +++++ src/connectors/momentService.ts | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 989eb7b7c..f7a190317 100644 --- a/.env.example +++ b/.env.example @@ -105,6 +105,7 @@ MATTERS_PASSPHRASES_SECRET= MATTERS_SPAM_DETECTION_API_URL= MATTERS_SHORT_CONTENT_SPAM_DETECTION_API_URL= MATTERS_COMMENT_SPAM_DETECTION_API_URL= +MATTERS_MOMENT_SPAM_DETECTION_API_URL= MATTERS_COMMENT_SPAM_AUTO_COLLAPSE=false MATTERS_AWS_SPAM_SAMPLE_QUEUE_URL= MATTERS_SPAM_SAMPLE_HASH_SALT= diff --git a/src/common/environment.ts b/src/common/environment.ts index 9eeea3b3f..59af45655 100644 --- a/src/common/environment.ts +++ b/src/common/environment.ts @@ -197,6 +197,11 @@ export const environment = { process.env.MATTERS_SHORT_CONTENT_SPAM_DETECTION_API_URL || '', commentSpamDetectionApiUrl: process.env.MATTERS_COMMENT_SPAM_DETECTION_API_URL || '', + // Dedicated moment spam model (label-fix retrain; fixes the shared short-content + // model's ~90% false-kill on Chinese moments). Falls back to the short-content + // model when unset, so this is a zero-downtime opt-in via env. + momentSpamDetectionApiUrl: + process.env.MATTERS_MOMENT_SPAM_DETECTION_API_URL || '', // When true, a comment whose spam score reaches the system spam threshold is // auto-collapsed (folded but still expandable in-thread — "不刪除,只是不再被 // 看見"). Default off so scoring stays observe-only until ops opts in. diff --git a/src/connectors/momentService.ts b/src/connectors/momentService.ts index 7ef20aa4d..2186e7e54 100644 --- a/src/connectors/momentService.ts +++ b/src/connectors/momentService.ts @@ -461,8 +461,11 @@ export class MomentService { id: string content: string }) => { + // Prefer the dedicated moment model; fall back to the shared short-content + // model when MATTERS_MOMENT_SPAM_DETECTION_API_URL is unset (zero-downtime). const detector = new SpamDetector( - environment.shortContentSpamDetectionApiUrl + environment.momentSpamDetectionApiUrl || + environment.shortContentSpamDetectionApiUrl ) const score = await detector.detect(content)