@avantf/dsh-mem 0.8.0 → 0.9.0

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.
Files changed (39) hide show
  1. package/lib/client.js +1088 -303
  2. package/lib/engine/graph-recall/index.d.ts +2 -2
  3. package/lib/engine/graph-recall/traverse.d.ts +2 -2
  4. package/lib/engine/graph-recall/types.d.ts +1 -1
  5. package/lib/engine/mem/config/config_files.d.ts +1 -1
  6. package/lib/engine/mem/defaults.d.ts +4 -1
  7. package/lib/engine/mem/entities/extract.d.ts +34 -14
  8. package/lib/engine/mem/index.d.ts +1 -0
  9. package/lib/engine/mem/modelBootstrap.d.ts +29 -0
  10. package/lib/engine/mem/store/graph_reader.d.ts +2 -2
  11. package/lib/engine/mem/store/memory.d.ts +53 -6
  12. package/lib/engine/mem/store/recall_policy.d.ts +10 -0
  13. package/lib/engine/mem-contract/config.d.ts +135 -0
  14. package/lib/engine/mem-contract/types.d.ts +11 -0
  15. package/lib/engine/mem-retrieval/adapters/auto_vstore.d.ts +10 -0
  16. package/lib/engine/mem-retrieval/adapters/hnswlib.d.ts +28 -0
  17. package/lib/engine/mem-retrieval/adapters/local_bge.d.ts +48 -6
  18. package/lib/engine/mem-retrieval/interfaces.d.ts +22 -2
  19. package/lib/engine/mem-retrieval/text_budget.d.ts +31 -0
  20. package/lib/index.js +1617 -114
  21. package/lib/interface-version.json +2 -2
  22. package/lib/types/client/index.d.ts.map +1 -1
  23. package/lib/types/client/paging.d.ts +58 -8
  24. package/lib/types/client/paging.d.ts.map +1 -1
  25. package/lib/types/client/time_filter.d.ts +54 -0
  26. package/lib/types/client/time_filter.d.ts.map +1 -0
  27. package/lib/types/deps_audit.d.ts +88 -0
  28. package/lib/types/deps_audit.d.ts.map +1 -0
  29. package/lib/types/envinit-bootstrap.d.ts +1 -1
  30. package/lib/types/envinit.d.ts +224 -4
  31. package/lib/types/envinit.d.ts.map +1 -1
  32. package/lib/types/hints.d.ts +58 -0
  33. package/lib/types/hints.d.ts.map +1 -1
  34. package/lib/types/index.d.ts.map +1 -1
  35. package/lib/types/render.d.ts.map +1 -1
  36. package/lib/types/runtime_deps_resource.d.ts +29 -0
  37. package/lib/types/runtime_deps_resource.d.ts.map +1 -0
  38. package/package.json +5 -4
  39. package/res/runtime-deps.yaml +99 -0
@@ -19,8 +19,9 @@ export interface SemanticRepresentation {
19
19
  /** Whether vectors are L2-normalized by the pipeline (cosine relies on it). */
20
20
  readonly normalize: boolean;
21
21
  /**
22
- * The CONFIGURED input-token cap (`0` = auto/declared window), i.e. the truncation window the
23
- * adapter bounds text to before encoding. The CONFIGURED value, not the resolved one: the
22
+ * The CONFIGURED input-token cap (`0` = auto/declared window), i.e. the input window the
23
+ * adapter bounds text to before encoding (an over-window text is split into windows and pooled —
24
+ * `text_budget.splitToWindows` — so the window bounds the INPUT, it no longer drops its tail). The CONFIGURED value, not the resolved one: the
24
25
  * resolved window depends on the loaded tokenizer, so it is unknown before warmup — and the
25
26
  * fingerprint must be identical before and after warmup, or a store would declare its own rows
26
27
  * stale the moment the model finished loading.
@@ -56,6 +57,15 @@ export interface SemanticBackend {
56
57
  * floor. Implementations that load lazily may omit it.
57
58
  */
58
59
  ensureWarm?(): void;
60
+ /**
61
+ * Optional: point the backend at an external module root for its native runtime dependency.
62
+ *
63
+ * The DSH plugin sets this to the base provider's shared `runtime-deps` root once that item is
64
+ * ready, so a package the plugin's own tree does not contain can still be loaded from the
65
+ * content-addressed store. Called BEFORE `warmUp()`; a backend that resolves its dependency
66
+ * statically may omit it, and one whose store root is absent keeps its normal resolution.
67
+ */
68
+ useModuleDir?(dir: string): void;
59
69
  }
