@avantf/dsh-mem 0.3.0 → 0.4.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 (145) hide show
  1. package/README.md +89 -28
  2. package/cordis.patch.yml +17 -0
  3. package/lib/client.js +155 -14
  4. package/lib/dsh-build.json +5 -5
  5. package/lib/engine/mem/config/config_files.d.ts +26 -0
  6. package/lib/engine/mem/config/domains.d.ts +20 -0
  7. package/lib/engine/mem/config/loader.d.ts +35 -0
  8. package/lib/engine/mem/config/paths.d.ts +53 -0
  9. package/lib/engine/mem/db/chunk.d.ts +26 -0
  10. package/lib/engine/mem/db/conn.d.ts +13 -0
  11. package/lib/engine/mem/db/dao/chunks.d.ts +150 -0
  12. package/lib/engine/mem/db/dao/contradictions.d.ts +98 -0
  13. package/lib/engine/mem/db/dao/documents.d.ts +51 -0
  14. package/lib/engine/mem/db/dao/entities.d.ts +67 -0
  15. package/lib/engine/mem/db/dao/facts.d.ts +472 -0
  16. package/lib/engine/mem/db/dao/stats.d.ts +14 -0
  17. package/lib/engine/mem/db/dao/triples.d.ts +80 -0
  18. package/lib/engine/mem/db/hash.d.ts +2 -0
  19. package/lib/engine/mem/db/knowledge.d.ts +17 -0
  20. package/lib/engine/mem/db/migrations.d.ts +71 -0
  21. package/lib/engine/mem/db/port.d.ts +57 -0
  22. package/lib/engine/mem/db/schema.d.ts +26 -0
  23. package/lib/engine/mem/db/sqlite.d.ts +89 -0
  24. package/lib/engine/mem/db/store.d.ts +35 -0
  25. package/lib/engine/mem/db/tokenizer.d.ts +61 -0
  26. package/lib/engine/mem/db/vectors.d.ts +50 -0
  27. package/lib/engine/mem/dispatch.d.ts +51 -0
  28. package/lib/engine/mem/entities/extract.d.ts +84 -0
  29. package/lib/engine/mem/eval/loader.d.ts +19 -0
  30. package/lib/engine/mem/eval/metrics.d.ts +25 -0
  31. package/lib/engine/mem/eval/runner.d.ts +10 -0
  32. package/lib/engine/mem/eval/write_metrics.d.ts +88 -0
  33. package/lib/engine/mem/git.d.ts +73 -0
  34. package/lib/engine/mem/hrr/algebra.d.ts +30 -0
  35. package/lib/engine/mem/hrr/atoms.d.ts +22 -0
  36. package/lib/engine/mem/hrr/encode.d.ts +32 -0
  37. package/lib/engine/mem/hrr/index.d.ts +3 -0
  38. package/lib/engine/mem/index.d.ts +27 -0
  39. package/lib/engine/mem/lifecycle/contradiction.d.ts +156 -0
  40. package/lib/engine/mem/lifecycle/index.d.ts +5 -0
  41. package/lib/engine/mem/lifecycle/maintenance.d.ts +48 -0
  42. package/lib/engine/mem/lifecycle/presence.d.ts +29 -0
  43. package/lib/engine/mem/lifecycle/tick.d.ts +43 -0
  44. package/lib/engine/mem/lifecycle/trust.d.ts +90 -0
  45. package/lib/engine/mem/modelBootstrap.d.ts +207 -0
  46. package/lib/engine/mem/router.d.ts +51 -0
  47. package/lib/engine/mem/runtime.d.ts +232 -0
  48. package/lib/engine/mem/store/common.d.ts +82 -0
  49. package/lib/engine/mem/store/doc_files.d.ts +125 -0
  50. package/lib/engine/mem/store/document_text.d.ts +47 -0
  51. package/lib/engine/mem/store/floors.d.ts +191 -0
  52. package/lib/engine/mem/store/hybrid.d.ts +232 -0
  53. package/lib/engine/mem/store/ingest_guard.d.ts +25 -0
  54. package/lib/engine/mem/store/knowledge.d.ts +483 -0
  55. package/lib/engine/mem/store/lexical.d.ts +67 -0
  56. package/lib/engine/mem/store/memory.d.ts +543 -0
  57. package/lib/engine/mem/store/source_picker.d.ts +43 -0
  58. package/lib/engine/mem-contract/config.d.ts +129 -0
  59. package/lib/engine/mem-contract/env.d.ts +31 -0
  60. package/lib/engine/mem-contract/family.d.ts +25 -0
  61. package/lib/engine/mem-contract/index.d.ts +8 -0
  62. package/lib/engine/mem-contract/log.d.ts +29 -0
  63. package/lib/engine/mem-contract/remote.d.ts +80 -0
  64. package/lib/engine/mem-contract/text.d.ts +92 -0
  65. package/lib/engine/mem-contract/tools.d.ts +284 -0
  66. package/lib/engine/mem-contract/types.d.ts +615 -0
  67. package/lib/engine/mem-retrieval/adapters/auto_vstore.d.ts +47 -0
  68. package/lib/engine/mem-retrieval/adapters/hnswlib.d.ts +174 -0
  69. package/lib/engine/mem-retrieval/adapters/local_bge.d.ts +121 -0
  70. package/lib/engine/mem-retrieval/adapters/local_numpy.d.ts +28 -0
  71. package/lib/engine/mem-retrieval/adapters/local_reranker.d.ts +52 -0
  72. package/lib/engine/mem-retrieval/adapters/none_reranker.d.ts +10 -0
  73. package/lib/engine/mem-retrieval/adapters/warm_gate.d.ts +46 -0
  74. package/lib/engine/mem-retrieval/budget.d.ts +30 -0
  75. package/lib/engine/mem-retrieval/fusion.d.ts +53 -0
  76. package/lib/engine/mem-retrieval/index.d.ts +14 -0
  77. package/lib/engine/mem-retrieval/interfaces.d.ts +82 -0
  78. package/lib/engine/mem-retrieval/log.d.ts +11 -0
  79. package/lib/engine/mem-retrieval/registry.d.ts +23 -0
  80. package/lib/engine/mem-retrieval/rerank.d.ts +13 -0
  81. package/lib/engine/mem-retrieval/stats.d.ts +64 -0
  82. package/lib/engine/mem-retrieval/text_budget.d.ts +52 -0
  83. package/lib/index.js +1773 -473
  84. package/lib/interface-version.json +2 -2
  85. package/lib/types/client/domains.d.ts +5 -4
  86. package/lib/types/client/domains.d.ts.map +1 -1
  87. package/lib/types/client/index.d.ts.map +1 -1
  88. package/lib/types/client/ingest.d.ts +1 -1
  89. package/lib/types/client/wire.d.ts +36 -0
  90. package/lib/types/client/wire.d.ts.map +1 -0
  91. package/lib/types/envinit-bootstrap.d.ts +3 -2
  92. package/lib/types/envinit.d.ts +2 -19
  93. package/lib/types/envinit.d.ts.map +1 -1
  94. package/lib/types/hints.d.ts +1 -1
  95. package/lib/types/index.d.ts +8 -3
  96. package/lib/types/index.d.ts.map +1 -1
  97. package/lib/types/open.d.ts +61 -11
  98. package/lib/types/open.d.ts.map +1 -1
  99. package/lib/types/prompt.d.ts +19 -1
  100. package/lib/types/prompt.d.ts.map +1 -1
  101. package/lib/types/provision.d.ts +1 -1
  102. package/lib/types/provision.d.ts.map +1 -1
  103. package/lib/types/reconcile.d.ts +64 -0
  104. package/lib/types/reconcile.d.ts.map +1 -0
  105. package/lib/types/remote.d.ts +53 -0
  106. package/lib/types/remote.d.ts.map +1 -1
  107. package/lib/types/render.d.ts +35 -0
  108. package/lib/types/render.d.ts.map +1 -0
  109. package/lib/types/tool_schema.d.ts +3 -13
  110. package/lib/types/tool_schema.d.ts.map +1 -1
  111. package/package.json +27 -18
  112. package/lib/client.js.map +0 -1
  113. package/lib/types/client/domains.js +0 -25
  114. package/lib/types/client/domains.js.map +0 -1
  115. package/lib/types/client/index.js +0 -1371
  116. package/lib/types/client/index.js.map +0 -1
  117. package/lib/types/client/ingest.js +0 -30
  118. package/lib/types/client/ingest.js.map +0 -1
  119. package/lib/types/client/paging.js +0 -36
  120. package/lib/types/client/paging.js.map +0 -1
  121. package/lib/types/client/summarize.js +0 -79
  122. package/lib/types/client/summarize.js.map +0 -1
  123. package/lib/types/data_home.js +0 -26
  124. package/lib/types/data_home.js.map +0 -1
  125. package/lib/types/envinit-bootstrap.js +0 -333
  126. package/lib/types/envinit.js +0 -402
  127. package/lib/types/envinit.js.map +0 -1
  128. package/lib/types/hints.js +0 -53
  129. package/lib/types/hints.js.map +0 -1
  130. package/lib/types/index.js +0 -755
  131. package/lib/types/index.js.map +0 -1
  132. package/lib/types/inject.js +0 -14
  133. package/lib/types/inject.js.map +0 -1
  134. package/lib/types/interface_gate.js +0 -84
  135. package/lib/types/interface_gate.js.map +0 -1
  136. package/lib/types/open.js +0 -133
  137. package/lib/types/open.js.map +0 -1
  138. package/lib/types/prompt.js +0 -148
  139. package/lib/types/prompt.js.map +0 -1
  140. package/lib/types/provision.js +0 -177
  141. package/lib/types/provision.js.map +0 -1
  142. package/lib/types/remote.js +0 -247
  143. package/lib/types/remote.js.map +0 -1
  144. package/lib/types/tool_schema.js +0 -149
  145. package/lib/types/tool_schema.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ import type { Reranker } from './interfaces.js';
