@yamo/memory-mesh 3.0.0 → 3.0.1
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 +8 -2
- package/lib/llm/client.d.ts +23 -48
- package/lib/llm/client.js +1 -0
- package/lib/llm/client.ts +298 -377
- package/lib/llm/index.js +1 -0
- package/lib/llm/index.ts +1 -2
- package/lib/memory/adapters/client.d.ts +22 -85
- package/lib/memory/adapters/client.js +1 -0
- package/lib/memory/adapters/client.ts +474 -633
- package/lib/memory/adapters/config.d.ts +82 -89
- package/lib/memory/adapters/config.js +1 -0
- package/lib/memory/adapters/config.ts +156 -225
- package/lib/memory/adapters/errors.d.ts +28 -20
- package/lib/memory/adapters/errors.js +1 -0
- package/lib/memory/adapters/errors.ts +83 -120
- package/lib/memory/context-manager.d.ts +15 -18
- package/lib/memory/context-manager.js +1 -0
- package/lib/memory/context-manager.ts +314 -401
- package/lib/memory/embeddings/factory.d.ts +18 -20
- package/lib/memory/embeddings/factory.js +1 -0
- package/lib/memory/embeddings/factory.ts +130 -173
- package/lib/memory/embeddings/index.js +1 -0
- package/lib/memory/embeddings/index.ts +1 -0
- package/lib/memory/embeddings/service.d.ts +36 -66
- package/lib/memory/embeddings/service.js +1 -0
- package/lib/memory/embeddings/service.ts +479 -616
- package/lib/memory/index.d.ts +2 -2
- package/lib/memory/index.js +1 -0
- package/lib/memory/index.ts +3 -13
- package/lib/memory/memory-mesh.d.ts +151 -93
- package/lib/memory/memory-mesh.js +1 -0
- package/lib/memory/memory-mesh.ts +1406 -1692
- package/lib/memory/memory-translator.d.ts +1 -6
- package/lib/memory/memory-translator.js +1 -0
- package/lib/memory/memory-translator.ts +96 -128
- package/lib/memory/schema.d.ts +29 -10
- package/lib/memory/schema.js +1 -0
- package/lib/memory/schema.ts +102 -185
- package/lib/memory/scorer.d.ts +3 -4
- package/lib/memory/scorer.js +1 -0
- package/lib/memory/scorer.ts +69 -86
- package/lib/memory/search/index.js +1 -0
- package/lib/memory/search/index.ts +1 -0
- package/lib/memory/search/keyword-search.d.ts +10 -26
- package/lib/memory/search/keyword-search.js +1 -0
- package/lib/memory/search/keyword-search.ts +123 -161
- package/lib/scrubber/config/defaults.d.ts +39 -46
- package/lib/scrubber/config/defaults.js +1 -0
- package/lib/scrubber/config/defaults.ts +50 -112
- package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
- package/lib/scrubber/errors/scrubber-error.js +39 -0
- package/lib/scrubber/errors/scrubber-error.ts +44 -0
- package/lib/scrubber/index.d.ts +0 -1
- package/lib/scrubber/index.js +1 -0
- package/lib/scrubber/index.ts +1 -2
- package/lib/scrubber/scrubber.d.ts +14 -31
- package/lib/scrubber/scrubber.js +1 -0
- package/lib/scrubber/scrubber.ts +93 -152
- package/lib/scrubber/stages/chunker.d.ts +22 -10
- package/lib/scrubber/stages/chunker.js +86 -0
- package/lib/scrubber/stages/chunker.ts +104 -0
- package/lib/scrubber/stages/metadata-annotator.d.ts +14 -15
- package/lib/scrubber/stages/metadata-annotator.js +64 -0
- package/lib/scrubber/stages/metadata-annotator.ts +75 -0
- package/lib/scrubber/stages/normalizer.d.ts +13 -10
- package/lib/scrubber/stages/normalizer.js +51 -0
- package/lib/scrubber/stages/normalizer.ts +60 -0
- package/lib/scrubber/stages/semantic-filter.d.ts +13 -10
- package/lib/scrubber/stages/semantic-filter.js +51 -0
- package/lib/scrubber/stages/semantic-filter.ts +62 -0
- package/lib/scrubber/stages/structural-cleaner.d.ts +15 -10
- package/lib/scrubber/stages/structural-cleaner.js +73 -0
- package/lib/scrubber/stages/structural-cleaner.ts +83 -0
- package/lib/scrubber/stages/validator.d.ts +14 -15
- package/lib/scrubber/stages/validator.js +56 -0
- package/lib/scrubber/stages/validator.ts +67 -0
- package/lib/scrubber/telemetry.d.ts +20 -27
- package/lib/scrubber/telemetry.js +1 -0
- package/lib/scrubber/telemetry.ts +53 -90
- package/lib/scrubber/utils/hash.d.ts +14 -0
- package/lib/scrubber/utils/hash.js +37 -0
- package/lib/scrubber/utils/hash.ts +40 -0
- package/lib/scrubber/utils/html-parser.d.ts +14 -0
- package/lib/scrubber/utils/html-parser.js +38 -0
- package/lib/scrubber/utils/html-parser.ts +46 -0
- package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
- package/lib/scrubber/utils/pattern-matcher.js +54 -0
- package/lib/scrubber/utils/pattern-matcher.ts +64 -0
- package/lib/scrubber/utils/token-counter.d.ts +18 -0
- package/lib/scrubber/utils/token-counter.js +30 -0
- package/lib/scrubber/utils/token-counter.ts +32 -0
- package/lib/utils/logger.d.ts +1 -11
- package/lib/utils/logger.js +1 -0
- package/lib/utils/logger.ts +43 -63
- package/lib/utils/skill-metadata.d.ts +6 -14
- package/lib/utils/skill-metadata.js +1 -0
- package/lib/utils/skill-metadata.ts +89 -103
- package/lib/yamo/emitter.d.ts +8 -35
- package/lib/yamo/emitter.js +1 -0
- package/lib/yamo/emitter.ts +77 -155
- package/lib/yamo/index.d.ts +14 -0
- package/lib/yamo/index.js +14 -0
- package/lib/yamo/index.ts +16 -0
- package/lib/yamo/schema.d.ts +8 -10
- package/lib/yamo/schema.js +1 -0
- package/lib/yamo/schema.ts +82 -114
- package/package.json +4 -2
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LanceDB Configuration Loader
|
|
3
|
-
* Loads and validates configuration from environment variables
|
|
4
|
-
*/
|
|
5
1
|
/**
|
|
6
2
|
* Default configuration values
|
|
7
3
|
*/
|
|
8
4
|
export declare const DEFAULTS: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
LANCEDB_URI: string;
|
|
6
|
+
LANCEDB_MEMORY_TABLE: string;
|
|
7
|
+
LANCEDB_MAX_CACHE_SIZE: string;
|
|
8
|
+
EMBEDDING_MODEL_TYPE: string;
|
|
9
|
+
EMBEDDING_MODEL_NAME: string;
|
|
10
|
+
EMBEDDING_DIMENSION: string;
|
|
11
|
+
EMBEDDING_BATCH_SIZE: string;
|
|
12
|
+
EMBEDDING_NORMALIZE: string;
|
|
13
|
+
OPENAI_EMBEDDING_MODEL: string;
|
|
14
|
+
DEFAULT_TOP_K: string;
|
|
15
|
+
DEFAULT_SIMILARITY_THRESHOLD: string;
|
|
16
|
+
ENABLE_HYBRID_SEARCH: string;
|
|
17
|
+
HYBRID_SEARCH_ALPHA: string;
|
|
18
|
+
VECTOR_INDEX_TYPE: string;
|
|
19
|
+
IVF_PARTITIONS: string;
|
|
20
|
+
PQ_BITS: string;
|
|
21
|
+
ENABLE_QUERY_CACHE: string;
|
|
22
|
+
QUERY_CACHE_TTL: string;
|
|
27
23
|
};
|
|
28
|
-
export type ConfigKey = keyof typeof DEFAULTS;
|
|
29
|
-
export type Config = Record<ConfigKey, string>;
|
|
30
24
|
/**
|
|
31
25
|
* Memory system configuration defaults
|
|
32
26
|
*/
|
|
33
27
|
export declare const MEMORY_DEFAULTS: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
28
|
+
MEMORY_ENABLED: string;
|
|
29
|
+
MEMORY_AUTO_CAPTURE: string;
|
|
30
|
+
MEMORY_AUTO_RECALL: string;
|
|
31
|
+
MEMORY_MAX_CONTEXT: string;
|
|
32
|
+
MEMORY_RELEVANCE_THRESHOLD: string;
|
|
33
|
+
MEMORY_IMPORTANCE_BOOST: string;
|
|
34
|
+
MEMORY_RECENCY_WEIGHT: string;
|
|
35
|
+
MEMORY_MIN_IMPORTANCE: string;
|
|
36
|
+
MEMORY_DEDUP_THRESHOLD: string;
|
|
37
|
+
MEMORY_CAPTURE_TOOL_RESULTS: string;
|
|
38
|
+
MEMORY_CAPTURE_FILE_OPS: string;
|
|
39
|
+
MEMORY_RETENTION_ENABLED: string;
|
|
40
|
+
MEMORY_RETENTION_DAYS: string;
|
|
41
|
+
MEMORY_MAX_PER_SESSION: string;
|
|
42
|
+
MEMORY_MIN_IMPORTANCE_TO_KEEP: string;
|
|
43
|
+
MEMORY_REDACT_PII: string;
|
|
44
|
+
MEMORY_ENCRYPTION_ENABLED: string;
|
|
51
45
|
};
|
|
52
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Load configuration with validation
|
|
48
|
+
*/
|
|
49
|
+
export declare function loadConfig(): {};
|
|
50
|
+
/**
|
|
51
|
+
* Load memory-specific configuration
|
|
52
|
+
* @returns {Object} Memory configuration object
|
|
53
|
+
*/
|
|
54
|
+
export declare function loadMemoryConfig(): {
|
|
53
55
|
enabled: boolean;
|
|
54
56
|
autoCapture: boolean;
|
|
55
57
|
autoRecall: boolean;
|
|
@@ -71,67 +73,58 @@ export interface MemoryConfig {
|
|
|
71
73
|
redactPii: boolean;
|
|
72
74
|
encryptionEnabled: boolean;
|
|
73
75
|
};
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Load configuration with validation
|
|
77
|
-
*/
|
|
78
|
-
export declare function loadConfig(): Config;
|
|
79
|
-
/**
|
|
80
|
-
* Load memory-specific configuration
|
|
81
|
-
* @returns {Object} Memory configuration object
|
|
82
|
-
*/
|
|
83
|
-
export declare function loadMemoryConfig(): MemoryConfig;
|
|
76
|
+
};
|
|
84
77
|
/**
|
|
85
78
|
* Validate configuration
|
|
86
79
|
*/
|
|
87
|
-
export declare function validateConfig(config:
|
|
80
|
+
export declare function validateConfig(config: any): any[];
|
|
88
81
|
/**
|
|
89
82
|
* Get validated configuration
|
|
90
83
|
*/
|
|
91
|
-
export declare function getConfig():
|
|
84
|
+
export declare function getConfig(): {};
|
|
92
85
|
declare const _default: {
|
|
93
86
|
loadConfig: typeof loadConfig;
|
|
94
87
|
validateConfig: typeof validateConfig;
|
|
95
88
|
getConfig: typeof getConfig;
|
|
96
89
|
loadMemoryConfig: typeof loadMemoryConfig;
|
|
97
90
|
DEFAULTS: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
LANCEDB_URI: string;
|
|
92
|
+
LANCEDB_MEMORY_TABLE: string;
|
|
93
|
+
LANCEDB_MAX_CACHE_SIZE: string;
|
|
94
|
+
EMBEDDING_MODEL_TYPE: string;
|
|
95
|
+
EMBEDDING_MODEL_NAME: string;
|
|
96
|
+
EMBEDDING_DIMENSION: string;
|
|
97
|
+
EMBEDDING_BATCH_SIZE: string;
|
|
98
|
+
EMBEDDING_NORMALIZE: string;
|
|
99
|
+
OPENAI_EMBEDDING_MODEL: string;
|
|
100
|
+
DEFAULT_TOP_K: string;
|
|
101
|
+
DEFAULT_SIMILARITY_THRESHOLD: string;
|
|
102
|
+
ENABLE_HYBRID_SEARCH: string;
|
|
103
|
+
HYBRID_SEARCH_ALPHA: string;
|
|
104
|
+
VECTOR_INDEX_TYPE: string;
|
|
105
|
+
IVF_PARTITIONS: string;
|
|
106
|
+
PQ_BITS: string;
|
|
107
|
+
ENABLE_QUERY_CACHE: string;
|
|
108
|
+
QUERY_CACHE_TTL: string;
|
|
116
109
|
};
|
|
117
110
|
MEMORY_DEFAULTS: {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
111
|
+
MEMORY_ENABLED: string;
|
|
112
|
+
MEMORY_AUTO_CAPTURE: string;
|
|
113
|
+
MEMORY_AUTO_RECALL: string;
|
|
114
|
+
MEMORY_MAX_CONTEXT: string;
|
|
115
|
+
MEMORY_RELEVANCE_THRESHOLD: string;
|
|
116
|
+
MEMORY_IMPORTANCE_BOOST: string;
|
|
117
|
+
MEMORY_RECENCY_WEIGHT: string;
|
|
118
|
+
MEMORY_MIN_IMPORTANCE: string;
|
|
119
|
+
MEMORY_DEDUP_THRESHOLD: string;
|
|
120
|
+
MEMORY_CAPTURE_TOOL_RESULTS: string;
|
|
121
|
+
MEMORY_CAPTURE_FILE_OPS: string;
|
|
122
|
+
MEMORY_RETENTION_ENABLED: string;
|
|
123
|
+
MEMORY_RETENTION_DAYS: string;
|
|
124
|
+
MEMORY_MAX_PER_SESSION: string;
|
|
125
|
+
MEMORY_MIN_IMPORTANCE_TO_KEEP: string;
|
|
126
|
+
MEMORY_REDACT_PII: string;
|
|
127
|
+
MEMORY_ENCRYPTION_ENABLED: string;
|
|
135
128
|
};
|
|
136
129
|
};
|
|
137
130
|
export default _default;
|
|
@@ -1,259 +1,190 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* LanceDB Configuration Loader
|
|
3
4
|
* Loads and validates configuration from environment variables
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
6
|
import path from "path";
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Default configuration values
|
|
10
9
|
*/
|
|
11
10
|
export const DEFAULTS = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
PQ_BITS: "8",
|
|
37
|
-
ENABLE_QUERY_CACHE: "true",
|
|
38
|
-
QUERY_CACHE_TTL: "300",
|
|
39
|
-
} as const;
|
|
40
|
-
|
|
41
|
-
export type ConfigKey = keyof typeof DEFAULTS;
|
|
42
|
-
export type Config = Record<ConfigKey, string>;
|
|
43
|
-
|
|
11
|
+
// LanceDB Configuration
|
|
12
|
+
LANCEDB_URI: "./runtime/data/lancedb",
|
|
13
|
+
LANCEDB_MEMORY_TABLE: "memory_entries",
|
|
14
|
+
LANCEDB_MAX_CACHE_SIZE: "2GB",
|
|
15
|
+
// Embedding Model Configuration
|
|
16
|
+
EMBEDDING_MODEL_TYPE: "local",
|
|
17
|
+
EMBEDDING_MODEL_NAME: "Xenova/all-MiniLM-L6-v2",
|
|
18
|
+
EMBEDDING_DIMENSION: "384",
|
|
19
|
+
EMBEDDING_BATCH_SIZE: "32",
|
|
20
|
+
EMBEDDING_NORMALIZE: "true",
|
|
21
|
+
// API-based Embeddings
|
|
22
|
+
OPENAI_EMBEDDING_MODEL: "text-embedding-3-small",
|
|
23
|
+
// Search Configuration
|
|
24
|
+
DEFAULT_TOP_K: "10",
|
|
25
|
+
DEFAULT_SIMILARITY_THRESHOLD: "0.7",
|
|
26
|
+
ENABLE_HYBRID_SEARCH: "true",
|
|
27
|
+
HYBRID_SEARCH_ALPHA: "0.5",
|
|
28
|
+
// Performance Tuning
|
|
29
|
+
VECTOR_INDEX_TYPE: "ivf_pq",
|
|
30
|
+
IVF_PARTITIONS: "256",
|
|
31
|
+
PQ_BITS: "8",
|
|
32
|
+
ENABLE_QUERY_CACHE: "true",
|
|
33
|
+
QUERY_CACHE_TTL: "300",
|
|
34
|
+
};
|
|
44
35
|
/**
|
|
45
36
|
* Memory system configuration defaults
|
|
46
37
|
*/
|
|
47
38
|
export const MEMORY_DEFAULTS = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// Privacy settings
|
|
72
|
-
MEMORY_REDACT_PII: "false",
|
|
73
|
-
MEMORY_ENCRYPTION_ENABLED: "false",
|
|
74
|
-
} as const;
|
|
75
|
-
|
|
76
|
-
export interface MemoryConfig {
|
|
77
|
-
enabled: boolean;
|
|
78
|
-
autoCapture: boolean;
|
|
79
|
-
autoRecall: boolean;
|
|
80
|
-
maxContext: number;
|
|
81
|
-
relevanceThreshold: number;
|
|
82
|
-
importanceBoost: number;
|
|
83
|
-
recencyWeight: number;
|
|
84
|
-
minImportance: number;
|
|
85
|
-
dedupThreshold: number;
|
|
86
|
-
captureToolResults: boolean;
|
|
87
|
-
captureFileOps: boolean;
|
|
88
|
-
retention: {
|
|
89
|
-
enabled: boolean;
|
|
90
|
-
days: number;
|
|
91
|
-
maxPerSession: number;
|
|
92
|
-
minImportanceToKeep: number;
|
|
93
|
-
};
|
|
94
|
-
privacy: {
|
|
95
|
-
redactPii: boolean;
|
|
96
|
-
encryptionEnabled: boolean;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
39
|
+
// Feature flags
|
|
40
|
+
MEMORY_ENABLED: "true",
|
|
41
|
+
MEMORY_AUTO_CAPTURE: "true",
|
|
42
|
+
MEMORY_AUTO_RECALL: "true",
|
|
43
|
+
// Recall settings
|
|
44
|
+
MEMORY_MAX_CONTEXT: "5",
|
|
45
|
+
MEMORY_RELEVANCE_THRESHOLD: "0.7",
|
|
46
|
+
MEMORY_IMPORTANCE_BOOST: "1.5",
|
|
47
|
+
MEMORY_RECENCY_WEIGHT: "0.3",
|
|
48
|
+
// Capture settings
|
|
49
|
+
MEMORY_MIN_IMPORTANCE: "0.3",
|
|
50
|
+
MEMORY_DEDUP_THRESHOLD: "0.9",
|
|
51
|
+
MEMORY_CAPTURE_TOOL_RESULTS: "true",
|
|
52
|
+
MEMORY_CAPTURE_FILE_OPS: "true",
|
|
53
|
+
// Retention settings
|
|
54
|
+
MEMORY_RETENTION_ENABLED: "true",
|
|
55
|
+
MEMORY_RETENTION_DAYS: "90",
|
|
56
|
+
MEMORY_MAX_PER_SESSION: "100",
|
|
57
|
+
MEMORY_MIN_IMPORTANCE_TO_KEEP: "0.5",
|
|
58
|
+
// Privacy settings
|
|
59
|
+
MEMORY_REDACT_PII: "false",
|
|
60
|
+
MEMORY_ENCRYPTION_ENABLED: "false",
|
|
61
|
+
};
|
|
100
62
|
/**
|
|
101
63
|
* Load configuration with validation
|
|
102
64
|
*/
|
|
103
|
-
export function loadConfig()
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const packageRoot = path.resolve(
|
|
120
|
-
path.dirname(currentFilePath),
|
|
121
|
-
"../../../",
|
|
122
|
-
);
|
|
123
|
-
config.LANCEDB_URI = path.resolve(packageRoot, config.LANCEDB_URI);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return config as Config;
|
|
65
|
+
export function loadConfig() {
|
|
66
|
+
const config = {};
|
|
67
|
+
for (const [key, defaultValue] of Object.entries(DEFAULTS)) {
|
|
68
|
+
config[key] = process.env[key] || defaultValue;
|
|
69
|
+
}
|
|
70
|
+
// Resolve relative paths to absolute relative to package root
|
|
71
|
+
if (config.LANCEDB_URI &&
|
|
72
|
+
(config.LANCEDB_URI.startsWith("./") ||
|
|
73
|
+
config.LANCEDB_URI.startsWith("../"))) {
|
|
74
|
+
const currentFileUrl = import.meta.url;
|
|
75
|
+
const currentFilePath = new URL(currentFileUrl).pathname;
|
|
76
|
+
// config.ts is in lib/brain/adapters, so package root is ../../../
|
|
77
|
+
const packageRoot = path.resolve(path.dirname(currentFilePath), "../../../");
|
|
78
|
+
config.LANCEDB_URI = path.resolve(packageRoot, config.LANCEDB_URI);
|
|
79
|
+
}
|
|
80
|
+
return config;
|
|
127
81
|
}
|
|
128
|
-
|
|
129
82
|
/**
|
|
130
83
|
* Load memory-specific configuration
|
|
131
84
|
* @returns {Object} Memory configuration object
|
|
132
85
|
*/
|
|
133
|
-
export function loadMemoryConfig()
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
redactPii: process.env.MEMORY_REDACT_PII === "true",
|
|
158
|
-
encryptionEnabled: process.env.MEMORY_ENCRYPTION_ENABLED === "true",
|
|
159
|
-
},
|
|
160
|
-
};
|
|
86
|
+
export function loadMemoryConfig() {
|
|
87
|
+
return {
|
|
88
|
+
enabled: process.env.MEMORY_ENABLED !== "false",
|
|
89
|
+
autoCapture: process.env.MEMORY_AUTO_CAPTURE !== "false",
|
|
90
|
+
autoRecall: process.env.MEMORY_AUTO_RECALL !== "false",
|
|
91
|
+
maxContext: parseInt(process.env.MEMORY_MAX_CONTEXT || "5"),
|
|
92
|
+
relevanceThreshold: parseFloat(process.env.MEMORY_RELEVANCE_THRESHOLD || "0.7"),
|
|
93
|
+
importanceBoost: parseFloat(process.env.MEMORY_IMPORTANCE_BOOST || "1.5"),
|
|
94
|
+
recencyWeight: parseFloat(process.env.MEMORY_RECENCY_WEIGHT || "0.3"),
|
|
95
|
+
minImportance: parseFloat(process.env.MEMORY_MIN_IMPORTANCE || "0.3"),
|
|
96
|
+
dedupThreshold: parseFloat(process.env.MEMORY_DEDUP_THRESHOLD || "0.9"),
|
|
97
|
+
captureToolResults: process.env.MEMORY_CAPTURE_TOOL_RESULTS !== "false",
|
|
98
|
+
captureFileOps: process.env.MEMORY_CAPTURE_FILE_OPS !== "false",
|
|
99
|
+
retention: {
|
|
100
|
+
enabled: process.env.MEMORY_RETENTION_ENABLED !== "false",
|
|
101
|
+
days: parseInt(process.env.MEMORY_RETENTION_DAYS || "90"),
|
|
102
|
+
maxPerSession: parseInt(process.env.MEMORY_MAX_PER_SESSION || "100"),
|
|
103
|
+
minImportanceToKeep: parseFloat(process.env.MEMORY_MIN_IMPORTANCE_TO_KEEP || "0.5"),
|
|
104
|
+
},
|
|
105
|
+
privacy: {
|
|
106
|
+
redactPii: process.env.MEMORY_REDACT_PII === "true",
|
|
107
|
+
encryptionEnabled: process.env.MEMORY_ENCRYPTION_ENABLED === "true",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
161
110
|
}
|
|
162
|
-
|
|
163
111
|
/**
|
|
164
112
|
* Validate configuration
|
|
165
113
|
*/
|
|
166
|
-
export function validateConfig(config
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (isNaN(dimension) || dimension <= 0) {
|
|
178
|
-
errors.push(`Invalid EMBEDDING_DIMENSION: ${config.EMBEDDING_DIMENSION}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const topK = parseInt(config.DEFAULT_TOP_K);
|
|
182
|
-
if (isNaN(topK) || topK <= 0) {
|
|
183
|
-
errors.push(`Invalid DEFAULT_TOP_K: ${config.DEFAULT_TOP_K}`);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Validate boolean strings
|
|
187
|
-
const boolFields: (keyof Config)[] = [
|
|
188
|
-
"EMBEDDING_NORMALIZE",
|
|
189
|
-
"ENABLE_HYBRID_SEARCH",
|
|
190
|
-
"ENABLE_QUERY_CACHE",
|
|
191
|
-
];
|
|
192
|
-
for (const field of boolFields) {
|
|
193
|
-
const value = config[field].toLowerCase();
|
|
194
|
-
if (value !== "true" && value !== "false") {
|
|
195
|
-
errors.push(`Invalid ${field}: must be 'true' or 'false'`);
|
|
114
|
+
export function validateConfig(config) {
|
|
115
|
+
const errors = [];
|
|
116
|
+
// Validate embedding model type
|
|
117
|
+
const validModelTypes = ["local", "openai", "cohere", "voyage"];
|
|
118
|
+
if (!validModelTypes.includes(config.EMBEDDING_MODEL_TYPE)) {
|
|
119
|
+
errors.push(`Invalid EMBEDDING_MODEL_TYPE: ${config.EMBEDDING_MODEL_TYPE}`);
|
|
120
|
+
}
|
|
121
|
+
// Validate numeric values
|
|
122
|
+
const dimension = parseInt(config.EMBEDDING_DIMENSION);
|
|
123
|
+
if (isNaN(dimension) || dimension <= 0) {
|
|
124
|
+
errors.push(`Invalid EMBEDDING_DIMENSION: ${config.EMBEDDING_DIMENSION}`);
|
|
196
125
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const threshold = parseFloat(config.DEFAULT_SIMILARITY_THRESHOLD);
|
|
201
|
-
if (isNaN(threshold) || threshold < 0 || threshold > 1) {
|
|
202
|
-
errors.push(
|
|
203
|
-
`Invalid DEFAULT_SIMILARITY_THRESHOLD: must be between 0 and 1`,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Validate hybrid search alpha (0-1 range)
|
|
208
|
-
const alpha = parseFloat(config.HYBRID_SEARCH_ALPHA);
|
|
209
|
-
if (isNaN(alpha) || alpha < 0 || alpha > 1) {
|
|
210
|
-
errors.push(`Invalid HYBRID_SEARCH_ALPHA: must be between 0 and 1`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Validate positive integers
|
|
214
|
-
const positiveIntFields: (keyof Config)[] = [
|
|
215
|
-
"EMBEDDING_BATCH_SIZE",
|
|
216
|
-
"IVF_PARTITIONS",
|
|
217
|
-
"PQ_BITS",
|
|
218
|
-
"QUERY_CACHE_TTL",
|
|
219
|
-
];
|
|
220
|
-
for (const field of positiveIntFields) {
|
|
221
|
-
const value = parseInt(config[field]);
|
|
222
|
-
if (isNaN(value) || value <= 0) {
|
|
223
|
-
errors.push(`Invalid ${field}: must be a positive integer`);
|
|
126
|
+
const topK = parseInt(config.DEFAULT_TOP_K);
|
|
127
|
+
if (isNaN(topK) || topK <= 0) {
|
|
128
|
+
errors.push(`Invalid DEFAULT_TOP_K: ${config.DEFAULT_TOP_K}`);
|
|
224
129
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
130
|
+
// Validate boolean strings
|
|
131
|
+
const boolFields = [
|
|
132
|
+
"EMBEDDING_NORMALIZE",
|
|
133
|
+
"ENABLE_HYBRID_SEARCH",
|
|
134
|
+
"ENABLE_QUERY_CACHE",
|
|
135
|
+
];
|
|
136
|
+
for (const field of boolFields) {
|
|
137
|
+
const value = config[field].toLowerCase();
|
|
138
|
+
if (value !== "true" && value !== "false") {
|
|
139
|
+
errors.push(`Invalid ${field}: must be 'true' or 'false'`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Validate similarity threshold (0-1 range)
|
|
143
|
+
const threshold = parseFloat(config.DEFAULT_SIMILARITY_THRESHOLD);
|
|
144
|
+
if (isNaN(threshold) || threshold < 0 || threshold > 1) {
|
|
145
|
+
errors.push(`Invalid DEFAULT_SIMILARITY_THRESHOLD: must be between 0 and 1`);
|
|
146
|
+
}
|
|
147
|
+
// Validate hybrid search alpha (0-1 range)
|
|
148
|
+
const alpha = parseFloat(config.HYBRID_SEARCH_ALPHA);
|
|
149
|
+
if (isNaN(alpha) || alpha < 0 || alpha > 1) {
|
|
150
|
+
errors.push(`Invalid HYBRID_SEARCH_ALPHA: must be between 0 and 1`);
|
|
151
|
+
}
|
|
152
|
+
// Validate positive integers
|
|
153
|
+
const positiveIntFields = [
|
|
154
|
+
"EMBEDDING_BATCH_SIZE",
|
|
155
|
+
"IVF_PARTITIONS",
|
|
156
|
+
"PQ_BITS",
|
|
157
|
+
"QUERY_CACHE_TTL",
|
|
158
|
+
];
|
|
159
|
+
for (const field of positiveIntFields) {
|
|
160
|
+
const value = parseInt(config[field]);
|
|
161
|
+
if (isNaN(value) || value <= 0) {
|
|
162
|
+
errors.push(`Invalid ${field}: must be a positive integer`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Validate cache size format (e.g., "2GB", "500MB")
|
|
166
|
+
const cacheSizePattern = /^\d+(\.\d+)?(KB|MB|GB|TB)$/;
|
|
167
|
+
if (!cacheSizePattern.test(config.LANCEDB_MAX_CACHE_SIZE)) {
|
|
168
|
+
errors.push(`Invalid LANCEDB_MAX_CACHE_SIZE: must match pattern like "2GB", "500MB"`);
|
|
169
|
+
}
|
|
170
|
+
return errors;
|
|
236
171
|
}
|
|
237
|
-
|
|
238
172
|
/**
|
|
239
173
|
* Get validated configuration
|
|
240
174
|
*/
|
|
241
|
-
export function getConfig()
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return config;
|
|
175
|
+
export function getConfig() {
|
|
176
|
+
const config = loadConfig();
|
|
177
|
+
const errors = validateConfig(config);
|
|
178
|
+
if (errors.length > 0) {
|
|
179
|
+
throw new Error(`Configuration validation failed:\n${errors.join("\n")}`);
|
|
180
|
+
}
|
|
181
|
+
return config;
|
|
250
182
|
}
|
|
251
|
-
|
|
252
183
|
export default {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
184
|
+
loadConfig,
|
|
185
|
+
validateConfig,
|
|
186
|
+
getConfig,
|
|
187
|
+
loadMemoryConfig,
|
|
188
|
+
DEFAULTS,
|
|
189
|
+
MEMORY_DEFAULTS,
|
|
259
190
|
};
|