Skip to content

Memory Service

The Memory Service provides Nova’s long-term memory system. It stores, retrieves, and manages memories across three tiers using PostgreSQL with pgvector for embedding-based similarity search combined with full-text keyword matching.

PropertyValue
Port8002
FrameworkFastAPI + SQLAlchemy async
DatabasePostgreSQL 16 with pgvector
State storeRedis (db 0)
Sourcememory-service/
TierPurposeStorage
SemanticFacts with confidence decay — key-value knowledge that ages using ACT-R cognitive modelPostgreSQL + pgvector embeddings
ProceduralLessons learned and procedures — how to do thingsPostgreSQL + pgvector embeddings
EpisodicTask summaries and event records — what happenedPostgreSQL + pgvector embeddings
  • Memory storage — store text content with embeddings across all three tiers
  • Hybrid retrieval — combine 70% cosine similarity (vector) with 30% ts_rank (full-text keyword) for accurate search
  • Fact management — upsert facts keyed on (project_id, category, key) with confidence tracking
  • Context assembly — build agent context packages from relevant memories for a given query
  • Confidence decay — ACT-R power-law decay: effective_confidence = base_confidence * (days_since_access ^ -0.5)
  • Background maintenance — cleanup of expired working memories, memory compaction, and table partitioning

All memory endpoints are prefixed with /api/v1/memories.

MethodPathDescription
POST/api/v1/memoriesStore a new memory (auto-embeds content)
POST/api/v1/memories/searchHybrid semantic + keyword search
POST/api/v1/memories/factsSave or upsert a fact
POST/api/v1/memories/bulkBulk store multiple memories
GET/api/v1/memories/browseBrowse memories with pagination and tier filter
GET/api/v1/memories/{id}Get a specific memory
PATCH/api/v1/memories/{id}Update a memory
DELETE/api/v1/memories/{id}Delete a memory
POST/api/v1/memories/{agent_id}/contextBuild context package for an agent
MethodPathDescription
GET/health/liveLiveness probe
GET/health/readyReadiness probe (checks DB)
VariableDescriptionDefault
DATABASE_URLPostgreSQL connection string
REDIS_URLRedis connection stringredis://redis:6379/0
LLM_GATEWAY_URLURL of the LLM Gateway for embeddingshttp://llm-gateway:8001
LOG_LEVELLogging levelINFO

The Memory Service generates embeddings via the LLM Gateway’s /embed endpoint. The embedding fallback chain is:

  1. text-embedding-3-small (OpenAI) — 1536 dimensions
  2. nomic-embed-text (Ollama) — 768 dimensions, zero-padded to 1536 for compatibility

A 3-tier embedding cache reduces redundant embedding calls:

  • L1: Redis (fast, volatile)
  • L2: PostgreSQL (persistent)
  • L3: LLM Gateway (source of truth)

Three background loops run continuously:

TaskIntervalPurpose
CleanupEvery 5 minutesDelete expired working memory rows
CompactionConfigurableMerge and consolidate related memories
PartitioningConfigurableManage table partitions for performance
  • SQLAlchemy async — unlike the Orchestrator (which uses raw asyncpg), Memory Service uses SQLAlchemy’s async engine for ORM-style queries
  • Hybrid search — combines pgvector cosine similarity with PostgreSQL full-text search (ts_rank) in a single query for best results on both semantic and exact-match lookups
  • ACT-R confidence — the cognitive science-based decay model ensures stale facts naturally lose relevance over time, preventing outdated information from contaminating agent context
  • Schema migrations — run automatically at startup via run_schema_migrations()