Home · Developers · Guides · Memory

Workspace

Memory

Memory service and store

Nova Coder separates memory into distinct layers to improve context handling and retrieval. Each layer has a different lifetime and scope.

Memory Layers

┌────────────────────────────────────────┐
│           Session Memory               │
│  Current conversation, open files      │
├────────────────────────────────────────┤
│           Working Memory               │
│  Current task, intermediate results    │
├────────────────────────────────────────┤
│           Project Memory               │
│  Architecture, symbol index, decisions │
├────────────────────────────────────────┤
│          Persistent Memory             │
│  User preferences, settings, plugins   │
└────────────────────────────────────────┘

MemoryStore

MemoryStore is a thread-safe SQLite-backed key-value store with enhanced concurrency and security features. All SQL operations are protected by a threading.Lock, and the database uses Write-Ahead Logging (WAL) mode for better performance and concurrency.

from novacoder.memory import MemoryStore, MemoryScope

store = MemoryStore('~/.config/novacoder/memory.db')
store.initialize()

store.set('project.summary', 'Flask API', scope=MemoryScope.PROJECT)
entry = store.get('project.summary', scope=MemoryScope.PROJECT)
print(entry.value)  # Flask API
print(entry.created_at)

Thread Safety Enhancements

The MemoryStore implements several thread safety improvements:

  • WAL Mode: Write-Ahead Logging enabled for better concurrency
  • Busy Timeout: Configured 5-second timeout for concurrent access
  • Synchronous Mode: Set to NORMAL for performance balance
  • Comprehensive Logging: All database operations logged for debugging and security
  • Thread Lock: All operations protected by threading.Lock

Database Configuration

The SQLite connection is configured with the following PRAGMA settings for optimal performance and safety:

PRAGMA journal_mode=WAL        # Write-Ahead Logging for better concurrency
PRAGMA synchronous=NORMAL       # Balance between safety and performance
PRAGMA busy_timeout=5000        # 5-second timeout for concurrent access

Logging

All memory operations are logged with appropriate context:

  • Set operations: Logged with key, scope, and value length
  • Get operations: Logged with key, scope, and found status
  • Delete operations: Logged with key and scope
  • Purge operations: Logged with count of expired entries removed

This logging aids in debugging, security auditing, and performance monitoring.

Memory Scopes

Scope Use Case Default TTL
session Current conversation 24 hours
working Current task scratchpad 2 hours
project Project architecture and index never
persistent User preferences and settings never
agent Agent-specific state 48 hours

MemoryService

MemoryService is the kernel service that manages the memory store. It exposes a service-level API and delegates to MemoryStore:

from novacoder.memory import MemoryService
from novacoder.config.settings import AppConfig

service = MemoryService(config=AppConfig())
service.initialize()

service.remember('key', 'value', scope=MemoryScope.SESSION)
print(service.recall('key'))
print(service.recall_all(scope=MemoryScope.SESSION))
service.forget('key')

Service API

  • remember(key, value, scope=SESSION, ttl_seconds=None), store a value
  • recall(key, scope=SESSION), return a value or None
  • forget(key, scope=SESSION), delete a single entry
  • clear(scope=SESSION), delete all entries in a scope
  • recall_all(scope=SESSION), return {key: value} for non-expired entries
  • recall_all_entries(scope=SESSION), return {key: MemoryEntry}
  • purge_expired(), delete expired entries and return the count

CLI

Clear every entry in a scope:

novacoder memory clear --scope session

TUI

The Memory page lists entries for the selected scope. A Delete Entry button removes the currently selected row by calling MemoryService.forget(). A Clear Scope button calls MemoryService.clear() for the selected scope.

TUI Backup Integration

The TUI Memory page includes backup and restore functionality:

  • Backup Button: Creates a backup for the currently selected scope
  • List Backups Button: Displays all available backups in a table
  • Restore Button: Restores the selected backup to the current scope
  • Backup DataTable: Shows backup ID, time, size, entries, and type

The backup system is integrated through MemoryService.backup with automatic handler registration for all memory scopes. See Memory Backup and Recovery for detailed information.

SessionContext

SessionContext wraps MemoryService to give each agent run a private session namespace. All keys are prefixed with the session id.

from novacoder.memory import SessionContext

ctx = SessionContext('session-1', service)
ctx.store('user', 'alice')
print(ctx.retrieve('user'))  # alice
ctx.close()

AgentManager creates a new SessionContext for every run() call and sets it on the agent via agent.set_session_context(). Agents can access it through self.session_context. See Session Context for more details.

Configuration

memory:
  database: sqlite
  db_path: ~/.config/novacoder/memory.db

Database Schema

The SQLite store uses a single table with created_at and expires_at columns:

CREATE TABLE memory (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    scope TEXT NOT NULL,
    key TEXT NOT NULL,
    value TEXT NOT NULL,
    timestamp TEXT NOT NULL,
    metadata TEXT,
    created_at REAL,
    expires_at REAL
);

TTL and Expiry

set() and remember() accept an optional ttl_seconds argument. When omitted, the default TTL for the scope is used. get() and get_all() filter out expired entries. Expired rows are removed by purge_expired().

