@oh-my-pi/pi-mnemosyne 15.6.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 (126) hide show
  1. package/README.md +107 -0
  2. package/dist/types/cli.d.ts +35 -0
  3. package/dist/types/config.d.ts +77 -0
  4. package/dist/types/core/aaak.d.ts +55 -0
  5. package/dist/types/core/annotations.d.ts +75 -0
  6. package/dist/types/core/banks.d.ts +33 -0
  7. package/dist/types/core/beam/consolidate.d.ts +32 -0
  8. package/dist/types/core/beam/helpers.d.ts +59 -0
  9. package/dist/types/core/beam/index.d.ts +59 -0
  10. package/dist/types/core/beam/recall.d.ts +32 -0
  11. package/dist/types/core/beam/schema.d.ts +2 -0
  12. package/dist/types/core/beam/store.d.ts +35 -0
  13. package/dist/types/core/beam/types.d.ts +233 -0
  14. package/dist/types/core/binary-vectors.d.ts +54 -0
  15. package/dist/types/core/chat-normalize.d.ts +13 -0
  16. package/dist/types/core/content-sanitizer.d.ts +18 -0
  17. package/dist/types/core/cost-log.d.ts +13 -0
  18. package/dist/types/core/embeddings.d.ts +35 -0
  19. package/dist/types/core/entities.d.ts +7 -0
  20. package/dist/types/core/episodic-graph.d.ts +89 -0
  21. package/dist/types/core/extraction/client.d.ts +31 -0
  22. package/dist/types/core/extraction/diagnostics.d.ts +51 -0
  23. package/dist/types/core/extraction/prompts.d.ts +2 -0
  24. package/dist/types/core/extraction.d.ts +6 -0
  25. package/dist/types/core/index.d.ts +4 -0
  26. package/dist/types/core/llm-backends.d.ts +21 -0
  27. package/dist/types/core/local-llm.d.ts +15 -0
  28. package/dist/types/core/memory.d.ts +160 -0
  29. package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
  30. package/dist/types/core/migrations/index.d.ts +1 -0
  31. package/dist/types/core/mmr.d.ts +8 -0
  32. package/dist/types/core/orchestrator.d.ts +20 -0
  33. package/dist/types/core/patterns.d.ts +61 -0
  34. package/dist/types/core/plugins.d.ts +109 -0
  35. package/dist/types/core/polyphonic-recall.d.ts +66 -0
  36. package/dist/types/core/query-cache.d.ts +47 -0
  37. package/dist/types/core/query-intent.d.ts +20 -0
  38. package/dist/types/core/recall-diagnostics.d.ts +48 -0
  39. package/dist/types/core/runtime-options.d.ts +61 -0
  40. package/dist/types/core/shmr.d.ts +56 -0
  41. package/dist/types/core/streaming.d.ts +136 -0
  42. package/dist/types/core/synonyms.d.ts +46 -0
  43. package/dist/types/core/temporal-parser.d.ts +16 -0
  44. package/dist/types/core/token-counter.d.ts +8 -0
  45. package/dist/types/core/triples.d.ts +63 -0
  46. package/dist/types/core/typed-memory.d.ts +39 -0
  47. package/dist/types/core/veracity-consolidation.d.ts +60 -0
  48. package/dist/types/core/weibull.d.ts +96 -0
  49. package/dist/types/db.d.ts +16 -0
  50. package/dist/types/diagnose.d.ts +24 -0
  51. package/dist/types/dr/index.d.ts +1 -0
  52. package/dist/types/dr/recovery.d.ts +68 -0
  53. package/dist/types/index.d.ts +5 -0
  54. package/dist/types/mcp-server.d.ts +40 -0
  55. package/dist/types/mcp-tools.d.ts +484 -0
  56. package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
  57. package/dist/types/migrations/index.d.ts +1 -0
  58. package/dist/types/types.d.ts +145 -0
  59. package/dist/types/util/datetime.d.ts +8 -0
  60. package/dist/types/util/env.d.ts +10 -0
  61. package/dist/types/util/ids.d.ts +3 -0
  62. package/dist/types/util/lru.d.ts +12 -0
  63. package/dist/types/util/regex.d.ts +10 -0
  64. package/package.json +82 -0
  65. package/src/cli.ts +390 -0
  66. package/src/config.ts +326 -0
  67. package/src/core/aaak.ts +142 -0
  68. package/src/core/annotations.ts +457 -0
  69. package/src/core/banks.ts +133 -0
  70. package/src/core/beam/consolidate.ts +963 -0
  71. package/src/core/beam/helpers.ts +920 -0
  72. package/src/core/beam/index.ts +353 -0
  73. package/src/core/beam/recall.ts +1091 -0
  74. package/src/core/beam/schema.ts +423 -0
  75. package/src/core/beam/store.ts +818 -0
  76. package/src/core/beam/types.ts +268 -0
  77. package/src/core/binary-vectors.ts +336 -0
  78. package/src/core/chat-normalize.ts +160 -0
  79. package/src/core/content-sanitizer.ts +136 -0
  80. package/src/core/cost-log.ts +103 -0
  81. package/src/core/embeddings.ts +490 -0
  82. package/src/core/entities.ts +259 -0
  83. package/src/core/episodic-graph.ts +708 -0
  84. package/src/core/extraction/client.ts +162 -0
  85. package/src/core/extraction/diagnostics.ts +193 -0
  86. package/src/core/extraction/prompts.ts +31 -0
  87. package/src/core/extraction.ts +335 -0
  88. package/src/core/index.ts +30 -0
  89. package/src/core/llm-backends.ts +51 -0
  90. package/src/core/local-llm.ts +436 -0
  91. package/src/core/memory.ts +617 -0
  92. package/src/core/migrations/e6-triplestore-split.ts +211 -0
  93. package/src/core/migrations/index.ts +1 -0
  94. package/src/core/mmr.ts +71 -0
  95. package/src/core/orchestrator.ts +53 -0
  96. package/src/core/patterns.ts +484 -0
  97. package/src/core/plugins.ts +375 -0
  98. package/src/core/polyphonic-recall.ts +563 -0
  99. package/src/core/query-cache.ts +370 -0
  100. package/src/core/query-intent.ts +139 -0
  101. package/src/core/recall-diagnostics.ts +157 -0
  102. package/src/core/runtime-options.ts +108 -0
  103. package/src/core/shmr.ts +471 -0
  104. package/src/core/streaming.ts +419 -0
  105. package/src/core/synonyms.ts +197 -0
  106. package/src/core/temporal-parser.ts +363 -0
  107. package/src/core/token-counter.ts +30 -0
  108. package/src/core/triples.ts +452 -0
  109. package/src/core/typed-memory.ts +407 -0
  110. package/src/core/veracity-consolidation.ts +477 -0
  111. package/src/core/weibull.ts +124 -0
  112. package/src/db.ts +128 -0
  113. package/src/diagnose.ts +174 -0
  114. package/src/dr/index.ts +1 -0
  115. package/src/dr/recovery.ts +405 -0
  116. package/src/index.ts +32 -0
  117. package/src/mcp-server.ts +155 -0
  118. package/src/mcp-tools.ts +961 -0
  119. package/src/migrations/e6-triplestore-split.ts +1 -0
  120. package/src/migrations/index.ts +1 -0
  121. package/src/types.ts +157 -0
  122. package/src/util/datetime.ts +69 -0
  123. package/src/util/env.ts +65 -0
  124. package/src/util/ids.ts +19 -0
  125. package/src/util/lru.ts +48 -0
  126. package/src/util/regex.ts +165 -0
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # @oh-my-pi/pi-mnemosyne
2
+
3
+ Local SQLite memory engine for Oh My Pi agents.
4
+
5
+ This package is the Bun/TypeScript port of the Mnemosyne memory engine. It provides:
6
+
7
+ - `Mnemosyne`, a small facade for remember/recall/stats/sleep workflows.
8
+ - `BeamMemory`, the lower-level working/episodic memory engine.
9
+ - MCP tool definitions and a dispatcher for host integrations.
10
+ - Optional local ONNX embeddings through `fastembed` and optional OpenAI-compatible embedding/LLM endpoints.
11
+
12
+ The package does not bundle or download a local GGUF LLM. LLM paths are host-backend or OpenAI-compatible remote only; when no LLM is configured, deterministic heuristic paths are used.
13
+
14
+ ## Basic use
15
+
16
+ ```ts
17
+ import { Mnemosyne } from "@oh-my-pi/pi-mnemosyne";
18
+
19
+ const memory = new Mnemosyne({ dbPath: "./mnemosyne.db", bank: "project" });
20
+ const id = memory.remember("The deployment target is stable-cluster.", {
21
+ source: "notes",
22
+ importance: 0.8,
23
+ veracity: "true",
24
+ });
25
+
26
+ const results = memory.recall("deployment target", 5);
27
+ console.log(id, results[0]?.content);
28
+
29
+ memory.close();
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ `Mnemosyne` accepts LLM and embedding options directly. `MNEMOSYNE_*` environment variables remain fallbacks/defaults when the matching constructor option is omitted.
35
+
36
+ ```ts
37
+ import { Mnemosyne } from "@oh-my-pi/pi-mnemosyne";
38
+ import type { Model } from "@oh-my-pi/pi-ai";
39
+
40
+ const ftsOnly = new Mnemosyne({ noEmbeddings: true });
41
+
42
+ const remoteEmbeddings = new Mnemosyne({
43
+ embeddingModel: "text-embedding-3-small",
44
+ embeddingApiUrl: "https://api.openai.com/v1",
45
+ embeddingApiKey: process.env.OPENAI_API_KEY,
46
+ });
47
+
48
+ const remoteLlm = new Mnemosyne({
49
+ llm: {
50
+ baseUrl: "https://api.openai.com/v1",
51
+ apiKey: process.env.OPENAI_API_KEY,
52
+ model: "gpt-4.1-mini",
53
+ },
54
+ // Equivalent aliases: llmBaseUrl, llmApiKey, llmModel.
55
+ });
56
+
57
+ declare const smolModel: Model;
58
+ const piAiLlm = new Mnemosyne({ llm: smolModel });
59
+ const dynamicLlm = new Mnemosyne({
60
+ llm: async (prompt, opts) => {
61
+ const token = await getFreshOauthToken();
62
+ return await completeWithPiAi(prompt, {
63
+ token,
64
+ maxTokens: opts?.maxTokens,
65
+ temperature: opts?.temperature,
66
+ });
67
+ },
68
+ });
69
+ ```
70
+
71
+ ### Banks and host scoping
72
+
73
+ `Mnemosyne` itself exposes banks directly through constructor options such as `bank`; it does not hard-code coding-agent project scoping.
74
+
75
+ The Oh My Pi coding-agent wrapper adds `mnemosyne.scoping` on top of those constructor options:
76
+
77
+ - `global`: one shared bank
78
+ - `per-project`: isolated project memory
79
+ - `per-project-tagged`: project-local writes plus global recall visibility
80
+
81
+ In `per-project-tagged`, the wrapper is responsible for combining project-local retention with global recall visibility. The package still just exposes banks plus constructor-level LLM and embedding options.
82
+
83
+ Common environment fallbacks:
84
+
85
+ - `MNEMOSYNE_DATA_DIR` / `MNEMOSYNE_DB_PATH`: default storage location.
86
+ - `MNEMOSYNE_NO_EMBEDDINGS=1`: force FTS-only recall.
87
+ - `MNEMOSYNE_EMBEDDING_MODEL`: defaults to `BAAI/bge-small-en-v1.5`.
88
+ - `MNEMOSYNE_EMBEDDING_API_URL` and `MNEMOSYNE_EMBEDDING_API_KEY`: OpenAI-compatible embedding endpoint.
89
+ - `MNEMOSYNE_LLM_ENABLED=1`, `MNEMOSYNE_LLM_BASE_URL`, `MNEMOSYNE_LLM_API_KEY`, `MNEMOSYNE_LLM_MODEL`: OpenAI-compatible LLM endpoint.
90
+
91
+ Local embeddings use the `fastembed` npm package. Its default `BGESmallENV15` model is 384-dimensional and uses the package's CLS pooling plus vector normalization path. Local GGUF LLMs are not available in this package.
92
+
93
+ ## Commands
94
+
95
+ ```sh
96
+ mnemosyne remember "Use stable-cluster for production deploys"
97
+ mnemosyne recall "production deploy target"
98
+ mnemosyne stats
99
+ mnemosyne sleep
100
+ ```
101
+
102
+ ## Tests
103
+
104
+ ```sh
105
+ bun --cwd packages/mnemosyne test
106
+ bun --cwd packages/mnemosyne run check
107
+ ```
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bun
2
+ import { BeamMemory } from "./core/beam";
3
+ export interface CliIo {
4
+ write(data: string): void;
5
+ }
6
+ export interface CliContext {
7
+ readonly dataDir?: string;
8
+ readonly dbPath?: string;
9
+ readonly memory?: BeamMemory;
10
+ readonly createMemory?: () => BeamMemory;
11
+ readonly stdout?: CliIo;
12
+ readonly stderr?: CliIo;
13
+ }
14
+ export declare class CliError extends Error {
15
+ readonly exitCode: number;
16
+ constructor(message: string, exitCode?: number);
17
+ }
18
+ type CommandHandler = (args: readonly string[], context?: CliContext) => number | Promise<number>;
19
+ export declare function memoryStats(memory: BeamMemory, dataDir?: string): Record<string, unknown>;
20
+ export declare const cmdExport: CommandHandler;
21
+ export declare const cmdImport: CommandHandler;
22
+ export declare const cmdMcp: CommandHandler;
23
+ export declare const cmdRemember: CommandHandler;
24
+ export declare const cmdRecall: CommandHandler;
25
+ export declare const cmdUpdate: CommandHandler;
26
+ export declare const cmdDelete: CommandHandler;
27
+ export declare const cmdStats: CommandHandler;
28
+ export declare const cmdSleep: CommandHandler;
29
+ export declare const cmdScratchpad: CommandHandler;
30
+ export declare const cmdBank: CommandHandler;
31
+ export declare const cmdDiagnose: CommandHandler;
32
+ export declare const COMMANDS: Readonly<Record<string, CommandHandler>>;
33
+ export declare function printHelp(context?: CliContext): void;
34
+ export declare function runCli(args?: readonly string[], context?: CliContext): Promise<number>;
35
+ export {};
@@ -0,0 +1,77 @@
1
+ import { type Env, envBool, envDisabled, envFloat, envInt, envOneOf, envOptionalString, envString, envTruthy } from "./util/env";
2
+ export type { Env };
3
+ export { envBool, envDisabled, envFloat, envInt, envOneOf, envOptionalString, envString, envTruthy };
4
+ export declare const DEFAULT_DATA_DIR: string;
5
+ export declare const DEFAULT_DB_FILENAME = "mnemosyne.db";
6
+ export declare const FASTEMBED_CACHE_DIR: string;
7
+ export declare const MODEL_CACHE_DIR: string;
8
+ export declare const DEFAULT_EMBEDDING_MODEL = "BAAI/bge-small-en-v1.5";
9
+ export declare const DEFAULT_EMBEDDING_API_URL = "https://openrouter.ai/api/v1";
10
+ export declare const DEFAULT_LLM_MODEL_REPO = "TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF";
11
+ export declare const DEFAULT_LLM_MODEL_FILE = "tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf";
12
+ export declare const HOST_LLM_TIMEOUT_SECONDS = 15;
13
+ export type VecType = "float32" | "int8" | "bit";
14
+ export declare const EMBEDDING_DIMS: Readonly<Record<string, number>>;
15
+ export declare const VERACITY_WEIGHT_DEFAULTS: {
16
+ readonly stated: 1;
17
+ readonly inferred: 0.7;
18
+ readonly tool: 0.5;
19
+ readonly imported: 0.6;
20
+ readonly unknown: 0.8;
21
+ };
22
+ export declare function dataDir(env?: Env): string;
23
+ export declare function dbPath(env?: Env): string;
24
+ export declare function beamOptimizationsEnabled(env?: Env): boolean;
25
+ export declare function embeddingModel(env?: Env): string;
26
+ export declare function embeddingDim(env?: Env): number;
27
+ export declare function embeddingApiKey(env?: Env): string;
28
+ export declare function embeddingApiUrl(env?: Env): string;
29
+ export declare function embeddingsViaApi(env?: Env): boolean;
30
+ export declare function embeddingsDisabled(env?: Env): boolean;
31
+ export declare function isApiEmbeddingModel(model?: string, env?: Env): boolean;
32
+ export declare function apiEmbeddingsAvailable(env?: Env): boolean;
33
+ export declare function workingMemoryMaxItems(env?: Env): number;
34
+ export declare function workingMemoryTtlHours(env?: Env): number;
35
+ export declare function episodicRecallLimit(env?: Env): number;
36
+ export declare function sleepBatchSize(env?: Env): number;
37
+ export declare function scratchpadMaxItems(env?: Env): number;
38
+ export declare function recencyHalflifeHours(env?: Env): number;
39
+ export declare function tier2Days(env?: Env): number;
40
+ export declare function tier3Days(env?: Env): number;
41
+ export declare function tier1Weight(env?: Env): number;
42
+ export declare function tier2Weight(env?: Env): number;
43
+ export declare function tier3Weight(env?: Env): number;
44
+ export declare function degradeBatchSize(env?: Env): number;
45
+ export declare function smartCompressEnabled(env?: Env): boolean;
46
+ export declare function tier3MaxChars(env?: Env): number;
47
+ export declare function statedWeight(env?: Env): number;
48
+ export declare function inferredWeight(env?: Env): number;
49
+ export declare function toolWeight(env?: Env): number;
50
+ export declare function importedWeight(env?: Env): number;
51
+ export declare function unknownWeight(env?: Env): number;
52
+ export declare function veracityWeightOverrides(env?: Env): string[];
53
+ export declare function vecType(env?: Env): VecType;
54
+ export declare function vectorWeight(env?: Env): number;
55
+ export declare function ftsWeight(env?: Env): number;
56
+ export declare function importanceWeight(env?: Env): number;
57
+ export declare function normalizedRecallWeights(vec?: number, fts?: number, importance?: number): readonly [number, number, number];
58
+ export declare function autoMigrateEnabled(env?: Env): boolean;
59
+ export declare function proactiveLinkingEnabled(env?: Env): boolean;
60
+ export declare function polyphonicRecallEnabled(env?: Env): boolean;
61
+ export declare function temporalHalflifeHours(env?: Env): number;
62
+ export declare function enhancedRecallEnabled(env?: Env): boolean;
63
+ export declare function llmEnabled(env?: Env): boolean;
64
+ export declare function llmMaxTokens(env?: Env): number;
65
+ export declare function llmThreads(env?: Env): number;
66
+ export declare function llmContext(env?: Env): number;
67
+ export declare function llmRepo(env?: Env): string;
68
+ export declare function llmFile(env?: Env): string;
69
+ export declare function llmModelFiles(env?: Env): readonly [repo: string, file: string];
70
+ export declare function llmBaseUrl(env?: Env): string;
71
+ export declare function llmApiKey(env?: Env): string;
72
+ export declare function llmModel(env?: Env): string;
73
+ export declare function hostLlmEnabled(env?: Env): boolean;
74
+ export declare function hostLlmProvider(env?: Env): string | undefined;
75
+ export declare function hostLlmModel(env?: Env): string | undefined;
76
+ export declare function hostLlmContext(env?: Env): number;
77
+ export declare function sleepPrompt(env?: Env): string;
@@ -0,0 +1,55 @@
1
+ export declare const CATEGORY_MAP: {
2
+ readonly PREFERENCE: "PREF";
3
+ readonly TRAIT: "TRAIT";
4
+ readonly STATUS: "STAT";
5
+ readonly INSTRUCTION: "INST";
6
+ readonly PROJECT: "PROJ";
7
+ readonly LOCATION: "LOC";
8
+ readonly FAMILY: "FAM";
9
+ readonly OCCUPATION: "OCC";
10
+ readonly DECISION: "DEC";
11
+ readonly EVENT: "EVT";
12
+ readonly TOOL: "TOOL";
13
+ readonly FACT: "FACT";
14
+ readonly OPINION: "OPN";
15
+ };
16
+ export declare const PHRASE_MAP: {
17
+ readonly "User asked ": "ASK ";
18
+ readonly "User wants ": "WANT ";
19
+ readonly "User prefers ": "PREF ";
20
+ readonly "User likes ": "LIKE ";
21
+ readonly "User dislikes ": "DISLIKE ";
22
+ readonly "User is ": "IS ";
23
+ readonly "User has ": "HAS ";
24
+ readonly "User built ": "BUILT ";
25
+ readonly "User asked for ": "ASK ";
26
+ readonly "User requested ": "REQ ";
27
+ readonly "Married to ": "MARRIED→";
28
+ readonly "Email: ": "@";
29
+ readonly "GitHub: ": "GH:";
30
+ readonly "Location: ": "LOC:";
31
+ readonly "Phone: ": "PH:";
32
+ readonly "User email is ": "@";
33
+ readonly "User voice message ": "VM ";
34
+ readonly "User stack: ": "STACK|";
35
+ readonly "Full-stack developer": "FSDEV";
36
+ readonly "Software Developer": "SDEV";
37
+ readonly "AI Systems Engineer": "AIENG";
38
+ readonly "real-time": "RT";
39
+ readonly "Real-time": "RT";
40
+ readonly bilingual: "bi";
41
+ readonly Bilingual: "bi";
42
+ readonly "self-hosted": "selfhost";
43
+ readonly automation: "auto";
44
+ readonly transcription: "transc";
45
+ readonly translation: "transl";
46
+ };
47
+ export declare const STRUCTURAL_REPLACEMENTS: readonly (readonly [pattern: string, replacement: string])[];
48
+ export declare const REV_CATEGORY: Record<"DEC" | "EVT" | "FACT" | "FAM" | "INST" | "LOC" | "OCC" | "OPN" | "PREF" | "PROJ" | "STAT" | "TOOL" | "TRAIT", "DECISION" | "EVENT" | "FACT" | "FAMILY" | "INSTRUCTION" | "LOCATION" | "OCCUPATION" | "OPINION" | "PREFERENCE" | "PROJECT" | "STATUS" | "TOOL" | "TRAIT">;
49
+ export declare const REV_PHRASE: Record<"@" | "AIENG" | "ASK " | "BUILT " | "DISLIKE " | "FSDEV" | "GH:" | "HAS " | "IS " | "LIKE " | "LOC:" | "MARRIED→" | "PH:" | "PREF " | "REQ " | "RT" | "SDEV" | "STACK|" | "VM " | "WANT " | "auto" | "bi" | "selfhost" | "transc" | "transl", "AI Systems Engineer" | "Bilingual" | "Email: " | "Full-stack developer" | "GitHub: " | "Location: " | "Married to " | "Phone: " | "Real-time" | "Software Developer" | "User asked " | "User asked for " | "User built " | "User dislikes " | "User email is " | "User has " | "User is " | "User likes " | "User prefers " | "User requested " | "User stack: " | "User voice message " | "User wants " | "automation" | "bilingual" | "real-time" | "self-hosted" | "transcription" | "translation">;
50
+ export declare function applyCategoryPrefixes(text: string): string;
51
+ export declare function applyPhrases(text: string): string;
52
+ export declare function applyStructural(text: string): string;
53
+ export declare function compactParens(text: string): string;
54
+ export declare function encode(text: string): string;
55
+ export declare const aaakEncode: typeof encode;
@@ -0,0 +1,75 @@
1
+ import type { Database } from "bun:sqlite";
2
+ declare const ANNOTATION_KIND_VALUES: readonly ["mentions", "fact", "occurred_on", "has_source"];
3
+ export type AnnotationKind = (typeof ANNOTATION_KIND_VALUES)[number] | (string & {});
4
+ export declare const ENTITY_STOP_WORDS: ReadonlySet<string>;
5
+ export declare const ANNOTATION_KINDS: ReadonlySet<string>;
6
+ export declare const MIN_FACT_LENGTH = 10;
7
+ export interface AnnotationRow {
8
+ readonly id: number;
9
+ readonly memory_id: string;
10
+ readonly kind: string;
11
+ readonly value: string;
12
+ readonly source: string | null;
13
+ readonly confidence: number | null;
14
+ readonly created_at: string | null;
15
+ }
16
+ export interface AnnotationInput {
17
+ readonly id?: number | bigint | null;
18
+ readonly memory_id: string;
19
+ readonly kind: string;
20
+ readonly value: string;
21
+ readonly source?: string | null;
22
+ readonly confidence?: number | null;
23
+ readonly created_at?: string | null;
24
+ }
25
+ export interface AnnotationImportStats {
26
+ inserted: number;
27
+ skipped: number;
28
+ overwritten: number;
29
+ imported_renumbered: number;
30
+ }
31
+ export interface AnnotationStoreOptions {
32
+ readonly dbPath?: string;
33
+ readonly db_path?: string;
34
+ readonly db?: Database;
35
+ readonly conn?: Database;
36
+ }
37
+ export declare function filterCleanMentions<T extends {
38
+ readonly value?: string | null;
39
+ }>(rows: readonly T[]): T[];
40
+ export declare function filterFacts(facts: readonly string[] | null | undefined): string[];
41
+ export declare function initAnnotations(path?: string): void;
42
+ export declare function initAnnotationsWithConn(db: Database): void;
43
+ export declare class AnnotationStore {
44
+ readonly dbPath: string;
45
+ readonly db: Database;
46
+ readonly conn: Database;
47
+ private readonly ownsConnection;
48
+ constructor(options?: AnnotationStoreOptions | string);
49
+ close(): void;
50
+ add(memoryId: string, kind: string, value: string, source?: string, confidence?: number): number;
51
+ addMany(memoryId: string, kind: string, values: readonly string[] | null | undefined, source?: string, confidence?: number): number;
52
+ queryByMemory(memoryId: string, kind?: string | null): AnnotationRow[];
53
+ queryByKind(kind: string, options?: {
54
+ readonly value?: string | null;
55
+ readonly memory_id?: string | null;
56
+ readonly memoryId?: string | null;
57
+ readonly filter_noise?: boolean;
58
+ readonly filterNoise?: boolean;
59
+ }): AnnotationRow[];
60
+ getDistinctValues(kind: string): string[];
61
+ exportAll(): AnnotationRow[];
62
+ importAll(annotations: readonly AnnotationInput[], force?: boolean): AnnotationImportStats;
63
+ }
64
+ export declare function addAnnotation(memoryId: string, kind: string, value: string, source?: string, confidence?: number, path?: string): number;
65
+ export interface QueryAnnotationsOptions {
66
+ readonly memory_id?: string | null;
67
+ readonly memoryId?: string | null;
68
+ readonly kind?: string | null;
69
+ readonly value?: string | null;
70
+ readonly db_path?: string | null;
71
+ readonly dbPath?: string | null;
72
+ }
73
+ export declare function queryAnnotations(options?: QueryAnnotationsOptions): AnnotationRow[];
74
+ export declare function queryAnnotations(memoryId?: string | null, kind?: string | null, value?: string | null, dbPath?: string | null): AnnotationRow[];
75
+ export {};
@@ -0,0 +1,33 @@
1
+ export declare const DEFAULT_DATA_DIR: string;
2
+ export declare const BANKS_DIR: string;
3
+ export declare class ValueError extends Error {
4
+ name: string;
5
+ }
6
+ export interface BankStats {
7
+ readonly name: string;
8
+ readonly exists: boolean;
9
+ readonly db_path: string;
10
+ readonly dbSizeBytes: number;
11
+ readonly db_size_bytes: number;
12
+ }
13
+ export declare class BankManager {
14
+ readonly dataDir: string;
15
+ readonly banksDir: string;
16
+ constructor(dataDir?: string);
17
+ createBank(name: string): string;
18
+ deleteBank(name: string, force?: boolean): boolean;
19
+ listBanks(): string[];
20
+ bankExists(name: string): boolean;
21
+ getBankDbPath(name: string): string;
22
+ renameBank(oldName: string, newName: string): string;
23
+ getBankStats(name: string): BankStats;
24
+ private validateName;
25
+ }
26
+ export declare function createBank(name: string, dataDir?: string): string;
27
+ export declare function deleteBank(name: string, dataDir?: string, force?: boolean): boolean;
28
+ export declare function listBanks(dataDir?: string): string[];
29
+ export declare function bankExists(name: string, dataDir?: string): boolean;
30
+ export declare function bankDbPath(name?: string, dataDir?: string): string;
31
+ export declare function setBank(bank: string): void;
32
+ export declare function getBank(): string;
33
+ export declare function resetBankForTests(): void;
@@ -0,0 +1,32 @@
1
+ import type { BeamMemoryState, BeamStats, JsonValue, MemoriaRetrieveResult, Metadata, SleepResult } from "./types";
2
+ type Row = Record<string, unknown>;
3
+ type FactCounts = {
4
+ metric: number;
5
+ date: number;
6
+ version: number;
7
+ entity: number;
8
+ sequence: number;
9
+ timeline: number;
10
+ negation: number;
11
+ decision: number;
12
+ };
13
+ type ConsolidateOptions = {
14
+ metadata?: Metadata | null;
15
+ validUntil?: string | null;
16
+ scope?: string;
17
+ veracity?: string | null;
18
+ };
19
+ export declare function consolidateToEpisodic(beam: BeamMemoryState, summary: string, sourceWmIds: readonly string[], source?: string, importance?: number, options?: ConsolidateOptions): string;
20
+ export declare function detectLanguage(_beam: BeamMemoryState, text: string): string;
21
+ export declare function storeFactStrings(beam: BeamMemoryState, facts: readonly string[], messageIdx?: number, sourceMemoryId?: string | null, importance?: number): number;
22
+ export declare function extractAndStoreFacts(beam: BeamMemoryState, content: string, messageIdx?: number, sourceMemoryId?: string | null): FactCounts;
23
+ export declare function memoriaRetrieve(beam: BeamMemoryState, query: string, ability?: string | null, topK?: number): MemoriaRetrieveResult;
24
+ export declare function getEpisodicStats(beam: BeamMemoryState, authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
25
+ export declare function getMemoriaStats(beam: BeamMemoryState): BeamStats;
26
+ export declare function degradeEpisodic(beam: BeamMemoryState, dryRun?: boolean): Record<string, JsonValue>;
27
+ export declare function getContaminated(beam: BeamMemoryState, limit?: number, minImportance?: number): Row[];
28
+ export declare function health(beam: BeamMemoryState, staleThresholdHours?: number): Record<string, JsonValue | Record<string, JsonValue>>;
29
+ export declare function sleep(beam: BeamMemoryState, dryRun?: boolean): SleepResult;
30
+ export declare function sleepAllSessions(beam: BeamMemoryState, dryRun?: boolean): SleepResult;
31
+ export declare function getConsolidationLog(beam: BeamMemoryState, limit?: number): Row[];
32
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import { sha256Hex16 } from "../../util/ids";
3
+ import type { BeamMemoryState, Metadata } from "./types";
4
+ export type Vector = number[];
5
+ export type HybridWeights = readonly [vecWeight: number, ftsWeight: number, importanceWeight: number];
6
+ export interface VectorDistanceResult {
7
+ rowid: number;
8
+ distance: number;
9
+ }
10
+ export interface WorkingVectorResult {
11
+ id: string;
12
+ sim: number;
13
+ }
14
+ export interface FtsRankResult {
15
+ rowid: number;
16
+ rank: number;
17
+ }
18
+ export interface WorkingFtsRankResult {
19
+ id: string;
20
+ rank: number;
21
+ }
22
+ export declare function generateId(content: string, now?: Date): string;
23
+ export declare function generateStableId(content: string, source?: string): string;
24
+ export declare function normalizeWeights(vecWeight: number | null | undefined, ftsWeight: number | null | undefined, importanceWeight: number | null | undefined): HybridWeights;
25
+ export declare function normalizeImportance(importance: number | null | undefined, fallback?: number): number;
26
+ export declare function normalizeDateUtc(dt: Date): Date;
27
+ export declare function parseIsoDateTimeUtc(value: string): Date;
28
+ export declare function parseQueryTime(queryTime?: string | Date | null): Date;
29
+ export declare function parseTimestampFast(ts: string | null | undefined, beam?: Pick<BeamMemoryState, "caches"> | null): Date | null;
30
+ export declare function recencyDecay(timestamp: string | null | undefined, halflifeHours?: number, now?: Date): number;
31
+ export declare function temporalBoost(memoryTimestamp: string | null | undefined, queryTime: Date | string, halflifeHours?: number, beam?: Pick<BeamMemoryState, "caches"> | null): number;
32
+ export declare function recallTokens(text: string): string[];
33
+ export declare function expandedQueryTokens(tokens: readonly string[]): string[];
34
+ export declare function minimumRecallRelevance(queryTokens: readonly string[]): number;
35
+ export declare function factMatchTokens(text: string): Set<string>;
36
+ export declare function containsSpacelessCjk(text: string): boolean;
37
+ export declare function hasCjk(text: string): boolean;
38
+ export declare function cjkFtsTerms(text: string): string[];
39
+ export declare function lexicalRelevance(queryTokens: readonly string[], content: string, queryLower?: string): number;
40
+ export declare function strictFactMatches(query: string, factText: string): boolean;
41
+ export declare function ftsQueryTerms(query: string): string[];
42
+ export declare function buildFtsQuery(query: string): string;
43
+ export declare function cjkLikeSearch(db: Database, query: string, k?: number, working?: boolean): Array<FtsRankResult | WorkingFtsRankResult>;
44
+ export declare function ftsSearch(db: Database, query: string, k?: number): FtsRankResult[];
45
+ export declare function ftsSearchWorking(db: Database, query: string, k?: number): WorkingFtsRankResult[];
46
+ export declare function encodeVector(embedding: readonly number[]): string;
47
+ export declare function decodeVector(value: string | null | undefined): Vector | null;
48
+ export declare function vecAvailable(db: Database): boolean;
49
+ export declare function effectiveVecType(db: Database): "float32" | "int8" | "bit";
50
+ export declare function vecInsert(db: Database, rowid: number, embedding: readonly number[]): void;
51
+ export declare function vecSearch(db: Database, embedding: readonly number[], k?: number): VectorDistanceResult[];
52
+ export declare function inMemoryVecSearch(db: Database, queryEmbedding: readonly number[], k?: number): VectorDistanceResult[];
53
+ export declare function workingMemoryVecSearch(db: Database, queryEmbedding: readonly number[], k?: number, now?: Date): WorkingVectorResult[];
54
+ export declare function normalizeMetadata(input: unknown): Metadata;
55
+ export declare function metadataJson(input: unknown): string;
56
+ export declare function detectLanguage(text: string): string;
57
+ export declare function memoryRowMetadata(row: unknown): Metadata;
58
+ export { cosineSimilarity, hammingDistance, informationTheoreticScore, maximallyInformativeBinarization, quantizeInt8, } from "../binary-vectors";
59
+ export { sha256Hex16 };
@@ -0,0 +1,59 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import type { BeamCaches, BeamConfig, BeamEvent, BeamMemoryOptions, BeamMemoryState, BeamStats, ImportStats, MemoriaRetrieveResult, Metadata, RecallEnhancedOptions, RecallOptions, RecallResult, RememberBatchItem, RememberBatchOptions, RememberOptions, SleepResult } from "./types";
3
+ export { initBeam } from "./schema";
4
+ export type * from "./types";
5
+ export declare class BeamMemory implements BeamMemoryState {
6
+ #private;
7
+ readonly db: Database;
8
+ readonly dbPath?: string;
9
+ readonly sessionId: string;
10
+ readonly authorId: string | null;
11
+ readonly authorType: string | null;
12
+ readonly channelId: string;
13
+ readonly useCloud: boolean;
14
+ readonly eventEmitter?: (event: BeamEvent) => void;
15
+ readonly pluginManager: BeamMemoryState["pluginManager"];
16
+ readonly annotations: BeamMemoryState["annotations"];
17
+ readonly triples: BeamMemoryState["triples"];
18
+ readonly episodicGraph: unknown | null;
19
+ readonly veracityConsolidator: unknown | null;
20
+ readonly caches: BeamCaches;
21
+ readonly config: BeamConfig;
22
+ readonly pendingExtractions: Set<Promise<void>>;
23
+ constructor(options?: BeamMemoryOptions);
24
+ constructor(sessionId?: string, dbPath?: string, authorId?: string | null, authorType?: string | null, channelId?: string | null, useCloud?: boolean, eventEmitter?: (event: BeamEvent) => void);
25
+ close(): void;
26
+ flushExtractions(): Promise<void>;
27
+ remember(content: string, options?: RememberOptions): string;
28
+ rememberBatch(items: readonly RememberBatchItem[], options?: RememberBatchOptions): string[];
29
+ getContext(limit?: number): unknown[];
30
+ invalidate(memoryId: string, replacementId?: string | null): boolean;
31
+ getWorkingStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
32
+ getGlobalWorkingStats(): BeamStats;
33
+ updateWorking(memoryId: string, content?: string | null, importance?: number | null): boolean;
34
+ get(memoryId: string): unknown | null;
35
+ forgetWorking(memoryId: string): boolean;
36
+ consolidateToEpisodic(summary: string, sourceWmIds: readonly string[], source?: string, importance?: number): string;
37
+ detectLanguage(text: string): string;
38
+ extractAndStoreFacts(content: string, messageIdx?: number, sourceMemoryId?: string | null): Record<string, unknown>;
39
+ memoriaRetrieve(query: string, ability?: string | null, topK?: number): MemoriaRetrieveResult;
40
+ recall(query: string, topK?: number, options?: RecallOptions): RecallResult[];
41
+ recallEnhanced(query: string, topK?: number, options?: RecallEnhancedOptions): RecallResult[];
42
+ formatContext(results: readonly RecallResult[], format?: string): string;
43
+ factRecall(query: string, topK?: number): RecallResult[];
44
+ getEpisodicStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
45
+ getMemoriaStats(): BeamStats;
46
+ scratchpadWrite(content: string): string;
47
+ scratchpadRead(): unknown[];
48
+ scratchpadClear(): void;
49
+ degradeEpisodic(dryRun?: boolean): Record<string, unknown>;
50
+ getContaminated(limit?: number, minImportance?: number): unknown[];
51
+ health(staleThresholdHours?: number): Record<string, unknown>;
52
+ sleep(dryRun?: boolean): SleepResult;
53
+ sleepAllSessions(dryRun?: boolean): SleepResult;
54
+ getConsolidationLog(limit?: number): unknown[];
55
+ exportToDict(): Record<string, unknown>;
56
+ importFromDict(data: Record<string, unknown>, force?: boolean): ImportStats;
57
+ protected emitEvent(type: string, data?: Omit<BeamEvent, "type" | "sessionId" | "timestamp">): void;
58
+ protected metadataJson(metadata: Metadata | null | undefined): string | null;
59
+ }
@@ -0,0 +1,32 @@
1
+ import type { BeamMemoryState, RecallEnhancedOptions, RecallOptions, RecallResult } from "./types";
2
+ type RecallOptionsInternal = RecallOptions & {
3
+ source?: string | null;
4
+ topic?: string | null;
5
+ veracity?: string | null;
6
+ memoryType?: string | null;
7
+ temporalWeight?: number;
8
+ temporalHalflife?: number;
9
+ vecWeight?: number;
10
+ ftsWeight?: number;
11
+ importanceWeight?: number;
12
+ queryEmbedding?: readonly number[] | null;
13
+ useSynonyms?: boolean;
14
+ useIntent?: boolean;
15
+ useMmr?: boolean;
16
+ mmrLambda?: number;
17
+ ignoreSessionScope?: boolean;
18
+ currentSensitive?: boolean;
19
+ updateRecallCounts?: boolean;
20
+ };
21
+ type FactRecallResult = RecallResult & {
22
+ fact_id?: string;
23
+ subject?: string;
24
+ predicate?: string;
25
+ };
26
+ export declare function parseQueryTime(value: RecallOptionsInternal["queryTime"]): Date;
27
+ export declare function temporalBoost(timestamp: unknown, queryTime: Date, halfLifeHours: number): number;
28
+ export declare function recall(beam: BeamMemoryState, query: string, topK?: number, options?: RecallOptionsInternal): RecallResult[];
29
+ export declare function recallEnhanced(beam: BeamMemoryState, query: string, topK?: number, options?: RecallEnhancedOptions & RecallOptionsInternal): RecallResult[];
30
+ export declare function formatContext(beam: BeamMemoryState, results: readonly RecallResult[], format?: string): string;
31
+ export declare function factRecall(beam: BeamMemoryState, query: string, topK?: number): FactRecallResult[];
32
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Database } from "bun:sqlite";
2
+ export declare function initBeam(db: Database): void;
@@ -0,0 +1,35 @@
1
+ import type { BeamMemoryState, BeamStats, ImportStats, RememberBatchItem, RememberBatchOptions, RememberOptions } from "./types";
2
+ type Row = Record<string, unknown>;
3
+ type StoreRememberOptions = RememberOptions & {
4
+ memoryId?: string;
5
+ memory_id?: string;
6
+ validUntil?: string | null;
7
+ valid_until?: string | null;
8
+ authorId?: string | null;
9
+ author_id?: string | null;
10
+ authorType?: string | null;
11
+ author_type?: string | null;
12
+ extractEntities?: boolean;
13
+ extract_entities?: boolean;
14
+ channelId?: string | null;
15
+ channel_id?: string | null;
16
+ };
17
+ type StoreRememberBatchOptions = RememberBatchOptions & {
18
+ forceVeracity?: boolean;
19
+ force_veracity?: boolean;
20
+ };
21
+ export declare function remember(beam: BeamMemoryState, content: string, options?: StoreRememberOptions): string;
22
+ export declare function rememberBatch(beam: BeamMemoryState, items: readonly RememberBatchItem[], options?: StoreRememberBatchOptions): string[];
23
+ export declare function getContext(beam: BeamMemoryState, limit?: number): Row[];
24
+ export declare function invalidate(beam: BeamMemoryState, memoryId: string, replacementId?: string | null): boolean;
25
+ export declare function getWorkingStats(beam: BeamMemoryState, authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
26
+ export declare function getGlobalWorkingStats(beam: BeamMemoryState): BeamStats;
27
+ export declare function updateWorking(beam: BeamMemoryState, memoryId: string, content?: string | null, importance?: number | null): boolean;
28
+ export declare function get(beam: BeamMemoryState, memoryId: string): Row | null;
29
+ export declare function forgetWorking(beam: BeamMemoryState, memoryId: string): boolean;
30
+ export declare function scratchpadWrite(beam: BeamMemoryState, content: string): string;
31
+ export declare function scratchpadRead(beam: BeamMemoryState): Row[];
32
+ export declare function scratchpadClear(beam: BeamMemoryState): void;
33
+ export declare function exportToDict(beam: BeamMemoryState): Record<string, unknown>;
34
+ export declare function importFromDict(beam: BeamMemoryState, data: Record<string, unknown>, force?: boolean): ImportStats;
35
+ export {};