Skip to content

Commit d0ea158

Browse files
committed
Performance upgrades x2
1 parent 9ba303d commit d0ea158

10 files changed

Lines changed: 621 additions & 253 deletions

File tree

.env.example

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,18 @@ OM_WEAVIATE_CLASS=OpenMemory
5858
# --------------------------------------------
5959
# Available providers: openai, gemini, ollama, local, synthetic
6060
# Embedding models per sector can be configured in models.yaml
61+
#
62+
# NOTE: Your selected TIER (fast/smart/deep) affects how embeddings work:
63+
# • FAST tier: Uses synthetic embeddings regardless of OM_EMBEDDINGS setting
64+
# • SMART tier: Combines synthetic + compressed semantic from your chosen provider
65+
# • DEEP tier: Uses full embeddings from your chosen provider
66+
#
67+
# For SMART/DEEP tiers, set your preferred provider:
6168
OM_EMBEDDINGS=openai
62-
OM_VEC_DIM=1536
69+
70+
# Vector dimension (auto-adjusted by tier, but can be overridden)
71+
# • FAST: 256-dim • SMART: 384-dim • DEEP: 1536-dim
72+
# OM_VEC_DIM=1536
6373

6474
# Embedding Mode
6575
# simple = 1 unified batch call for all sectors (faster, rate-limit safe, recommended)
@@ -99,15 +109,67 @@ LOCAL_MODEL_PATH=/path/to/your/local/model
99109
# --------------------------------------------
100110
# Memory System Settings
101111
# --------------------------------------------
112+
113+
# ============================================
114+
# PERFORMANCE TIER (Auto-detected or Manual)
115+
# ============================================
116+
# OpenMemory automatically detects your hardware and selects the optimal tier.
117+
# You can override this by setting OM_TIER manually.
118+
#
119+
# Available Tiers:
120+
#
121+
# FAST - Synthetic embeddings only (256-dim)
122+
# • Recall: ~70-75% • QPS: 700-850 • RAM: 0.6GB/10k memories
123+
# • Best for: Local apps, VS Code extensions, low-end hardware
124+
# • Auto-selected: < 4 CPU cores or < 8GB RAM
125+
#
126+
# SMART - Hybrid embeddings (256-dim synthetic + 128-dim compressed semantic = 384-dim)
127+
# • Recall: ~85% • QPS: 500-600 • RAM: 0.9GB/10k memories
128+
# • Best for: Production servers, AI copilots, mid-range hardware
129+
# • Auto-selected: 4-7 CPU cores and 8-15GB RAM
130+
#
131+
# DEEP - Full AI embeddings (1536-dim OpenAI/Gemini)
132+
# • Recall: ~95-100% • QPS: 350-400 • RAM: 1.6GB/10k memories
133+
# • Best for: Cloud deployments, high-accuracy systems, research
134+
# • Auto-selected: 8+ CPU cores and 16+ GB RAM
135+
#
136+
# Leave commented to auto-detect, or set manually:
137+
# OM_TIER=fast
138+
# OM_TIER=smart
139+
# OM_TIER=deep
140+
102141
OM_MIN_SCORE=0.3
103142
OM_DECAY_LAMBDA=0.02
104143

105144
# Decay interval in minutes
106145
# Testing: 0.5 (30s) for rapid benchmarks
107146
# Development: 5 (5min) for realistic decay testing
108-
# Production: 1440 (24h) for stable long-term operation
109-
# Recommended: 5-60 minutes to balance decay accuracy vs overhead
110-
OM_DECAY_INTERVAL_MINUTES=144
147+
# Production: 10 (10min) for optimal throughput (3% batch = less disk pressure)
148+
# Recommended: 5-10 minutes to balance decay accuracy vs overhead
149+
OM_DECAY_INTERVAL_MINUTES=10
150+
151+
# Decay ratio (percentage of memories to decay per run, 0.01-0.1)
152+
# Lower = more stable variance, higher = faster decay propagation
153+
OM_DECAY_RATIO=0.03
154+
155+
# Sleep between segment processing (ms) to avoid lock contention
156+
OM_DECAY_SLEEP_MS=200
157+
158+
# Full Semantic Graph MVP Settings
159+
# Use summary-only storage (≤300 chars, intelligent extraction)
160+
OM_USE_SUMMARY_ONLY=true
161+
# Maximum summary length - smart extraction preserves dates, names, numbers, actions
162+
OM_SUMMARY_MAX_LENGTH=300
163+
# Memories per segment (10k recommended for optimal cache performance)
164+
OM_SEG_SIZE=10000
165+
166+
# Cache segments (auto-tuned by tier, but can be overridden)
167+
# • FAST: 2 segments • SMART: 3 segments • DEEP: 5 segments
168+
# OM_CACHE_SEGMENTS=3
169+
170+
# Max active queries (auto-tuned by tier, but can be overridden)
171+
# • FAST: 32 queries • SMART: 64 queries • DEEP: 128 queries
172+
# OM_MAX_ACTIVE=64
111173

112174
# Brain Sector Configuration (auto-classified, but you can override)
113175
# Sectors: episodic, semantic, procedural, emotional, reflective

README.md

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -87,51 +87,6 @@ npm install
8787
npm run dev
8888
```
8989

90-
Example `.env` configuration:
91-
92-
```ini
93-
# Core server
94-
OM_PORT=8080
95-
OM_MODE=standard
96-
OM_API_KEY=
97-
98-
# Metadata store
99-
OM_METADATA_BACKEND=sqlite # sqlite | postgres
100-
OM_DB_PATH=./data/openmemory.sqlite # used when sqlite
101-
102-
# PostgreSQL (only when OM_METADATA_BACKEND=postgres or OM_VECTOR_BACKEND=pgvector)
103-
OM_PG_HOST=localhost
104-
OM_PG_PORT=5432
105-
OM_PG_DB=openmemory
106-
OM_PG_USER=postgres
107-
OM_PG_PASSWORD=postgres
108-
OM_PG_SCHEMA=public
109-
OM_PG_TABLE=openmemory_memories
110-
OM_PG_SSL=disable # disable | require
111-
112-
# Vector store
113-
OM_VECTOR_BACKEND=sqlite # sqlite | pgvector | weaviate
114-
OM_VECTOR_TABLE=openmemory_vectors
115-
OM_WEAVIATE_URL=
116-
OM_WEAVIATE_API_KEY=
117-
OM_WEAVIATE_CLASS=OpenMemory
118-
119-
# Embeddings
120-
OM_EMBEDDINGS=openai
121-
OM_VEC_DIM=768
122-
OPENAI_API_KEY=
123-
GEMINI_API_KEY=
124-
OLLAMA_URL=http://localhost:11434
125-
LOCAL_MODEL_PATH=
126-
OM_MIN_SCORE=0.3
127-
OM_DECAY_LAMBDA=0.02
128-
129-
# LangGraph integration (optional)
130-
OM_LG_NAMESPACE=default
131-
OM_LG_MAX_CONTEXT=50
132-
OM_LG_REFLECTIVE=true
133-
```
134-
13590
Start server:
13691

13792
```bash

backend/src/config/index.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import path from 'path'
22
import dotenv from 'dotenv'
3+
import os from 'node:os'
34

45
dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
56

67
const num = (v: string | undefined, d: number) => Number(v) || d
78
const str = (v: string | undefined, d: string) => v || d
89
const 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+
1027
export 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

Comments
 (0)