@@ -20,3 +20,41 @@ export function adaptiveThreshold(query, candidates = []) {
2020 if ( scores . length >= 5 && scores [ 0 ] - scores [ 4 ] > 0.3 ) return 0.5 ;
2121 return 0.65 ;
2222}
23+
24+ // Issue #239(第 5 项):注入条数的查询自适应(去 always-on 化的一半)。
25+ // 依据:不确定性强的话题多召回、确定性的少召回(Oblivion 的不确定性驱动读路径);
26+ // 但**注入相关却带偏生成**的内容可能比不注入更糟(2607.24010 与 2604.02280 两处
27+ // 独立出处),所以这里只做**单向收缩**:模糊 → 维持用户配置的上限,确定 → 收缩,
28+ // 绝不越过上限。判据只看查询本身——不做额外检索(2607.24010:触发侧成本别忽略,
29+ // 先探针检索等于白付一次 fuseRecall)。
30+ const RECALL_CUES = [
31+ // 中文回指 / 时间线索:出现即说明用户要的是「记忆里的东西」,当场算不出来
32+ "上次" , "之前" , "以前" , "那天" , "那次" , "刚才" , "刚刚" , "后来" , "很早" ,
33+ "还记得" , "记不记得" , "我们讨论" , "我们聊" , "我说过" , "你提过" , "提到过" ,
34+ "最近" , "上次说" , "之前说" ,
35+ // 英文同类线索
36+ "last time" , "previously" , "earlier" , "remember" , "we discussed" ,
37+ "i mentioned" , "you said" , "that thing" , "remind me"
38+ ] ;
39+
40+ /**
41+ * 这段查询是否需要「宽召回」。命中回指/时间线索,或短到几乎匹配任何东西
42+ * (与 adaptiveThreshold 对 <5 字符的判断同源)。纯函数、零成本。
43+ * 拿不到查询时不猜——返回 true 维持现状。
44+ */
45+ export function needsBroadRecall ( query ) {
46+ const q = String ( query ?? "" ) . trim ( ) . toLowerCase ( ) ;
47+ if ( q === "" ) return true ;
48+ if ( q . length < 5 ) return true ;
49+ return RECALL_CUES . some ( ( cue ) => q . includes ( cue ) ) ;
50+ }
51+
52+ /**
53+ * 注入条数的自适应预算:模糊 → 维持配置上限;确定 → 收缩到一半(下限 1)。
54+ * `maxItems <= 1` 时原样返回(含 0 = 不注入,flag 打开也不该把 0 变成 1)。
55+ */
56+ export function adaptiveInjectBudget ( query , maxItems ) {
57+ const cap = Number . isFinite ( maxItems ) && maxItems > 0 ? Math . floor ( maxItems ) : maxItems ;
58+ if ( ! Number . isFinite ( cap ) || cap <= 1 ) return cap ;
59+ return needsBroadRecall ( query ) ? cap : Math . max ( 1 , Math . ceil ( cap / 2 ) ) ;
60+ }
0 commit comments