acp-kernel 0.0.28 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,9 +7,9 @@ import type { SearchAlgorithm } from "../types.js";
7
7
  * raw term count. Stemming collapses English morphology
8
8
  * (compress/compressed/compression → ~compress).
9
9
  *
10
- * On a 30-block mixed EN/CJK benchmark: MRR 0.812 vs 0.821 for substring
11
- * alone not better in isolation, but a strong precision component when
12
- * combined with fuzzy recall (see hybrid.ts).
10
+ * On the 32-block mixed EN/CJK benchmark: MRR 0.833 / R@1 0.833 / R@3 0.833
11
+ * vs 0.797 / 0.792 / 0.792 for substring better in isolation on every
12
+ * metric, and the precision component of the hybrid default (see hybrid.ts).
13
13
  */
14
14
  export declare const bm25Algorithm: SearchAlgorithm;
15
15
  //# sourceMappingURL=bm25.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/bm25.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAG3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,EAAE,eAqC3B,CAAC"}
1
+ {"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/bm25.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAI3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,EAAE,eAkC3B,CAAC"}
@@ -4,11 +4,21 @@ import type { SearchAlgorithm } from "../types.js";
4
4
  *
5
5
  * Decomposes the query into character bigrams and measures overlap with
6
6
  * each doc. Robust to typos (tokan≈token), partial words, and works
7
- * uniformly across all scripts (CJK benefits most). Only considers query
8
- * tokens of length >= 4 to avoid noise from short common-character pairs.
7
+ * uniformly across all scripts (CJK benefits most).
9
8
  *
