Skip to main content

Configuration

All configuration is passed at engine creation time. There are no config files or environment variables.

Engine parameters

from openmem import MemoryEngine

engine = MemoryEngine(
db_path=":memory:", # Database path
max_hops=2, # Spreading activation depth
decay_per_hop=0.5, # Activation decay per hop
weights={ # Scoring weights
"activation": 0.5,
"recency": 0.2,
"strength": 0.2,
"confidence": 0.1,
},
)

db_path

ValueBehavior
":memory:" (default)In-memory database. Fast, but lost on exit.
"memories.db"Persistent SQLite file. Survives restarts.
Any file pathCreates the file if it doesn't exist.

max_hops

Controls how far spreading activation traverses the memory graph.

ValueEffect
0No spreading — only BM25 direct hits
1Activate immediate neighbors
2 (default)Activate neighbors of neighbors

Higher values pull in more context but may surface less relevant memories.

decay_per_hop

How much activation drops at each hop. Default is 0.5 (50% reduction per level).

A memory with activation 0.8 at hop 0 activates its neighbor at 0.4 (hop 1), which activates its neighbor at 0.2 (hop 2).

weights

Controls how the final competition score is calculated. Must sum to 1.0.

WeightDefaultDescription
activation0.5Spreading activation score
recency0.2How recently the memory was accessed
strength0.2Reinforcement history
confidence0.1Confidence set at creation time

Scoring constants

These are not currently configurable but define the scoring behavior:

ConstantValueDescription
LAMBDA_RECENCY0.05Recency decay rate (~14-day half-life)
ALPHA_DECAY0.01Natural strength decay rate
BETA_REINFORCE0.1Strength boost on reinforce()
CHARS_PER_TOKEN4Token estimation for budget packing

Status penalties

Memories that have been superseded or contradicted receive score penalties:

StatusMultiplier
active1.0 (no penalty)
superseded0.5 (50% reduction)
contradicted0.3 (70% reduction)

Example configurations

Recency-heavy (chatbot)

Prioritize recent conversations:

engine = MemoryEngine(
db_path="chat.db",
weights={"activation": 0.3, "recency": 0.5, "strength": 0.1, "confidence": 0.1},
)

Deep graph traversal (knowledge base)

Pull in more connected context:

engine = MemoryEngine(
db_path="knowledge.db",
max_hops=2,
decay_per_hop=0.7, # less decay = more neighbors surface
weights={"activation": 0.6, "recency": 0.1, "strength": 0.2, "confidence": 0.1},
)

High-confidence only (critical decisions)

Trust confidence scores heavily:

engine = MemoryEngine(
db_path="decisions.db",
weights={"activation": 0.4, "recency": 0.1, "strength": 0.2, "confidence": 0.3},
)