2
+ /**
3
+ * The one rerank-and-reorder pass shared by every retrieval leg (memory search,
4
+ * knowledge search — the blocks were byte-identical and had already drifted once
5
+ * on the miss-sort sentinel).
6
+ *
7
+ * Contract: `reranker.rerank` returns candidate ids best-first; ids it omits sort
8
+ * last with their fused order preserved (stable sort). A disabled/unavailable
9
+ * reranker is a pass-through.
10
+ */
11
+ export declare function rerankHits<T extends {
12
+ id: number;
13
+ }>(reranker: Reranker, query: string, hits: T[], textOf: (id: number) => string): Promise<T[]>;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Process-wide retrieval health counters (DESIGN §20).
3
+ *
4
+ * What this answers, and why it is a counter rather than a query: "is the semantic leg
5
+ * actually live?", "how often does a query return nothing?", "how slow is retrieval?", and
6
+ * "did any budget truncate model-facing text?". None of those can be recovered from the
7
+ * database after the fact — the DB only holds what was stored, not how it was retrieved.
8
+ *
9
+ * In-process like {@link retrievalLogger}, with `snapshot()`/`restore()` so the STORE can
10
+ * persist the aggregate through `avantf_stats`: a restart resets counters in the reference
11
+ * design, which makes a long-lived degradation look like a fresh healthy process. The
12
+ * counters themselves stay free of any DB dependency (retrieval-core has none).
13
+ *
14
+ * The SHAPES live in `@avantf/mem-contract` (they are UI payloads — the settings page renders
15
+ * them), so this module only owns the counting.
16
+ */
17
+ import type { RetrievalFloorDrops, RetrievalHealth, RetrievalHealthSummary } from '../mem-contract/index.js';
18
+ export interface RetrievalEvent {
19
+ /** `memory` | `knowledge` | `cross` — free-form so a new store needs no schema change. */
20
+ kind: string;
21
+ results: number;
22
+ latencyMs: number;
23
+ semanticLive: boolean;
24
+ rerankUsed?: boolean;
25
+ rerankFallback?: boolean;
26
+ /**
27
+ * Per-leg candidates removed by the relevance floors before fusion. The per-leg shape is what
28
+ * makes an empty result readable ("the FTS floor cut 7 rows" vs "no leg had a candidate"); the
29
+ * aggregate counter below is what survives the process.
30
+ */
31
+ droppedByFloor?: RetrievalFloorDrops;
32
+ }
33
+ /** Record one completed retrieval. */
34
+ export declare function recordRetrieval(event: RetrievalEvent): void;
35
+ export type TruncationKind = 'embedding' | 'rerank' | 'output';
36
+ /**
37
+ * Record that a retrieval LEG returned exactly its cap, i.e. that its tail was dropped.
38
+ *
39
+ * The cap is a cost bound, and `fusion` scaling by each leg's maximum means a trimmed tail cannot
40
+ * rescale the survivors — but "cannot distort" is not "did not bind": past the headroom a leg's
41
+ * weakest entries simply cannot reach the result, and nothing else reports that. `size === cap` is
42
+ * the same proxy the lifecycle tick uses for "the budget ran out" (a leg that finished under the
43
+ * cap cannot have been cut).
44
+ */
45
+ export declare function recordLegCapped(): void;
46
+ /**
47
+ * Record that a budget had to bound model-facing text.
48
+ *
49
+ * This counter is the point of the whole module: the pre-existing behavior truncated
50
+ * embedding input silently, so nothing anywhere could tell that a store had been indexed
51
+ * with half its text missing.
52
+ */
53
+ export declare function recordTruncation(kind: TruncationKind): void;
54
+ /** A copy safe to hand to a caller (never the live object). */
55
+ export declare function retrievalHealth(): RetrievalHealth;
56
+ export declare function retrievalHealthSummary(): RetrievalHealthSummary;
57
+ /**
58
+ * Restore a snapshot read back from storage. Deliberately total: a snapshot written by an
59
+ * older build (or a corrupt row) must not break the diagnostics path, so unknown/missing
60
+ * numbers fall back to the empty counter instead of throwing.
61
+ */
62
+ export declare function restoreRetrievalHealth(snapshot: unknown): void;
63
+ /** Clear every counter (tests, and an explicit operator reset). */
64
+ export declare function resetRetrievalHealth(): void;
@@ -0,0 +1,52 @@
1
+ /** Window assumed when neither the config nor the loaded model declares one. */
2
+ export declare const DEFAULT_MODEL_WINDOW = 512;
3
+ /** Roughly how many tokens CJK text yields per character (used by the chunk-size derivation). */
4
+ export declare const CJK_TOKENS_PER_CHAR = 1;
5
+ /**
6
+ * Estimate the token count of `text`.
7
+ *
8
+ * Deliberately an OVER-estimate for mixed text: under-estimating is what silently drops
9
+ * content past the window, while over-estimating only truncates slightly earlier.
10
+ */
11
+ export declare function estimateTokens(text: string): number;
12
+ export interface TruncatedText {
13
+ /** The bounded text (equals the input when it already fit). */
14
+ text: string;
15
+ truncated: boolean;
16
+ /** Estimated tokens dropped, for the log line. */
17
+ omittedTokens: number;
18
+ }
19
+ /**
20
+ * Bound `text` to `maxTokens`, preferring a sentence/clause boundary near the cut and
21
+ * appending `marker` so the truncation is VISIBLE rather than silent.
22
+ *
23
+ * The marker's own cost is reserved out of the budget, and the result is verified against
24
+ * `maxTokens` before returning (the estimator rounds up per character class, so a naive
25
+ * character walk can land one token over).
26
+ */
27
+ export declare function truncateToTokens(text: string, maxTokens: number, opts?: {
28
+ marker?: string;
29
+ estimate?: (text: string) => number;
30
+ }): TruncatedText;
31
+ /**
32
+ * Resolve the effective input window for a loaded model.
33
+ *
34
+ * @param configured - `0` (or negative) means "auto: use the model's declared window".
35
+ * A positive value is an operator cap and is CLAMPED to the declared
36
+ * window when the model declares one, so `max_input_tokens` can never
37
+ * push text past what the model can actually read.
38
+ * @param declared - `model_max_length` reported by the loaded tokenizer, if any.
39
+ * @param fallback - used when neither is available.
40
+ */
41
+ export declare function resolveWindow(configured: number, declared: number | undefined, fallback?: number): number;
42
+ /**
43
+ * Read the declared window off a transformers.js pipeline. The pipeline is typed as a bare
44
+ * function in the adapters, so this probes defensively and treats a sentinel as absent.
45
+ */
46
+ export declare function declaredWindowOf(pipe: unknown): number | undefined;
47
+ /**
48
+ * Characters of a chunk that fit the window for `window` tokens, minus the per-chunk
49
+ * overhead (`specialTokens` for CLS/SEP). Used to derive `knowledge.chunk_size` so the
50
+ * default chunking is justified by the shipped model's window instead of by feel.
51
+ */
52
+ export declare function windowChars(window: number, specialTokens?: number): number;