10
- * On benchmark: highest recall@3 (0.913) of any single algorithm it is
11
- * the recall boost in the hybrid default.
9
+ * Query-token gate CJK gets its own length rule; Latin is frozen:
10
+ * length >= 4 (any script) typo-tolerant bigram rescue needs a couple of
11
+ * chars before it means anything; 2-3-char Latin tokens ("to", "of",
12
+ * "us") are stop-word noise whose bigrams overlap nearly every doc.
13
+ * length >= 2 && CJK Chinese/Japanese/Korean words are mostly
14
+ * 2-character atomic units (登录/缓存/図表), so the Latin-style >= 4 rule
15
+ * would lock the whole CJK query space out of this recall channel
16
+ * (that gap is what bench "缓存 → nothing" exposed). Single CJK chars
17
+ * stay excluded — one char cannot form a bigram, nothing to compare.
18
+ *
19
+ * On benchmark: lowest MRR of any single algorithm (0.795 — a hair under
20
+ * substring's 0.797) — precision is weak, but it is the recall boost in the
21
+ * hybrid default.
12
22
  */
13
23
  export declare const fuzzyAlgorithm: SearchAlgorithm;
14
24
  //# sourceMappingURL=fuzzy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/fuzzy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAG3E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,EAAE,eAmB5B,CAAC"}
1
+ {"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/fuzzy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAI3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,EAAE,eAoB5B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"substring.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/substring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAE3E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAahC,CAAC"}
1
+ {"version":3,"file":"substring.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/substring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAG3E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAahC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Per-doc derived features, memoized across search calls.
3
+ *
4
+ * A search over the compressed history re-scores the SAME immutable docs on
5
+ * every call — compressed block summaries and folded message text never
6
+ * change. Without this cache, every search_context call re-tokenized the
7
+ * entire corpus (segmenter CJK pass ≈ 0.3s/MB cold) plus re-lowercased it
8
+ * and rebuilt the bigram set for each channel: a 5MB session cost ~3s PER
9
+ * CALL, growing linearly with session length. With the cache the corpus is
10
+ * processed once; later searches are O(docs × query-terms).
11
+ *
12
+ * Keyed by doc text (immutable). Bounded by total cached source chars —
13
+ * oldest docs are evicted when the cap is exceeded, so a long-lived
14
+ * process serving many sessions cannot grow unboundedly. Hosts that want to
15
+ * release the memory eagerly on session shutdown/switch can call
16
+ * clearDocFeatures() (optional: the cap already bounds it).
17
+ */
18
+ export interface DocFeatures {
19
+ /** Stemmed term frequencies (BM25 channel). */
20
+ tf: Map<string, number>;
21
+ /** Total term count (BM25 length normalization). */
22
+ len: number;
23
+ /** Lower-cased text (substring + fuzzy channels). */
24
+ lower: string;
25
+ /** Unique char bigrams of `lower` (fuzzy channel). */
26
+ grams: Set<string>;
27
+ }
28
+ export declare function docFeatures(text: string): DocFeatures;
29
+ /** Drop all cached features (e.g. on session shutdown/switch). */
30
+ export declare function clearDocFeatures(): void;
31
+ /**
32
+ * Set the cache cap in source chars. Docs larger than the cap are never
33
+ * cached. Also used by tests to exercise eviction.
34
+ */
35
+ export declare function setDocCacheCap(chars: number): void;
36
+ /** Cache occupancy — for diagnostics. */
37
+ export declare function docCacheInfo(): {
38
+ entries: number;
39
+ chars: number;
40
+ };
41
+ //# sourceMappingURL=doc-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doc-cache.d.ts","sourceRoot":"","sources":["../../src/search/doc-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,WAAW,WAAW;IACxB,+CAA+C;IAC/C,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACtB;AAeD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAcrD;AAED,kEAAkE;AAClE,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAOlD;AAED,yCAAyC;AACzC,wBAAgB,YAAY,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAEjE"}
@@ -27,5 +27,7 @@ export declare function blockDocs(state: CompressionState): SearchDoc[];
27
27
  export declare function messageDocs(msgs: MessageInput[]): SearchDoc[];
28
28
  /** Sync entry — throws for async algorithms. Pass docs from blockDocs() + messageDocs(). */
29
29
  export declare function searchBlocks(docs: SearchDoc[], query: string, options?: SearchOptions): SearchResult[];
30
+ export { clearDocFeatures, docCacheInfo, docFeatures, setDocCacheCap } from "./doc-cache.js";
31
+ export type { DocFeatures } from "./doc-cache.js";
30
32
  export declare function searchBlocksAsync(docs: SearchDoc[], query: string, options?: SearchOptions): Promise<SearchResult[]>;
31
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,aAA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EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7F,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAE9H"}
@@ -3,9 +3,20 @@
3
3
  *
4
4
  * Handles mixed Latin + CJK content — the single biggest quality lever
5
5
  * over plain substring search. Latin is split on non-word boundaries;
6
- * CJK (no spaces) is decomposed into overlapping bigrams so a query like
7
- * "身份验证" still scores against doc text "身份验证流程".
6
+ * CJK (no spaces) is word-segmented via Intl.Segmenter (CLDR dictionary),
7
+ * falling back to overlapping bigrams on out-of-vocabulary text so a query
8
+ * like "身份验证" still scores against doc text "身份验证流程".
9
+ *
10
+ * CJK segmentation is a SINGLE segment() pass over the whole text, not one
11
+ * call per CJK run: a segment() call has fixed overhead (~3µs), and
12
+ * run-heavy text (logs: dozens of short runs per line) made per-run calls
13
+ * 10-16× slower than one bulk pass. ICU never merges CJK words across
14
+ * non-CJK boundaries, so bulk segmentation yields the same words per run
15
+ * (differential-verified against the per-run implementation across a
16
+ * mixed-script stress corpus); run boundaries are re-derived below to keep
17
+ * the all-OOV bigram fallback.
8
18
  */
19
+ export declare const CJK: RegExp;
9
20
  export interface TokenizeOptions {
10
21
  stem?: boolean;
11
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../src/search/tokenizer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,eAAoB,GAAG,MAAM,EAAE,CAuB3E;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOlD;AAED,0BAA0B;AAC1B,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAItE"}
1
+ {"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../src/search/tokenizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAYH,eAAO,MAAM,GAAG,QAA2D,CAAC;AAyB5E,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,eAAoB,GAAG,MAAM,EAAE,CA+C3E;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOlD;AAED,0BAA0B;AAC1B,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAItE"}
package/dist/search.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  * Search — re-exports from the modular src/search/ implementation.
3
3
  */
4
4
  export { searchBlocks, searchBlocksAsync, blockDocs, messageDocs } from "./search/index.js";
5
+ export { clearDocFeatures, docCacheInfo, docFeatures, setDocCacheCap } from "./search/index.js";
6
+ export type { DocFeatures } from "./search/index.js";
5
7
  export type { SearchResult, SearchOptions, SearchAlgorithm, AsyncSearchAlgorithm, AnySearchAlgorithm, SearchDoc, SearchDocKind, ScoredBlock, MessageRole, RoleWeights, MessageInput, } from "./search/types.js";
6
8
  export { DEFAULT_ALGORITHM, DEFAULT_ROLE_WEIGHTS } from "./search/types.js";
7
9
  export { registerSearchAlgorithm, getSearchAlgorithm, listSearchAlgorithms } from "./search/registry.js";
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5F,YAAY,EACR,YAAY,EACZ,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAChG,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,YAAY,EACR,YAAY,EACZ,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acp-kernel",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.",
5
5
  "license": "MIT",
6
6
  "author": "ranxianglei",