11import path from 'path'
22import dotenv from 'dotenv'
3+ import os from 'node:os'
34
45dotenv . config ( { path : path . resolve ( __dirname , '../../../.env' ) } )
56
67const num = ( v : string | undefined , d : number ) => Number ( v ) || d
78const str = ( v : string | undefined , d : string ) => v || d
89const bool = ( v : string | undefined ) => v === 'true'
910
11+ type Tier = 'fast' | 'smart' | 'deep'
12+ function detectTier ( ) : Tier {
13+ const manual = process . env . OM_TIER as Tier
14+ if ( manual && [ 'fast' , 'smart' , 'deep' ] . includes ( manual ) ) return manual
15+ const cores = os . cpus ( ) . length
16+ const ramGB = os . totalmem ( ) / ( 1024 ** 3 )
17+ if ( cores >= 8 && ramGB >= 16 ) return 'deep'
18+ if ( cores >= 4 && ramGB >= 8 ) return 'smart'
19+ return 'fast'
20+ }
21+
22+ export const tier = detectTier ( )
23+ const tierDims = { fast : 256 , smart : 384 , deep : 1536 }
24+ const tierCache = { fast : 2 , smart : 3 , deep : 5 }
25+ const tierMaxActive = { fast : 32 , smart : 64 , deep : 128 }
26+
1027export const env = {
1128 port : num ( process . env . OM_PORT , 8080 ) ,
1229 db_path : str ( process . env . OM_DB_PATH , './data/openmemory.sqlite' ) ,
@@ -27,10 +44,10 @@ export const env = {
2744 gemini_key : process . env . GEMINI_API_KEY || process . env . OM_GEMINI_API_KEY || '' ,
2845 ollama_url : str ( process . env . OLLAMA_URL || process . env . OM_OLLAMA_URL , 'http://localhost:11434' ) ,
2946 local_model_path : process . env . LOCAL_MODEL_PATH || process . env . OM_LOCAL_MODEL_PATH || '' ,
30- vec_dim : num ( process . env . OM_VEC_DIM , 768 ) ,
47+ vec_dim : num ( process . env . OM_VEC_DIM , tierDims [ tier ] ) ,
3148 min_score : num ( process . env . OM_MIN_SCORE , 0.3 ) ,
3249 decay_lambda : num ( process . env . OM_DECAY_LAMBDA , 0.02 ) ,
33- decay_interval_minutes : num ( process . env . OM_DECAY_INTERVAL_MINUTES , 1440 ) , // Default 24 hours
50+ decay_interval_minutes : num ( process . env . OM_DECAY_INTERVAL_MINUTES , 1440 ) ,
3451 max_payload_size : num ( process . env . OM_MAX_PAYLOAD_SIZE , 1_000_000 ) ,
3552 mode : str ( process . env . OM_MODE , 'standard' ) . toLowerCase ( ) ,
3653 lg_namespace : str ( process . env . OM_LG_NAMESPACE , 'default' ) ,
@@ -42,6 +59,13 @@ export const env = {
4259 ide_allowed_origins : str ( process . env . OM_IDE_ALLOWED_ORIGINS , 'http://localhost:5173,http://localhost:3000' ) . split ( ',' ) ,
4360 auto_reflect : bool ( process . env . OM_AUTO_REFLECT ) ,
4461 reflect_interval : num ( process . env . OM_REFLECT_INTERVAL , 10 ) ,
45- reflect_min : num ( process . env . OM_REFLECT_MIN_MEMORIES , 20 )
62+ reflect_min : num ( process . env . OM_REFLECT_MIN_MEMORIES , 20 ) ,
63+ use_summary_only : ( process . env . OM_USE_SUMMARY_ONLY ?? 'true' ) !== 'false' ,
64+ summary_max_length : num ( process . env . OM_SUMMARY_MAX_LENGTH , 200 ) ,
65+ seg_size : num ( process . env . OM_SEG_SIZE , 10000 ) ,
66+ cache_segments : num ( process . env . OM_CACHE_SEGMENTS , tierCache [ tier ] ) ,
67+ max_active : num ( process . env . OM_MAX_ACTIVE , tierMaxActive [ tier ] ) ,
68+ decay_ratio : num ( process . env . OM_DECAY_RATIO , 0.03 ) ,
69+ decay_sleep_ms : num ( process . env . OM_DECAY_SLEEP_MS , 200 )
4670}
4771
0 commit comments