MemoryService.start() schedules a daily purge through the kernel Scheduler.

store.set('temp', 'data', scope=MemoryScope.WORKING, ttl_seconds=3600)

Closing the Store

close() terminates the connection and marks the store as closed. Subsequent calls to get() or set() raise RuntimeError.

store.clear()

Development Instructions

Adding a New Memory Scope

  1. Add a new value to MemoryScope in novacoder/memory/memory.py.
  2. Update DEFAULT_SCOPE_TTL if needed.
  3. Add tests verifying scope isolation and TTL.
  4. Update this wiki page and the glossary.

Adding a New Memory Backend

  1. Define a backend interface (e.g., MemoryBackend) in novacoder/memory/backends/.
  2. Refactor MemoryStore to delegate to the backend.
  3. Implement the SQLite backend as the default.
  4. Add a backend factory selected by MemoryConfig.database.

Testing Memory

def test_memory_store(tmp_path):
    from novacoder.memory import MemoryStore, MemoryScope
    store = MemoryStore(tmp_path / 'memory.db')
    store.initialize()
    store.set('key', 'value', scope=MemoryScope.PROJECT)
    entry = store.get('key', scope=MemoryScope.PROJECT)
    assert entry.value == 'value'
    store.clear()

Vector Memory

Nova Coder includes a lightweight in-memory vector store for semantic retrieval. It is enabled by setting memory.vector_db to memory:

memory:
  vector_db: memory

The VectorMemoryStore lives in novacoder.embeddings and uses an AIProvider that supports embed:

from novacoder.embeddings import VectorMemoryStore
from novacoder.ai.provider import AIProvider

store = VectorMemoryStore()
await store.embed_and_store('greeting', 'hello world', provider)
keys = await store.search('hi', provider, top_k=3)

MemoryService exposes vector memory when configured:

await memory_service.vector_embed_and_store('greeting', 'hello world', provider)
keys = await memory_service.vector_search('hi', provider)

MemoryService uses ModelRouter.select("embeddings") to choose an embedding-capable provider. OllamaProvider calls /api/embed and OpenAIProvider calls /embeddings when an API key is configured. With the memory vector backend, embeddings are persisted alongside the memory store.

Advanced Memory Systems

Nova Coder's memory system has been significantly enhanced with 15 new production-grade systems for security, reliability, and scalability:

High Priority Systems

  • Vector Databases - Production vector database support (Pinecone, Weaviate, ChromaDB, Qdrant, Milvus)
  • Memory Encryption - AES-256 encryption with key management and rotation
  • Backup and Recovery - Automated backup with point-in-time recovery and verification
  • Access Control - Role-based access control (RBAC) with key-level permissions
  • Memory Validation - Schema-based validation with custom business rules

Medium Priority Systems

  • Memory Compression - zlib and lz4 compression with statistics
  • Memory Analytics - Access pattern analysis, hot key detection, and monitoring
  • Memory Indexing - Full-text search, metadata indexing, and composite indexes
  • Memory Replication - Master-slave replication with health monitoring
  • Memory Query Capabilities - Pattern search, metadata queries, and time-range queries
  • Memory Transactions - Atomic multi-key operations with savepoints and isolation levels
  • Memory Caching - In-memory caching with LRU, LFU, FIFO, and TTL eviction policies

Low Priority Systems

  • Memory Export/Import - JSON, CSV, and SQLite format support
  • Memory Versioning - Change tracking, rollback, and version comparison
  • Memory Sharding - Horizontal sharding with consistent hashing
  • Distributed Memory - Distributed memory storage for horizontal scaling
  • Memory Streams - Stream-based memory operations for real-time data
  • Memory Graph - Graph-based memory for relationship tracking
  • Memory Federation - Federation across multiple memory stores

Integration

All new systems are integrated into MemoryService and accessible via property accessors:

from novacoder.memory import MemoryService

service = MemoryService(config)
service.initialize()

# Access new systems
service.compression.compress(data)
service.encryption.encrypt(data)
service.backup.create_backup(["session"], BackupType.FULL)
service.access_control.check_permission("user", "key", Permission.READ, "project")
service.analytics.get_access_statistics()
service.cache.get_default_cache().get("key")

TUI Integration

The Memory page in the TUI now includes:

  • Real-time statistics cards (compression, encryption, cache, backups)
  • Analytics button to view memory analytics
  • Backup button to create memory backups
  • All operations run in background threads

Future Enhancements

  • Conversation summarization
  • Cross-project memory with user consent
  • Memory decay and importance scoring
  • Episodic memory for past mistakes
  • Configuration
  • Workspace
  • Agents
  • Memory Advanced Systems - Comprehensive overview of all advanced memory systems
  • Memory Vector Databases
  • Memory Compression
  • Memory Encryption
  • Memory Backup and Recovery
  • Memory Access Control
  • Memory Analytics
  • Memory Indexing
  • Memory Replication
  • Memory Query Capabilities
  • Memory Transactions
  • Memory Validation
  • Memory Caching
  • Memory Export/Import
  • Memory Versioning
  • Memory Sharding
  • Distributed Memory
  • Memory Federation
  • Memory Graph
  • Memory Streams

Source: wiki/memory.md · rendered 2026-11-10