@avantf/dsh-mem 0.8.1 → 0.10.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.
- package/README.md +42 -43
- package/lib/client.js +1181 -327
- package/lib/engine/graph-recall/index.d.ts +2 -2
- package/lib/engine/graph-recall/traverse.d.ts +2 -2
- package/lib/engine/graph-recall/types.d.ts +1 -1
- package/lib/engine/mem/config/config_files.d.ts +1 -1
- package/lib/engine/mem/db/dao/facts.d.ts +80 -82
- package/lib/engine/mem/dbdrivers/sqlite/facts.d.ts +6 -13
- package/lib/engine/mem/defaults.d.ts +4 -1
- package/lib/engine/mem/entities/extract.d.ts +34 -14
- package/lib/engine/mem/facts_io.d.ts +4 -0
- package/lib/engine/mem/index.d.ts +1 -0
- package/lib/engine/mem/interfaces/repositories.d.ts +5 -19
- package/lib/engine/mem/lifecycle/maintenance.d.ts +8 -4
- package/lib/engine/mem/lifecycle/tick.d.ts +11 -10
- package/lib/engine/mem/lifecycle/trust.d.ts +24 -37
- package/lib/engine/mem/modelBootstrap.d.ts +29 -0
- package/lib/engine/mem/runtime.d.ts +4 -8
- package/lib/engine/mem/store/facts_restore.d.ts +8 -6
- package/lib/engine/mem/store/graph_reader.d.ts +2 -2
- package/lib/engine/mem/store/memory.d.ts +98 -37
- package/lib/engine/mem/store/recall_policy.d.ts +10 -0
- package/lib/engine/mem/store/time_filter.d.ts +1 -1
- package/lib/engine/mem/trustHeartbeat.d.ts +1 -1
- package/lib/engine/mem-contract/config.d.ts +144 -9
- package/lib/engine/mem-contract/index.d.ts +2 -0
- package/lib/engine/mem-contract/time.d.ts +75 -0
- package/lib/engine/mem-contract/tools.d.ts +9 -15
- package/lib/engine/mem-contract/trust_curve.d.ts +119 -0
- package/lib/engine/mem-contract/types.d.ts +73 -12
- package/lib/engine/mem-retrieval/adapters/auto_vstore.d.ts +10 -0
- package/lib/engine/mem-retrieval/adapters/hnswlib.d.ts +28 -0
- package/lib/engine/mem-retrieval/adapters/local_bge.d.ts +48 -6
- package/lib/engine/mem-retrieval/interfaces.d.ts +22 -2
- package/lib/engine/mem-retrieval/text_budget.d.ts +31 -0
- package/lib/index.js +2349 -665
- package/lib/interface-version.json +2 -2
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/paging.d.ts +58 -8
- package/lib/types/client/paging.d.ts.map +1 -1
- package/lib/types/client/time_filter.d.ts +54 -0
- package/lib/types/client/time_filter.d.ts.map +1 -0
- package/lib/types/command.d.ts.map +1 -1
- package/lib/types/deps_audit.d.ts +88 -0
- package/lib/types/deps_audit.d.ts.map +1 -0
- package/lib/types/envinit-bootstrap.d.ts +1 -1
- package/lib/types/envinit.d.ts +224 -4
- package/lib/types/envinit.d.ts.map +1 -1
- package/lib/types/hints.d.ts +58 -0
- package/lib/types/hints.d.ts.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/remote.d.ts.map +1 -1
- package/lib/types/render.d.ts.map +1 -1
- package/lib/types/runtime_deps_resource.d.ts +29 -0
- package/lib/types/runtime_deps_resource.d.ts.map +1 -0
- package/package.json +26 -24
- package/res/runtime-deps.yaml +99 -0
|
@@ -39,6 +39,16 @@ export declare class AutoVectorStore implements VectorStore {
|
|
|
39
39
|
/** Build the ANN index now if one is owed (see the class comment). */
|
|
40
40
|
prepare(): void;
|
|
41
41
|
attachPersistence(path: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Point the ANN side at a shared module root (the plugin's native self-heal item) — for THIS store
|
|
44
|
+
* when it already migrated, and for the one it may migrate to later.
|
|
45
|
+
*
|
|
46
|
+
* The delegate call covers the first case; the module-level root (set by
|
|
47
|
+
* `HnswlibVectorStore.useModuleDir` / `useHnswlibModuleDir`) is what a FUTURE
|
|
48
|
+
* `new HnswlibVectorStore` in `maybeUpgrade` reads. Below the threshold nothing changes: an
|
|
49
|
+
* unmigrated store keeps serving from brute force, which is the intended backend at that size.
|
|
50
|
+
*/
|
|
51
|
+
useModuleDir(dir: string): void;
|
|
42
52
|
flush(): void;
|
|
43
53
|
/** Reclaim dead entries in the migrated backend (the numpy fallback has none). */
|
|
44
54
|
compact(): void;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { VectorStore } from '../interfaces.js';
|
|
2
|
+
/**
|
|
3
|
+
* Point the loader at a shared module root (the base `runtime-deps` handle's directory).
|
|
4
|
+
*
|
|
5
|
+
* The cache follows the ROOT: a change forgets what was loaded, because the next `require` must come
|
|
6
|
+
* from the new root (that is the whole point of setting one). It costs nothing in practice — Node's
|
|
7
|
+
* own `require` cache makes re-entering the same file cheap, and a live native index is untouched
|
|
8
|
+
* (see `HnswlibVectorStore.useModuleDir`, which only rebuilds when it has no native index at all).
|
|
9
|
+
*/
|
|
10
|
+
export declare function useHnswlibModuleDir(dir: string | undefined): void;
|
|
2
11
|
/**
|
|
3
12
|
* Search-time beam width, when the config does not say otherwise.
|
|
4
13
|
*
|
|
@@ -63,6 +72,25 @@ export declare class HnswlibVectorStore implements VectorStore {
|
|
|
63
72
|
private restores;
|
|
64
73
|
private rebuilds;
|
|
65
74
|
constructor(dim: number, efSearch?: number);
|
|
75
|
+
/**
|
|
76
|
+
* Build a native index at `max` capacity, or `null` when the binding cannot be loaded.
|
|
77
|
+
*
|
|
78
|
+
* One place for "make an index": the constructor, `reindex()` and `rebuild()` each used to spell
|
|
79
|
+
* the `require` out themselves, which is how a module root set after construction could never
|
|
80
|
+
* reach them. `null` is the caller's signal to serve from {@link fallback} — a missing binding
|
|
81
|
+
* degrades, it never throws.
|
|
82
|
+
*/
|
|
83
|
+
private openNative;
|
|
84
|
+
/**
|
|
85
|
+
* Point this store's native side at a shared module root and, when the binding was unavailable
|
|
86
|
+
* until now, rebuild the index from the tracked vectors under it.
|
|
87
|
+
*
|
|
88
|
+
* This is the case the whole hook exists for: `mem` builds its vector store during mount, while the
|
|
89
|
+
* native self-heal item is still installing, so the constructor may have fallen back. When the item
|
|
90
|
+
* settles, the plugin calls this — and a store that already serves natively is left alone (the
|
|
91
|
+
* binding is the same one).
|
|
92
|
+
*/
|
|
93
|
+
useModuleDir(dir: string): void;
|
|
66
94
|
add(id: number, vec: Float32Array): void;
|
|
67
95
|
/** Whether the real hnswlib native index is active (false = brute-force fallback). */
|
|
68
96
|
get native(): boolean;
|
|
@@ -53,6 +53,16 @@ export interface ModelEnv {
|
|
|
53
53
|
* the eager constructor warm.
|
|
54
54
|
*/
|
|
55
55
|
deferWarm?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Module root to load `@huggingface/transformers` from, when it is not this tree's own optional
|
|
58
|
+
* dependency. The DSH plugin sets it (through {@link LocalBgeBackend.useModuleDir}) to the base
|
|
59
|
+
* provider's shared `runtime-deps` root after the semantic self-heal item is ready.
|
|
60
|
+
*
|
|
61
|
+
* Empty/absent = the pre-existing resolution: `import('@huggingface/transformers')` from this
|
|
62
|
+
* module, i.e. the optional dependency or nothing. A root that no longer resolves falls back to
|
|
63
|
+
* that path with one warning — a deleted store must not be worse than no self-heal.
|
|
64
|
+
*/
|
|
65
|
+
moduleDir?: string;
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
68
|
* Local BGE embedder via `@huggingface/transformers` (transformers.js, ONNX).
|
|
@@ -101,6 +111,8 @@ export declare class LocalBgeBackend implements SemanticBackend {
|
|
|
101
111
|
* the weights). The resolved representation is CACHED, so the warning is one line per process.
|
|
102
112
|
*/
|
|
103
113
|
representation(): SemanticRepresentation;
|
|
114
|
+
/** Point the loader at a shared runtime-dependency root before the first warmup. */
|
|
115
|
+
useModuleDir(dir: string): void;
|
|
104
116
|
/**
|
|
105
117
|
* Fire-and-forget retry for call sites that only observe availability. No-op
|
|
106
118
|
* while the model is ready or an attempt is already in flight; otherwise
|
|
@@ -119,14 +131,44 @@ export declare class LocalBgeBackend implements SemanticBackend {
|
|
|
119
131
|
*/
|
|
120
132
|
private window;
|
|
121
133
|
/**
|
|
122
|
-
*
|
|
134
|
+
* The window-sized slices `text` is encoded in (see `text_budget.splitToWindows`).
|
|
135
|
+
*
|
|
136
|
+
* WHERE THE BOUNDARY CAN LIVE. The feature-extraction pipeline's `_call` accepts
|
|
137
|
+
* `{pooling, normalize, quantize, precision}` and nothing else, so `max_length` cannot be raised
|
|
138
|
+
* from the call site — past `model_max_length` transformers.js truncates and says nothing. This
|
|
139
|
+
* adapter is therefore the only place that can apply the model's own window, and it SPLITS rather
|
|
140
|
+
* than cuts: a text past the window is a document chunk (or a long fact) whose tail is content,
|
|
141
|
+
* and cutting it dropped 503 of ~1015 tokens out of the vector in production.
|
|
142
|
+
*/
|
|
143
|
+
private windows;
|
|
144
|
+
/**
|
|
145
|
+
* Report an input that needed more than one window — once per process, and as an INFO line.
|
|
146
|
+
*
|
|
147
|
+
* Not a warning any more: nothing is lost (every window is pooled into the one vector), so the
|
|
148
|
+
* line is a tuning hint, not a degradation. It carries the actionable number: `chunk_size` is
|
|
149
|
+
* measured in CHARACTERS and {@link windowChars} converts the model's token window into exactly
|
|
150
|
+
* that, which is the thing an operator (or a chunker's default) has to change to keep one window
|
|
151
|
+
* per input. `semantic.max_input_tokens` is deliberately NOT suggested: `resolveWindow` clamps it
|
|
152
|
+
* to the model's declared window, so raising it cannot buy a single extra token.
|
|
153
|
+
*/
|
|
154
|
+
private reportSplit;
|
|
155
|
+
/** The configured width's vector: model output padded/truncated, with the one-shot dim warning. */
|
|
156
|
+
private toVector;
|
|
157
|
+
/**
|
|
158
|
+
* ONE vector for several windows: token-weighted mean of the window vectors, re-normalized when the
|
|
159
|
+
* representation normalizes.
|
|
123
160
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
161
|
+
* Weighted rather than a plain mean because the last window is usually short, and a plain mean
|
|
162
|
+
* would over-represent a fragment. Mean-of-normalized-vectors then re-normalized is the mean
|
|
163
|
+
* DIRECTION of the windows — the same coordinate space the model's own mean pooling produces, so
|
|
164
|
+
* `representationKey` (`pooling`/`normalize`/window) does not move and stored vectors stay
|
|
165
|
+
* comparable with the ones this writes.
|
|
128
166
|
*/
|
|
129
|
-
private
|
|
167
|
+
private pool;
|
|
168
|
+
/** Encode the windows of one text in ONE model call, falling back to one call per window. */
|
|
169
|
+
private encodeWindows;
|
|
170
|
+
/** Encode one plan: a single window verbatim, several pooled. */
|
|
171
|
+
private encodePlan;
|
|
130
172
|
encode(text: string): Promise<Float32Array>;
|
|
131
173
|
/**
|
|
132
174
|
* Encode several texts in ONE model call.
|
|
@@ -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
|
|
23
|
-
* adapter bounds text to before encoding
|
|
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
|
*
|