60
70
  /** Distance/ann index over entry vectors (per-store instance). */
61
71
  export interface VectorStore {
@@ -98,6 +108,16 @@ export interface VectorStore {
98
108
  * snapshot built from another space. Best-effort: a missing/corrupt/stale file is rebuilt.
99
109
  */
100
110
  attachPersistence?(path: string): void;
111
+ /**
112
+ * Optional: point the backend at an external module root for its NATIVE dependency.
113
+ *
114
+ * The DSH plugin sets this to the base provider's shared `runtime-deps` root once the native
115
+ * self-heal item is ready, so `hnswlib-node` can be loaded from the content-addressed store. Unlike
116
+ * `SemanticBackend.useModuleDir` it may arrive AFTER construction (the item settles in the
117
+ * background): an implementation whose native side already failed to load must retry from the new
118
+ * root rather than stay on its fallback. A backend with no native dependency omits it.
119
+ */
120
+ useModuleDir?(dir: string): void;
101
121
  /**
102
122
  * Optional: persist any state that is only in memory. Called on shutdown; implementations that
103
123
  * have nothing pending may omit it.
@@ -28,6 +28,37 @@ export declare function truncateToTokens(text: string, maxTokens: number, opts?:
28
28
  marker?: string;
29
29
  estimate?: (text: string) => number;
30
30
  }): TruncatedText;
31
+ /** A model-facing text sliced into window-sized pieces (see {@link splitToWindows}). */
32
+ export interface WindowedText {
33
+ /** The windows, in order. Concatenated they ARE the input: nothing is dropped. */
34
+ windows: string[];
35
+ /** Estimated tokens of the whole input. */
36
+ tokens: number;
37
+ /** Estimated tokens of each window, aligned with {@link windows} (the pooling weight). */
38
+ windowTokens: number[];
39
+ }
40
+ /**
41
+ * Slice `text` into windows of at most `maxTokens` estimated tokens instead of truncating it.
42
+ *
43
+ * WHY THIS EXISTS. The window belongs to the loaded model and the call site cannot widen it, so a
44
+ * text past it has exactly one of two fates: cut (what {@link truncateToTokens} does, and what
45
+ * transformers.js does silently on its own) or split. A knowledge chunk of ~1000 characters against
46
+ * a 512-token model lost half its content from the vector that way — measured in production as
47
+ * "503 tokens dropped here". Splitting keeps every token in the representation; the adapter that
48
+ * can only return ONE vector then pools the window vectors (`LocalBgeBackend.encode`).
49
+ *
50
+ * Every returned window satisfies `estimate(window) <= maxTokens` (a one-character window is the
51
+ * floor; the estimator cannot exceed a limit of 1 token for a single character). Cuts land on a
52
+ * sentence/clause boundary when one is in the window's final quarter, so a window does not start or
53
+ * end mid-word.
54
+ *
55
+ * @param text - the input.
56
+ * @param maxTokens - the per-window budget (already net of special tokens, as the adapter computes it).
57
+ * @param opts - estimator override (tests use a flat one); defaults to {@link estimateTokens}.
58
+ */
59
+ export declare function splitToWindows(text: string, maxTokens: number, opts?: {
60
+ estimate?: (text: string) => number;
61
+ }): WindowedText;
31
62
  /**
32
63
  * Resolve the effective input window for a loaded model.
33
64
  *