@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.
- package/README.md +107 -0
- package/dist/types/cli.d.ts +35 -0
- package/dist/types/config.d.ts +77 -0
- package/dist/types/core/aaak.d.ts +55 -0
- package/dist/types/core/annotations.d.ts +75 -0
- package/dist/types/core/banks.d.ts +33 -0
- package/dist/types/core/beam/consolidate.d.ts +32 -0
- package/dist/types/core/beam/helpers.d.ts +59 -0
- package/dist/types/core/beam/index.d.ts +59 -0
- package/dist/types/core/beam/recall.d.ts +32 -0
- package/dist/types/core/beam/schema.d.ts +2 -0
- package/dist/types/core/beam/store.d.ts +35 -0
- package/dist/types/core/beam/types.d.ts +233 -0
- package/dist/types/core/binary-vectors.d.ts +54 -0
- package/dist/types/core/chat-normalize.d.ts +13 -0
- package/dist/types/core/content-sanitizer.d.ts +18 -0
- package/dist/types/core/cost-log.d.ts +13 -0
- package/dist/types/core/embeddings.d.ts +35 -0
- package/dist/types/core/entities.d.ts +7 -0
- package/dist/types/core/episodic-graph.d.ts +89 -0
- package/dist/types/core/extraction/client.d.ts +31 -0
- package/dist/types/core/extraction/diagnostics.d.ts +51 -0
- package/dist/types/core/extraction/prompts.d.ts +2 -0
- package/dist/types/core/extraction.d.ts +6 -0
- package/dist/types/core/index.d.ts +4 -0
- package/dist/types/core/llm-backends.d.ts +21 -0
- package/dist/types/core/local-llm.d.ts +15 -0
- package/dist/types/core/memory.d.ts +160 -0
- package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
- package/dist/types/core/migrations/index.d.ts +1 -0
- package/dist/types/core/mmr.d.ts +8 -0
- package/dist/types/core/orchestrator.d.ts +20 -0
- package/dist/types/core/patterns.d.ts +61 -0
- package/dist/types/core/plugins.d.ts +109 -0
- package/dist/types/core/polyphonic-recall.d.ts +66 -0
- package/dist/types/core/query-cache.d.ts +47 -0
- package/dist/types/core/query-intent.d.ts +20 -0
- package/dist/types/core/recall-diagnostics.d.ts +48 -0
- package/dist/types/core/runtime-options.d.ts +61 -0
- package/dist/types/core/shmr.d.ts +56 -0
- package/dist/types/core/streaming.d.ts +136 -0
- package/dist/types/core/synonyms.d.ts +46 -0
- package/dist/types/core/temporal-parser.d.ts +16 -0
- package/dist/types/core/token-counter.d.ts +8 -0
- package/dist/types/core/triples.d.ts +63 -0
- package/dist/types/core/typed-memory.d.ts +39 -0
- package/dist/types/core/veracity-consolidation.d.ts +60 -0
- package/dist/types/core/weibull.d.ts +96 -0
- package/dist/types/db.d.ts +16 -0
- package/dist/types/diagnose.d.ts +24 -0
- package/dist/types/dr/index.d.ts +1 -0
- package/dist/types/dr/recovery.d.ts +68 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mcp-server.d.ts +40 -0
- package/dist/types/mcp-tools.d.ts +484 -0
- package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
- package/dist/types/migrations/index.d.ts +1 -0
- package/dist/types/types.d.ts +145 -0
- package/dist/types/util/datetime.d.ts +8 -0
- package/dist/types/util/env.d.ts +10 -0
- package/dist/types/util/ids.d.ts +3 -0
- package/dist/types/util/lru.d.ts +12 -0
- package/dist/types/util/regex.d.ts +10 -0
- package/package.json +82 -0
- package/src/cli.ts +390 -0
- package/src/config.ts +326 -0
- package/src/core/aaak.ts +142 -0
- package/src/core/annotations.ts +457 -0
- package/src/core/banks.ts +133 -0
- package/src/core/beam/consolidate.ts +963 -0
- package/src/core/beam/helpers.ts +920 -0
- package/src/core/beam/index.ts +353 -0
- package/src/core/beam/recall.ts +1091 -0
- package/src/core/beam/schema.ts +423 -0
- package/src/core/beam/store.ts +818 -0
- package/src/core/beam/types.ts +268 -0
- package/src/core/binary-vectors.ts +336 -0
- package/src/core/chat-normalize.ts +160 -0
- package/src/core/content-sanitizer.ts +136 -0
- package/src/core/cost-log.ts +103 -0
- package/src/core/embeddings.ts +490 -0
- package/src/core/entities.ts +259 -0
- package/src/core/episodic-graph.ts +708 -0
- package/src/core/extraction/client.ts +162 -0
- package/src/core/extraction/diagnostics.ts +193 -0
- package/src/core/extraction/prompts.ts +31 -0
- package/src/core/extraction.ts +335 -0
- package/src/core/index.ts +30 -0
- package/src/core/llm-backends.ts +51 -0
- package/src/core/local-llm.ts +436 -0
- package/src/core/memory.ts +617 -0
- package/src/core/migrations/e6-triplestore-split.ts +211 -0
- package/src/core/migrations/index.ts +1 -0
- package/src/core/mmr.ts +71 -0
- package/src/core/orchestrator.ts +53 -0
- package/src/core/patterns.ts +484 -0
- package/src/core/plugins.ts +375 -0
- package/src/core/polyphonic-recall.ts +563 -0
- package/src/core/query-cache.ts +370 -0
- package/src/core/query-intent.ts +139 -0
- package/src/core/recall-diagnostics.ts +157 -0
- package/src/core/runtime-options.ts +108 -0
- package/src/core/shmr.ts +471 -0
- package/src/core/streaming.ts +419 -0
- package/src/core/synonyms.ts +197 -0
- package/src/core/temporal-parser.ts +363 -0
- package/src/core/token-counter.ts +30 -0
- package/src/core/triples.ts +452 -0
- package/src/core/typed-memory.ts +407 -0
- package/src/core/veracity-consolidation.ts +477 -0
- package/src/core/weibull.ts +124 -0
- package/src/db.ts +128 -0
- package/src/diagnose.ts +174 -0
- package/src/dr/index.ts +1 -0
- package/src/dr/recovery.ts +405 -0
- package/src/index.ts +32 -0
- package/src/mcp-server.ts +155 -0
- package/src/mcp-tools.ts +961 -0
- package/src/migrations/e6-triplestore-split.ts +1 -0
- package/src/migrations/index.ts +1 -0
- package/src/types.ts +157 -0
- package/src/util/datetime.ts +69 -0
- package/src/util/env.ts +65 -0
- package/src/util/ids.ts +19 -0
- package/src/util/lru.ts +48 -0
- package/src/util/regex.ts +165 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
3
|
+
import type { MemoryInput, Metadata } from "../types";
|
|
4
|
+
import { BeamMemory } from "./beam/index";
|
|
5
|
+
import type { RecallEnhancedOptions, RecallOptions, RecallResult, SleepResult } from "./beam/types";
|
|
6
|
+
import { type MnemosyneEmbeddingRuntimeOptions, type MnemosyneLlmCompletion, type MnemosyneLlmRuntimeOptions, type ResolvedMnemosyneRuntimeOptions } from "./runtime-options";
|
|
7
|
+
export interface MnemosyneOptions {
|
|
8
|
+
readonly db?: Database;
|
|
9
|
+
readonly dbPath?: string;
|
|
10
|
+
readonly db_path?: string;
|
|
11
|
+
readonly sessionId?: string;
|
|
12
|
+
readonly session_id?: string;
|
|
13
|
+
readonly bank?: string | null;
|
|
14
|
+
readonly authorId?: string | null;
|
|
15
|
+
readonly author_id?: string | null;
|
|
16
|
+
readonly authorType?: string | null;
|
|
17
|
+
readonly author_type?: string | null;
|
|
18
|
+
readonly channelId?: string | null;
|
|
19
|
+
readonly channel_id?: string | null;
|
|
20
|
+
readonly noEmbeddings?: boolean;
|
|
21
|
+
readonly embeddingModel?: string;
|
|
22
|
+
readonly embeddingApiUrl?: string;
|
|
23
|
+
readonly embeddingApiKey?: string;
|
|
24
|
+
readonly embeddings?: false | MnemosyneEmbeddingRuntimeOptions;
|
|
25
|
+
readonly llmEnabled?: boolean;
|
|
26
|
+
readonly llmBaseUrl?: string;
|
|
27
|
+
readonly llmApiKey?: string;
|
|
28
|
+
readonly llmModel?: string | Model<Api>;
|
|
29
|
+
readonly llm?: false | MnemosyneLlmRuntimeOptions | Model<Api> | MnemosyneLlmCompletion;
|
|
30
|
+
}
|
|
31
|
+
export interface RememberInput extends MemoryInput {
|
|
32
|
+
readonly extract?: boolean;
|
|
33
|
+
readonly extractEntities?: boolean;
|
|
34
|
+
readonly extract_entities?: boolean;
|
|
35
|
+
readonly trustTier?: string | null;
|
|
36
|
+
readonly trust_tier?: string | null;
|
|
37
|
+
readonly memoryType?: string | null;
|
|
38
|
+
readonly memory_type?: string | null;
|
|
39
|
+
}
|
|
40
|
+
export interface RememberFacadeOptions {
|
|
41
|
+
readonly source?: string | null;
|
|
42
|
+
readonly importance?: number;
|
|
43
|
+
readonly metadata?: Metadata | null;
|
|
44
|
+
readonly validUntil?: string | Date | null;
|
|
45
|
+
readonly valid_until?: string | Date | null;
|
|
46
|
+
readonly scope?: string | null;
|
|
47
|
+
readonly extractEntities?: boolean;
|
|
48
|
+
readonly extract_entities?: boolean;
|
|
49
|
+
readonly extract?: boolean;
|
|
50
|
+
readonly trustTier?: string | null;
|
|
51
|
+
readonly trust_tier?: string | null;
|
|
52
|
+
readonly timestamp?: string | Date | null;
|
|
53
|
+
readonly veracity?: string | null;
|
|
54
|
+
readonly memoryType?: string | null;
|
|
55
|
+
readonly memory_type?: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface RecallFacadeOptions extends Omit<RecallOptions, "temporalHalflife" | "vecWeight" | "ftsWeight" | "importanceWeight"> {
|
|
58
|
+
readonly from_date?: string | null;
|
|
59
|
+
readonly to_date?: string | null;
|
|
60
|
+
readonly source?: string | null;
|
|
61
|
+
readonly topic?: string | null;
|
|
62
|
+
readonly temporalWeight?: number;
|
|
63
|
+
readonly temporal_weight?: number;
|
|
64
|
+
readonly query_time?: string | Date | null;
|
|
65
|
+
readonly temporalHalflife?: number | null;
|
|
66
|
+
readonly temporal_halflife?: number | null;
|
|
67
|
+
readonly vecWeight?: number | null;
|
|
68
|
+
readonly vec_weight?: number | null;
|
|
69
|
+
readonly ftsWeight?: number | null;
|
|
70
|
+
readonly fts_weight?: number | null;
|
|
71
|
+
readonly importanceWeight?: number | null;
|
|
72
|
+
readonly importance_weight?: number | null;
|
|
73
|
+
}
|
|
74
|
+
export interface MemoryFacadeStats {
|
|
75
|
+
total_memories: number;
|
|
76
|
+
total_sessions: number;
|
|
77
|
+
sources: Record<string, number>;
|
|
78
|
+
last_memory: string | null;
|
|
79
|
+
database: string;
|
|
80
|
+
mode: "beam";
|
|
81
|
+
banks: string[];
|
|
82
|
+
beam: {
|
|
83
|
+
working_memory: unknown;
|
|
84
|
+
episodic_memory: unknown;
|
|
85
|
+
triples: {
|
|
86
|
+
total: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
type ModuleRememberOptions = RememberFacadeOptions & {
|
|
91
|
+
readonly bank?: string | null;
|
|
92
|
+
};
|
|
93
|
+
type ModuleRecallOptions = RecallFacadeOptions & {
|
|
94
|
+
readonly bank?: string | null;
|
|
95
|
+
};
|
|
96
|
+
type ModuleRecallEnhancedOptions = RecallFacadeOptions & RecallEnhancedOptions & {
|
|
97
|
+
readonly bank?: string | null;
|
|
98
|
+
};
|
|
99
|
+
export declare class Mnemosyne {
|
|
100
|
+
#private;
|
|
101
|
+
readonly sessionId: string;
|
|
102
|
+
readonly bank: string;
|
|
103
|
+
readonly dbPath?: string;
|
|
104
|
+
readonly authorId: string | null;
|
|
105
|
+
readonly authorType: string | null;
|
|
106
|
+
readonly channelId: string;
|
|
107
|
+
readonly beam: BeamMemory;
|
|
108
|
+
readonly conn: Database;
|
|
109
|
+
readonly db: Database;
|
|
110
|
+
readonly runtimeOptions?: ResolvedMnemosyneRuntimeOptions;
|
|
111
|
+
constructor(options?: MnemosyneOptions);
|
|
112
|
+
close(): void;
|
|
113
|
+
flushExtractions(): Promise<void>;
|
|
114
|
+
remember(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
115
|
+
recall(query: string, topK?: number, options?: RecallFacadeOptions): RecallResult[];
|
|
116
|
+
recallEnhanced(query: string, topK?: number, options?: RecallFacadeOptions & RecallEnhancedOptions): RecallResult[];
|
|
117
|
+
getContext(limit?: number): unknown[];
|
|
118
|
+
getStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): MemoryFacadeStats;
|
|
119
|
+
get(memoryId: string): unknown | null;
|
|
120
|
+
forget(memoryId: string): boolean;
|
|
121
|
+
update(memoryId: string, content?: string | null, importance?: number | null): boolean;
|
|
122
|
+
sleep(dryRun?: boolean): SleepResult;
|
|
123
|
+
sleepAllSessions(dryRun?: boolean): SleepResult;
|
|
124
|
+
scratchpadWrite(content: string): string;
|
|
125
|
+
scratchpadRead(): unknown[];
|
|
126
|
+
scratchpadClear(): void;
|
|
127
|
+
addMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
128
|
+
saveMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
129
|
+
storeMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
130
|
+
search(query: string, topK?: number, options?: RecallFacadeOptions): RecallResult[];
|
|
131
|
+
query(query: string, topK?: number, options?: RecallFacadeOptions): RecallResult[];
|
|
132
|
+
consolidate(dryRun?: boolean): SleepResult;
|
|
133
|
+
}
|
|
134
|
+
export declare function setBank(bank: string): void;
|
|
135
|
+
export declare function getBank(): string;
|
|
136
|
+
export declare function getDefaultInstance(bank?: string | null): Mnemosyne;
|
|
137
|
+
export declare function remember(content: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
138
|
+
export declare function recall(query: string, topK?: number, options?: ModuleRecallOptions): RecallResult[];
|
|
139
|
+
export declare function recallEnhanced(query: string, topK?: number, options?: ModuleRecallEnhancedOptions): RecallResult[];
|
|
140
|
+
export declare function getContext(limit?: number, bank?: string | null): unknown[];
|
|
141
|
+
export declare function getStats(bank?: string | null): MemoryFacadeStats;
|
|
142
|
+
export declare function get(memoryId: string, bank?: string | null): unknown | null;
|
|
143
|
+
export declare function forget(memoryId: string, bank?: string | null): boolean;
|
|
144
|
+
export declare function update(memoryId: string, content?: string | null, importance?: number | null, bank?: string | null): boolean;
|
|
145
|
+
export declare function sleep(dryRun?: boolean, bank?: string | null): SleepResult;
|
|
146
|
+
export declare function sleepAllSessions(dryRun?: boolean, bank?: string | null): SleepResult;
|
|
147
|
+
export declare function flushExtractions(bank?: string | null): Promise<void>;
|
|
148
|
+
export declare function scratchpadWrite(content: string, bank?: string | null): string;
|
|
149
|
+
export declare function scratchpadRead(bank?: string | null): unknown[];
|
|
150
|
+
export declare function scratchpadClear(bank?: string | null): void;
|
|
151
|
+
export declare function addMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
152
|
+
export declare function saveMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
153
|
+
export declare function storeMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
154
|
+
export declare function search(query: string, topK?: number, options?: ModuleRecallOptions): RecallResult[];
|
|
155
|
+
export declare function query(query: string, topK?: number, options?: ModuleRecallOptions): RecallResult[];
|
|
156
|
+
export declare function resetDefaultInstanceForTests(): void;
|
|
157
|
+
export declare function resetMemoryForTests(): void;
|
|
158
|
+
export declare function resetModuleStateForTests(): void;
|
|
159
|
+
export type { MemoryInput, MemoryStats } from "../types";
|
|
160
|
+
export default Mnemosyne;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { type DatabasePath } from "../../db";
|
|
3
|
+
export declare const ANNOTATION_KINDS: readonly ["mentions", "fact", "occurred_on", "has_source"];
|
|
4
|
+
export type AnnotationKind = (typeof ANNOTATION_KINDS)[number];
|
|
5
|
+
export interface MigrationOptions {
|
|
6
|
+
readonly dbPath: DatabasePath;
|
|
7
|
+
readonly dryRun?: boolean;
|
|
8
|
+
readonly backup?: boolean;
|
|
9
|
+
readonly logFn?: (line: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface PendingConnection {
|
|
12
|
+
query<T = unknown>(sql: string): {
|
|
13
|
+
get(...params: unknown[]): T | null;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function hasPendingMigration(db: Database): boolean;
|
|
17
|
+
export declare function migrate(dbPathOrOptions: DatabasePath | MigrationOptions, dryRun?: boolean, backup?: boolean, logFn?: (line: string) => void): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./e6-triplestore-split";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface MmrResult {
|
|
2
|
+
readonly content?: string;
|
|
3
|
+
readonly score?: number;
|
|
4
|
+
readonly [key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export type SimilarityFn = (textA: string, textB: string) => number;
|
|
7
|
+
export declare function jaccardSimilarity(textA: string, textB: string): number;
|
|
8
|
+
export declare function mmrRerank<T extends MmrResult>(results: readonly T[], lambdaParam?: number, topK?: number, similarityFn?: SimilarityFn): T[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BeamMemoryState, RecallOptions, RecallResult } from "./beam/types";
|
|
2
|
+
import { type PolyphonicMemoryResult, type PolyphonicRecallOptions } from "./polyphonic-recall";
|
|
3
|
+
export interface OrchestratorBeam extends BeamMemoryState {
|
|
4
|
+
recall?: (query: string, topK?: number, options?: RecallOptions) => RecallResult[];
|
|
5
|
+
recallEnhanced?: (query: string, topK?: number, options?: RecallOptions) => RecallResult[];
|
|
6
|
+
}
|
|
7
|
+
export interface OrchestrateRecallOptions extends Omit<RecallOptions, "queryEmbedding">, Omit<PolyphonicRecallOptions, "queryEmbedding"> {
|
|
8
|
+
readonly queryEmbedding?: readonly number[] | Float32Array | null;
|
|
9
|
+
readonly enhanced?: boolean;
|
|
10
|
+
readonly forcePolyphonic?: boolean;
|
|
11
|
+
readonly forceLinear?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface OrchestratedRecallResult extends Omit<RecallResult, "metadata" | "score" | "tier"> {
|
|
14
|
+
score?: number;
|
|
15
|
+
metadata?: RecallResult["metadata"];
|
|
16
|
+
tier?: RecallResult["tier"] | PolyphonicMemoryResult["tier"];
|
|
17
|
+
combined_score?: PolyphonicMemoryResult["combined_score"];
|
|
18
|
+
voice_scores?: PolyphonicMemoryResult["voice_scores"];
|
|
19
|
+
}
|
|
20
|
+
export declare function orchestrateRecall(beam: OrchestratorBeam, query: string, topK?: number, options?: OrchestrateRecallOptions): OrchestratedRecallResult[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface CompressionStatsInit {
|
|
2
|
+
readonly originalSize?: number;
|
|
3
|
+
readonly compressedSize?: number;
|
|
4
|
+
readonly ratio?: number;
|
|
5
|
+
readonly method?: string;
|
|
6
|
+
readonly patternsFound?: number;
|
|
7
|
+
readonly memoriesCompressed?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class CompressionStats {
|
|
10
|
+
originalSize: number;
|
|
11
|
+
compressedSize: number;
|
|
12
|
+
ratio: number;
|
|
13
|
+
method: string;
|
|
14
|
+
patternsFound: number;
|
|
15
|
+
memoriesCompressed: number;
|
|
16
|
+
constructor(init?: CompressionStatsInit);
|
|
17
|
+
get savingsPercent(): number;
|
|
18
|
+
}
|
|
19
|
+
export type MemoryRecord = Record<string, unknown> & {
|
|
20
|
+
content?: string;
|
|
21
|
+
timestamp?: string;
|
|
22
|
+
created_at?: string;
|
|
23
|
+
source?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class MemoryCompressor {
|
|
26
|
+
readonly dictionary: Readonly<Record<string, string>>;
|
|
27
|
+
constructor(dictionary?: Readonly<Record<string, string>>);
|
|
28
|
+
static buildDefaultDict(): Record<string, string>;
|
|
29
|
+
compress(content: string, method?: string): readonly [string, CompressionStats];
|
|
30
|
+
private dictCompress;
|
|
31
|
+
private rleCompress;
|
|
32
|
+
private semanticCompressSingle;
|
|
33
|
+
compressBatch(memories: readonly MemoryRecord[], method?: string): readonly [MemoryRecord[], CompressionStats];
|
|
34
|
+
decompress(content: string, method?: string): string;
|
|
35
|
+
}
|
|
36
|
+
export interface DetectedPatternInit {
|
|
37
|
+
readonly patternType?: string;
|
|
38
|
+
readonly pattern_type?: string;
|
|
39
|
+
readonly description: string;
|
|
40
|
+
readonly confidence: number;
|
|
41
|
+
readonly samples?: readonly string[];
|
|
42
|
+
readonly metadata?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
export declare class DetectedPattern {
|
|
45
|
+
patternType: string;
|
|
46
|
+
description: string;
|
|
47
|
+
confidence: number;
|
|
48
|
+
samples: string[];
|
|
49
|
+
metadata: Record<string, unknown>;
|
|
50
|
+
constructor(init: DetectedPatternInit);
|
|
51
|
+
toDict(): Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
export declare class PatternDetector {
|
|
54
|
+
readonly minConfidence: number;
|
|
55
|
+
constructor(minConfidence?: number);
|
|
56
|
+
detectTemporal(memories: readonly MemoryRecord[]): DetectedPattern[];
|
|
57
|
+
detectContent(memories: readonly MemoryRecord[]): DetectedPattern[];
|
|
58
|
+
detectSequence(memories: readonly MemoryRecord[]): DetectedPattern[];
|
|
59
|
+
detectAll(memories: readonly MemoryRecord[]): DetectedPattern[];
|
|
60
|
+
summarizePatterns(memories: readonly MemoryRecord[]): Record<string, unknown>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export declare const DEFAULT_PLUGIN_DIR: string;
|
|
2
|
+
export type PluginConfig = Record<string, unknown>;
|
|
3
|
+
export type MemoryDict = Record<string, unknown>;
|
|
4
|
+
export declare class MnemosynePlugin {
|
|
5
|
+
static readonly abstractBase = true;
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
protected initialized: boolean;
|
|
10
|
+
readonly config: PluginConfig;
|
|
11
|
+
constructor(config?: PluginConfig);
|
|
12
|
+
initialize(): void;
|
|
13
|
+
shutdown(): void;
|
|
14
|
+
onRemember(_memory: MemoryDict): void;
|
|
15
|
+
onRecall(_memory: MemoryDict): void;
|
|
16
|
+
onConsolidate(_summary: MemoryDict): void;
|
|
17
|
+
onInvalidate(_memoryId: string): void;
|
|
18
|
+
toDict(): Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export declare class LoggingPlugin extends MnemosynePlugin {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
private readonly memoryLog;
|
|
24
|
+
private readonly maxEntries;
|
|
25
|
+
constructor(config?: PluginConfig);
|
|
26
|
+
private append;
|
|
27
|
+
onRemember(memory: MemoryDict): void;
|
|
28
|
+
onRecall(memory: MemoryDict): void;
|
|
29
|
+
onConsolidate(summary: MemoryDict): void;
|
|
30
|
+
onInvalidate(memoryId: string): void;
|
|
31
|
+
getLog(): MemoryDict[];
|
|
32
|
+
clearLog(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class MetricsPlugin extends MnemosynePlugin {
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
37
|
+
private readonly counters;
|
|
38
|
+
private readonly timings;
|
|
39
|
+
private readonly maxTimingSamples;
|
|
40
|
+
constructor(config?: PluginConfig);
|
|
41
|
+
onRemember(_memory: MemoryDict): void;
|
|
42
|
+
onRecall(_memory: MemoryDict): void;
|
|
43
|
+
onConsolidate(_summary: MemoryDict): void;
|
|
44
|
+
onInvalidate(_memoryId: string): void;
|
|
45
|
+
recordTiming(event: string, durationMs: number): void;
|
|
46
|
+
getCounters(): Record<string, number>;
|
|
47
|
+
getTimings(event: string): number[];
|
|
48
|
+
getAverageTiming(event: string): number | null;
|
|
49
|
+
reset(): void;
|
|
50
|
+
getSummary(): Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
export type FilterRule = (item: MemoryDict) => boolean;
|
|
53
|
+
export declare class FilterPlugin extends MnemosynePlugin {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
private readonly rules;
|
|
57
|
+
private readonly blocked;
|
|
58
|
+
private readonly maxBlocked;
|
|
59
|
+
constructor(config?: PluginConfig);
|
|
60
|
+
addRule(rule: FilterRule): void;
|
|
61
|
+
removeRule(rule: FilterRule): void;
|
|
62
|
+
clearRules(): void;
|
|
63
|
+
onRemember(memory: MemoryDict): void;
|
|
64
|
+
onRecall(memory: MemoryDict): void;
|
|
65
|
+
onConsolidate(summary: MemoryDict): void;
|
|
66
|
+
onInvalidate(_memoryId: string): void;
|
|
67
|
+
private passes;
|
|
68
|
+
private block;
|
|
69
|
+
getBlocked(): MemoryDict[];
|
|
70
|
+
isBlocked(memoryId: string): boolean;
|
|
71
|
+
}
|
|
72
|
+
export declare class CompressionPlugin extends MnemosynePlugin {
|
|
73
|
+
name: string;
|
|
74
|
+
version: string;
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
private readonly threshold;
|
|
77
|
+
constructor(config?: PluginConfig);
|
|
78
|
+
compressLines(lines: string[]): string[];
|
|
79
|
+
onRemember(_memory: MemoryDict): void;
|
|
80
|
+
onRecall(_memory: MemoryDict): void;
|
|
81
|
+
onConsolidate(_summary: MemoryDict): void;
|
|
82
|
+
onInvalidate(_memoryId: string): void;
|
|
83
|
+
}
|
|
84
|
+
export type PluginConstructor<T extends MnemosynePlugin = MnemosynePlugin> = new (config?: PluginConfig) => T;
|
|
85
|
+
export declare class PluginManager {
|
|
86
|
+
private readonly pluginDir;
|
|
87
|
+
private readonly registry;
|
|
88
|
+
private readonly instances;
|
|
89
|
+
constructor(pluginDir?: string);
|
|
90
|
+
registerPlugin(name: string, pluginClass: PluginConstructor): void;
|
|
91
|
+
loadPlugin(name: string, config?: PluginConfig): MnemosynePlugin;
|
|
92
|
+
unloadPlugin(name: string): void;
|
|
93
|
+
listPlugins(): Array<Record<string, unknown>>;
|
|
94
|
+
getPlugin(name: string): MnemosynePlugin | null;
|
|
95
|
+
isLoaded(name: string): boolean;
|
|
96
|
+
isRegistered(name: string): boolean;
|
|
97
|
+
loadAll(configs?: Record<string, PluginConfig>): MnemosynePlugin[];
|
|
98
|
+
unloadAll(): void;
|
|
99
|
+
discoverPlugins(): string[];
|
|
100
|
+
notifyRemember(memory: MemoryDict): void;
|
|
101
|
+
notifyRecall(memory: MemoryDict): void;
|
|
102
|
+
notifyConsolidate(summary: MemoryDict): void;
|
|
103
|
+
notifyInvalidate(memoryId: string): void;
|
|
104
|
+
}
|
|
105
|
+
export declare class ValueError extends Error {
|
|
106
|
+
name: string;
|
|
107
|
+
}
|
|
108
|
+
export declare function getManager(): PluginManager;
|
|
109
|
+
export declare function resetManager(): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { type Env } from "../config";
|
|
3
|
+
import { type DatabasePath } from "../db";
|
|
4
|
+
import type { BeamMemoryState, JsonValue, Metadata, RecallResult } from "./beam/types";
|
|
5
|
+
import { EpisodicGraph } from "./episodic-graph";
|
|
6
|
+
import { VeracityConsolidator } from "./veracity-consolidation";
|
|
7
|
+
export type PolyphonicVoice = "vector" | "graph" | "fact" | "temporal";
|
|
8
|
+
export interface VoiceRecallResult {
|
|
9
|
+
readonly memoryId: string;
|
|
10
|
+
readonly score: number;
|
|
11
|
+
readonly voice: PolyphonicVoice;
|
|
12
|
+
readonly metadata: Metadata;
|
|
13
|
+
}
|
|
14
|
+
export interface PolyphonicResult {
|
|
15
|
+
readonly memoryId: string;
|
|
16
|
+
combinedScore: number;
|
|
17
|
+
readonly voiceScores: Partial<Record<PolyphonicVoice, number>>;
|
|
18
|
+
readonly metadata: Metadata;
|
|
19
|
+
}
|
|
20
|
+
export interface PolyphonicMemoryResult extends Omit<RecallResult, "metadata" | "score" | "tier"> {
|
|
21
|
+
score: number;
|
|
22
|
+
combined_score: number;
|
|
23
|
+
voice_scores: Partial<Record<PolyphonicVoice, number>>;
|
|
24
|
+
metadata: Metadata;
|
|
25
|
+
tier: "working" | "episodic";
|
|
26
|
+
}
|
|
27
|
+
export interface PolyphonicRecallOptions {
|
|
28
|
+
readonly queryEmbedding?: readonly number[] | Float32Array | null;
|
|
29
|
+
readonly contextBudget?: number;
|
|
30
|
+
}
|
|
31
|
+
interface PolyphonicEngineOptions {
|
|
32
|
+
readonly dbPath?: DatabasePath;
|
|
33
|
+
readonly db?: Database;
|
|
34
|
+
readonly graph?: EpisodicGraph;
|
|
35
|
+
readonly consolidator?: VeracityConsolidator;
|
|
36
|
+
readonly sessionId?: string | null;
|
|
37
|
+
readonly channelId?: string | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function polyphonicRecallIsEnabled(env?: Env): boolean;
|
|
40
|
+
export declare class PolyphonicRecallEngine {
|
|
41
|
+
readonly dbPath: DatabasePath;
|
|
42
|
+
readonly db: Database;
|
|
43
|
+
readonly ownsConnection: boolean;
|
|
44
|
+
readonly graph: EpisodicGraph;
|
|
45
|
+
readonly consolidator: VeracityConsolidator;
|
|
46
|
+
readonly sessionId: string;
|
|
47
|
+
readonly channelId: string | null;
|
|
48
|
+
readonly voiceWeights: Readonly<Record<PolyphonicVoice, number>>;
|
|
49
|
+
constructor(options?: PolyphonicEngineOptions);
|
|
50
|
+
recall(query: string, queryEmbedding?: readonly number[] | Float32Array | null, topK?: number, contextBudget?: number): PolyphonicMemoryResult[];
|
|
51
|
+
vectorVoice(queryEmbedding: readonly number[] | Float32Array | null): VoiceRecallResult[];
|
|
52
|
+
graphVoice(query: string): VoiceRecallResult[];
|
|
53
|
+
factVoice(query: string): VoiceRecallResult[];
|
|
54
|
+
temporalVoice(query: string): VoiceRecallResult[];
|
|
55
|
+
combineVoices(...voiceResults: readonly VoiceRecallResult[][]): Map<string, PolyphonicResult>;
|
|
56
|
+
diversityRerank(results: ReadonlyMap<string, PolyphonicResult>, topK: number): PolyphonicResult[];
|
|
57
|
+
estimateSimilarity(a: PolyphonicResult, b: PolyphonicResult): number;
|
|
58
|
+
assembleContext(results: readonly PolyphonicResult[], budget: number): PolyphonicResult[];
|
|
59
|
+
getStats(): Record<string, JsonValue>;
|
|
60
|
+
close(): void;
|
|
61
|
+
private hydrateResults;
|
|
62
|
+
private lookupMemory;
|
|
63
|
+
}
|
|
64
|
+
export declare function getPolyphonicEngine(beam: BeamMemoryState): PolyphonicRecallEngine;
|
|
65
|
+
export declare function polyphonicRecall(beam: BeamMemoryState, query: string, topK?: number, options?: PolyphonicRecallOptions): PolyphonicMemoryResult[];
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type QueryCacheResult = Record<string, unknown>;
|
|
2
|
+
export type QueryEmbedding = readonly number[];
|
|
3
|
+
export interface QueryCacheOptions {
|
|
4
|
+
readonly dbPath?: string | null;
|
|
5
|
+
readonly db_path?: string | null;
|
|
6
|
+
readonly maxSize?: number;
|
|
7
|
+
readonly max_size?: number;
|
|
8
|
+
readonly ttlSeconds?: number;
|
|
9
|
+
readonly ttl_seconds?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface QueryCacheStats {
|
|
12
|
+
readonly hits: number;
|
|
13
|
+
readonly misses: number;
|
|
14
|
+
readonly hit_rate: number;
|
|
15
|
+
readonly tier1_hits: number;
|
|
16
|
+
readonly tier2_hits: number;
|
|
17
|
+
readonly tier3_hits: number;
|
|
18
|
+
readonly tier4_hits: number;
|
|
19
|
+
readonly size: number;
|
|
20
|
+
readonly max_size: number;
|
|
21
|
+
readonly version: number;
|
|
22
|
+
}
|
|
23
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
24
|
+
export declare function isEnhancedRecallEnabled(env?: Env): boolean;
|
|
25
|
+
export declare function isQueryCacheEnabled(useCache?: boolean, env?: Env): boolean;
|
|
26
|
+
export declare class QueryCache {
|
|
27
|
+
#private;
|
|
28
|
+
readonly maxSize: number;
|
|
29
|
+
readonly ttlSeconds: number;
|
|
30
|
+
hits: number;
|
|
31
|
+
misses: number;
|
|
32
|
+
tier1Hits: number;
|
|
33
|
+
tier2Hits: number;
|
|
34
|
+
tier3Hits: number;
|
|
35
|
+
tier4Hits: number;
|
|
36
|
+
constructor(options?: QueryCacheOptions | string | null, maxSize?: number, ttlSeconds?: number);
|
|
37
|
+
invalidate(): void;
|
|
38
|
+
get(query: string, embedding?: QueryEmbedding | null): readonly QueryCacheResult[] | null;
|
|
39
|
+
put(query: string, results: readonly QueryCacheResult[], embedding?: QueryEmbedding | null): void;
|
|
40
|
+
close(): void;
|
|
41
|
+
get hitRate(): number;
|
|
42
|
+
stats(): QueryCacheStats;
|
|
43
|
+
normalize(query: string): string;
|
|
44
|
+
cosineSimilarity(embA: QueryEmbedding, embB: QueryEmbedding): number;
|
|
45
|
+
jaccardWords(queryA: string, queryB: string): number;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type QueryIntentCategory = "temporal" | "factual" | "entity" | "preference" | "procedural" | "general";
|
|
2
|
+
export interface QueryIntent {
|
|
3
|
+
readonly category: QueryIntentCategory;
|
|
4
|
+
readonly confidence: number;
|
|
5
|
+
readonly signals: QueryIntentCategory[];
|
|
6
|
+
readonly vec_bias: number;
|
|
7
|
+
readonly fts_bias: number;
|
|
8
|
+
readonly importance_bias: number;
|
|
9
|
+
}
|
|
10
|
+
export interface IntentWeights {
|
|
11
|
+
readonly vec_bias: number;
|
|
12
|
+
readonly fts_bias: number;
|
|
13
|
+
readonly importance_bias: number;
|
|
14
|
+
}
|
|
15
|
+
type IntentPatternGroup = readonly [QueryIntentCategory, readonly RegExp[]];
|
|
16
|
+
export declare const INTENT_PATTERNS: readonly IntentPatternGroup[];
|
|
17
|
+
export declare const INTENT_WEIGHTS: Record<QueryIntentCategory, IntentWeights>;
|
|
18
|
+
export declare function classifyIntent(query: string): QueryIntent;
|
|
19
|
+
export declare function adjustWeights(baseVec?: number, baseFts?: number, baseImportance?: number, intent?: QueryIntent | null): [number, number, number];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const RECALL_TIERS: readonly ["wm_fts", "wm_vec", "wm_fallback", "em_fts", "em_vec", "em_fallback"];
|
|
2
|
+
export type RecallTier = (typeof RECALL_TIERS)[number];
|
|
3
|
+
export interface TierStatsSnapshot {
|
|
4
|
+
readonly calls_with_hits: number;
|
|
5
|
+
readonly total_hits: number;
|
|
6
|
+
}
|
|
7
|
+
export interface RecallDiagnosticsSnapshot {
|
|
8
|
+
readonly created_at: string;
|
|
9
|
+
readonly snapshot_at: string;
|
|
10
|
+
readonly totals: {
|
|
11
|
+
readonly calls: number;
|
|
12
|
+
readonly calls_using_wm_fallback: number;
|
|
13
|
+
readonly calls_using_em_fallback: number;
|
|
14
|
+
readonly calls_truly_empty: number;
|
|
15
|
+
readonly wm_fallback_rate: number;
|
|
16
|
+
readonly em_fallback_rate: number;
|
|
17
|
+
};
|
|
18
|
+
readonly by_tier: Record<RecallTier, TierStatsSnapshot>;
|
|
19
|
+
}
|
|
20
|
+
export declare class RecallDiagnostics {
|
|
21
|
+
private tierStats;
|
|
22
|
+
private totalCalls;
|
|
23
|
+
private callsUsingWmFallback;
|
|
24
|
+
private callsUsingEmFallback;
|
|
25
|
+
private callsTrulyEmpty;
|
|
26
|
+
private createdAt;
|
|
27
|
+
constructor();
|
|
28
|
+
private static validateTier;
|
|
29
|
+
recordTierHits(tier: RecallTier | string, hitCount: number): void;
|
|
30
|
+
recordFallbackUsed(options?: {
|
|
31
|
+
readonly wm?: boolean;
|
|
32
|
+
readonly em?: boolean;
|
|
33
|
+
}): void;
|
|
34
|
+
recordCall(options?: {
|
|
35
|
+
readonly trulyEmpty?: boolean;
|
|
36
|
+
readonly truly_empty?: boolean;
|
|
37
|
+
}): void;
|
|
38
|
+
fallbackRate(): {
|
|
39
|
+
readonly wm: number;
|
|
40
|
+
readonly em: number;
|
|
41
|
+
};
|
|
42
|
+
snapshot(): RecallDiagnosticsSnapshot;
|
|
43
|
+
reset(): void;
|
|
44
|
+
}
|
|
45
|
+
export declare function getDiagnostics(): RecallDiagnostics;
|
|
46
|
+
export declare function getRecallDiagnostics(): RecallDiagnosticsSnapshot;
|
|
47
|
+
export declare function resetRecallDiagnostics(): void;
|
|
48
|
+
export declare function explainRecallDiagnostics(snapshot: RecallDiagnosticsSnapshot): string[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
2
|
+
export interface MnemosyneLlmCompleteOptions {
|
|
3
|
+
maxTokens?: number;
|
|
4
|
+
temperature?: number;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
provider?: string | null;
|
|
7
|
+
model?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export type MnemosyneLlmCompletion = (prompt: string, opts?: MnemosyneLlmCompleteOptions) => string | null | Promise<string | null>;
|
|
10
|
+
export interface MnemosyneEmbeddingProvider {
|
|
11
|
+
embed(texts: readonly string[]): unknown | Promise<unknown>;
|
|
12
|
+
available?(): boolean | Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
export interface MnemosyneEmbeddingRuntimeOptions {
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
model?: string;
|
|
17
|
+
apiUrl?: string;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
provider?: MnemosyneEmbeddingProvider | ((texts: readonly string[]) => unknown | Promise<unknown>);
|
|
20
|
+
}
|
|
21
|
+
export interface MnemosyneLlmRuntimeOptions {
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
model?: string | Model<Api>;
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
complete?: MnemosyneLlmCompletion;
|
|
28
|
+
/** Override the fact-extraction prompt template ({text}/{lang}). Used to feed small local models a friendlier format. */
|
|
29
|
+
extractionPrompt?: string;
|
|
30
|
+
/** Override the consolidation/sleep prompt template ({memories}/{source}/{memory_count}). */
|
|
31
|
+
consolidationPrompt?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface MnemosyneRuntimeOptions {
|
|
34
|
+
embeddings?: false | MnemosyneEmbeddingRuntimeOptions;
|
|
35
|
+
llm?: false | MnemosyneLlmRuntimeOptions | Model<Api> | MnemosyneLlmCompletion;
|
|
36
|
+
}
|
|
37
|
+
export interface ResolvedMnemosyneEmbeddingRuntimeOptions {
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
model?: string;
|
|
40
|
+
apiUrl?: string;
|
|
41
|
+
apiKey?: string;
|
|
42
|
+
provider?: MnemosyneEmbeddingProvider;
|
|
43
|
+
}
|
|
44
|
+
export interface ResolvedMnemosyneLlmRuntimeOptions {
|
|
45
|
+
enabled?: boolean;
|
|
46
|
+
baseUrl?: string;
|
|
47
|
+
apiKey?: string;
|
|
48
|
+
model?: string | Model<Api>;
|
|
49
|
+
maxTokens?: number;
|
|
50
|
+
complete?: MnemosyneLlmCompletion;
|
|
51
|
+
extractionPrompt?: string;
|
|
52
|
+
consolidationPrompt?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ResolvedMnemosyneRuntimeOptions {
|
|
55
|
+
embeddings?: ResolvedMnemosyneEmbeddingRuntimeOptions;
|
|
56
|
+
llm?: ResolvedMnemosyneLlmRuntimeOptions;
|
|
57
|
+
}
|
|
58
|
+
export declare function withMnemosyneRuntimeOptions<T>(options: ResolvedMnemosyneRuntimeOptions | undefined, fn: () => T): T;
|
|
59
|
+
export declare function getMnemosyneRuntimeOptions(): ResolvedMnemosyneRuntimeOptions | undefined;
|
|
60
|
+
export declare function resolveEmbeddingProvider(provider: MnemosyneEmbeddingProvider | ((texts: readonly string[]) => unknown | Promise<unknown>) | undefined): MnemosyneEmbeddingProvider | undefined;
|
|
61
|
+
export declare function isPiAiModel(value: unknown): value is Model<Api>;
|