Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions TASK_BACKLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# memU Task Backlog (local fallback)

Updated: 2026-03-05
Reason: production `/tasks` endpoint returned 404; captured here for later API sync.

## P0

### 1) Temporal graph decay engine
- **Task:** Implement temporal graph decay for memU memories (event-time + access-time half-life scoring) with tunable lane profiles and audit trail.
- **Owner:** lenny
- **Lane:** memory-core
- **Why now:** stale memories are likely diluting retrieval quality as corpus grows.
- **Acceptance criteria:**
- configurable half-life policy by memory lane
- retrieval score includes temporal decay factor
- stale-hit rate metric in dashboard

### 2) Neuro-symbolic memory router
- **Task:** Prototype neuro-symbolic memory router: vector ANN candidate retrieval + symbolic constraint/filter pass + explainability traces.
- **Owner:** lenny
- **Lane:** retrieval
- **Why now:** improves correctness and trust while preserving semantic recall.
- **Acceptance criteria:**
- rule-filter stage after vector retrieval
- explanation trace for final memories
- A/B report with precision@5 and contradiction-rate deltas

## P1

### 3) Local-first CRDT sync layer
- **Task:** Add local-first CRDT sync layer for offline agents (append-only op log + merge/replay + conflict metrics dashboard).
- **Owner:** lenny
- **Lane:** sync
- **Why now:** enables resilient offline-first operation with deterministic convergence.
- **Acceptance criteria:**
- peer merge semantics documented and tested
- replay endpoint + conflict counter metrics
- deterministic convergence test suite

### 4) Vector compression + reranking pipeline
- **Task:** Introduce vector compression pipeline (int8/binary quantization + rerank on full-float vectors) and benchmark recall/latency/cost tradeoffs.
- **Owner:** lenny
- **Lane:** vector-db
- **Why now:** reduce infra cost and improve query latency at rising memory scale.
- **Acceptance criteria:**
- benchmark harness for recall@k / p95 latency / RAM usage
- quantized index profile toggles
- production recommendation doc with guardrails

### 5) Hybrid retrieval fusion baseline (BM25 + ANN + RRF)
- **Task:** Add a first-class hybrid retrieval path combining keyword BM25 and vector ANN, merged with Reciprocal Rank Fusion.
- **Owner:** lenny
- **Lane:** retrieval
- **Why now:** deep-research evidence shows better recall on exact entities/terms while preserving semantic retrieval.
- **Acceptance criteria:**
- dual retrieval execution path in API
- configurable fusion weights / RRF mode
- benchmark showing precision@5 and miss-rate improvements on hard queries

### 6) Tiered memory architecture (L0/L1/L2)
- **Task:** Implement memory tiers: L0 working set (hot RAM), L1 episodic vectors, L2 symbolic graph facts with policy gating.
- **Owner:** lenny
- **Lane:** memory-core
- **Why now:** separates fast-context operations from durable long-term reasoning and improves debuggability.
- **Acceptance criteria:**
- explicit routing policy for each tier
- migration plan for existing memories
- observability dashboard showing tier hit ratios and latency

### 7) Retrieval-triggered reinforcement decay
- **Task:** Upgrade temporal decay to a reinforcement model where successful retrieval/access boosts edge/node vitality while inactive memory decays.
- **Owner:** lenny
- **Lane:** memory-core
- **Why now:** prevents over-pruning high-value memories and suppresses stale noise automatically.
- **Acceptance criteria:**
- decay + reinforcement formula documented and configurable
- audit log for score changes
- offline replay test proving stability across 30+ day simulations

### 8) Local-first CRDT sync MVP (SQLite WAL + op-log + peer merge)
- **Task:** Build a local-first sync MVP for offline-capable agents with CRDT merge semantics and opportunistic peer synchronization.
- **Owner:** lenny
- **Lane:** sync
- **Why now:** supports intermittent connectivity and reduces central API dependency for short outages.
- **Acceptance criteria:**
- append-only operation log persisted locally
- merge/replay API and conflict telemetry
- deterministic convergence test across 3 simulated peers

## P2

### 9) Adaptive vector index maintenance (IVF/HNSW drift repair)
- **Task:** Implement adaptive index maintenance that monitors partition recall/latency drift and triggers targeted re-clustering only for degraded regions.
- **Owner:** lenny
- **Lane:** vector-db
- **Why now:** avoids full index rebuilds while preserving retrieval quality under continuous ingest.
- **Acceptance criteria:**
- drift detector with configurable thresholds
- targeted reindex jobs + audit logs
- throughput/latency benchmark vs full rebuild baseline

### 10) Provenance-weighted contradiction guardrail
- **Task:** Add provenance/confidence metadata to memories and enforce a symbolic contradiction veto during final retrieval ranking.
- **Owner:** lenny
- **Lane:** retrieval
- **Why now:** improves trustworthiness by reducing high-similarity but low-trust conflicting recalls.
- **Acceptance criteria:**
- confidence score stored per memory/edge
- contradiction checker in retrieval pipeline
- measurable contradiction-rate reduction on regression set

### 11) Two-stage context compression (masking → structured summary)
- **Task:** Introduce staged context compression where old context is first masked, then summarized only when token pressure persists.
- **Owner:** lenny
- **Lane:** memory-core
- **Why now:** minimizes lost-in-the-middle failures while controlling token spend.
- **Acceptance criteria:**
- policy engine for compression stage transitions
- regression suite for context retention quality
- token-cost and completion-quality dashboard deltas

### 12) Event-driven multi-device memory coherence
- **Task:** Implement delta-push sync notifications with CRDT merge acknowledgements to tighten cross-device memory convergence.
- **Owner:** lenny
- **Lane:** sync
- **Why now:** reduces stale state windows when multiple devices/agents update shared memory concurrently.
- **Acceptance criteria:**
- changefeed/delta event channel
- merge ack + retry tracking
- deterministic convergence tests under concurrent write storms
8 changes: 7 additions & 1 deletion memu/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@
@asynccontextmanager
async def lifespan(app: FastAPI):
global pool, _fastembed_model, _nats_cluster, _nats_publisher
pool = await asyncpg.create_pool(DATABASE_URL, min_size=2, max_size=10)
async def _init_hnsw_search(conn):
"""Set HNSW ef_search for quality filtered retrieval (migration 013)."""
await conn.execute("SET hnsw.ef_search = 100")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SET hnsw.ef_search = 100 will raise unrecognized configuration parameter on clusters running older pgvector / without HNSW, and because it runs during pool init (before migrations) it can prevent the service from starting (and thus prevent applying migration 013). Consider making startup resilient when the parameter isn’t available.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle unsupported HNSW GUC during pool init

create_pool(..., init=_init_hnsw_search) now executes SET hnsw.ef_search = 100 on every new connection, and this happens before run_migrations(pool) is called. In environments where that GUC is unavailable (for example, pgvector not installed yet in the DB or a version that does not expose hnsw.ef_search), pool creation will raise and the API will fail to start instead of degrading gracefully as the migration path currently does.

Useful? React with 👍 / 👎.


pool = await asyncpg.create_pool(
DATABASE_URL, min_size=2, max_size=10, init=_init_hnsw_search
)

# Run DB migrations
try:
Expand Down
41 changes: 41 additions & 0 deletions memu/migrations/013_hnsw_filtered_retrieval.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- Migration 013: Upgrade IVFFlat → HNSW index for filtered ANN retrieval
-- Motivation: HNSW supports efficient pre-filtering by agent_id/memory_type
-- which eliminates the post-filter accuracy loss we get with IVFFlat.
-- pgvector >= 0.7.0 required (HNSW support), 0.8+ recommended for filtered search.

-- Step 1: Drop the old IVFFlat index
DROP INDEX IF EXISTS idx_memories_embedding;

-- Step 2: Create HNSW index on embedding column
-- m=16, ef_construction=200 are good defaults for our ~3000 memory corpus.
-- For larger corpora (>100k), increase ef_construction to 256-512.
CREATE INDEX idx_memories_embedding_hnsw

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration drops/rebuilds the vector index with a plain CREATE INDEX, which takes a strong lock on memories and can block reads/writes during creation on production-sized tables. Please make sure rollout expectations/downtime match this (or that migrations are run in a way that won’t impact availability).

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

ON memories USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 200);

-- Step 3: Create composite indexes for common filtered queries
-- These let pgvector push agent_id/memory_type filters INTO the ANN scan
-- instead of post-filtering (which discards valid nearest neighbors).

-- Agent-scoped search (most common query pattern for multi-agent)
CREATE INDEX IF NOT EXISTS idx_memories_agent_created
ON memories (agent_id, created_at DESC);

-- Type-scoped search (e.g., "find all lessons")
CREATE INDEX IF NOT EXISTS idx_memories_type_created
ON memories (memory_type, created_at DESC);

-- Confidence-filtered search
CREATE INDEX IF NOT EXISTS idx_memories_confidence
ON memories (confidence DESC)
WHERE confidence >= 0.5;

-- Step 4: Set HNSW search parameters for quality
-- ef (search-time beam width) trades speed for recall accuracy.
-- Default 40 is too low for filtered search; 100 gives good recall without
-- significant latency increase at our corpus size.
-- This is a session-level setting; we'll set it in the application connection pool.
-- ALTER SYSTEM SET hnsw.ef_search = 100; -- uncomment if you want cluster-wide

COMMENT ON INDEX idx_memories_embedding_hnsw IS
'HNSW index for filtered ANN retrieval. Replaces IVFFlat (migration 013). m=16, ef_construction=200.';
77 changes: 77 additions & 0 deletions reports/2026-03-04-fumemory-evolution-proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# FuMemory Evolution Proposal — 2026-03-04

## Run Evidence
- `routine_memu_evolution.sh`: ✅ MD sync ran, health check passed (`ok=true`, `db=schema=vector=ok`, `total_memories=2700`)
- Deep research: ✅ Perplexity `sonar-deep-research` completed (`29 in / 9450 out tokens`)
- `/tasks` API write: ❌ unavailable in prod for this route (`POST /api/v1/memu/tasks` -> 405, `POST /tasks` -> 404)
- Fallback applied: ✅ backlog updated in `memu-oss/TASK_BACKLOG.md`

## Most Promising Architecture Moves

### 1) Hybrid Neuro-Symbolic Memory Tiers (highest impact)
**Concept:** split memory into three tiers:
- **L0 (Working):** short-window, high-churn context in RAM
- **L1 (Episodic):** quantized vector store for semantic retrieval
- **L2 (Semantic/Rules):** graph facts + symbolic constraints + policy checks

**Why this wins:**
- Keeps latency low for active reasoning
- Preserves long-horizon recall
- Adds explainability and contradiction resistance through symbolic checks

### 2) Reinforcement Temporal Decay (not just time decay)
**Concept:** memory strength decays with inactivity but gets reinforced on successful retrieval and task outcomes.

**Why this wins:**
- Prevents useful memories from being pruned
- Naturally suppresses stale/unhelpful memory
- Creates quality drift control without manual curation

### 3) Local-First CRDT Sync
**Concept:** agent writes first to local SQLite WAL + op-log, then merges with peers/backend using CRDT semantics when connectivity returns.

**Why this wins:**
- Offline resilience
- Lower dependency on centralized uptime
- Deterministic convergence in distributed multi-agent setups

### 4) Vector DB Efficiency Stack
**Concept:** int8 quantization + HNSW tuning + hybrid BM25 fusion + optional GPU path.

**Why this wins:**
- Major cost reduction (RAM + compute)
- Better p95 latency at scale
- Better exact-term recall with hybrid retrieval

## 30-Day Implementation Plan

### Phase 1 (Week 1): Baseline + Safety Rails
1. Add hybrid retrieval endpoint (ANN + BM25 + RRF).
2. Instrument precision@5, contradiction-rate, stale-hit-rate, p95 latency.
3. Ship benchmark harness with fixed query corpus.

### Phase 2 (Week 2): Tiered Routing
1. Introduce L0/L1/L2 memory router.
2. Route writes by memory type (observation/fact/decision/policy).
3. Add trace output: `why_this_memory` for every retrieval response.

### Phase 3 (Week 3): Reinforcement Decay
1. Add decay + reinforcement scoring formula.
2. Record score deltas in audit table.
3. Run 30-day replay simulation and tune half-life profiles by lane.

### Phase 4 (Week 4): Local-First Sync MVP
1. Implement local op-log + WAL.
2. Build CRDT merge/replay endpoint and conflict metrics.
3. Run 3-peer deterministic convergence tests under partition/reconnect scenarios.

## Concrete Success Targets
- Precision@5: **+12%** on hard retrieval set
- Contradiction rate: **-40%**
- p95 retrieval latency: **<120ms** at 10k+ memory scale
- Memory infra cost/query: **-35%**
- Offline task continuity: **>=95%** for local-first agents during simulated API outages

## Notes
- This proposal was grounded in the deep-research run focused on neuro-symbolic storage, temporal graph decay, local-first P2P sync, and vector optimization.
- Backlog items reflecting this proposal were added to local fallback backlog because production task API is still inconsistent.
98 changes: 98 additions & 0 deletions reports/2026-03-05-fumemory-evolution-proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# FuMemory Evolution Proposal — 2026-03-05

## Run Evidence
- `routine_memu_evolution.sh`: ✅ MD sync + health check passed (`ok=true`, `db/scheme/vector=ok`, `total_memories=2733`).
- Perplexity deep research: ✅ completed via `sonar-deep-research` (`29 in / 9399 out tokens`).
- memU task API writes: ❌ unavailable in production routing (`POST /api/v1/memu/tasks` -> 405, `POST /tasks` -> 404).
- Fallback applied: ✅ backlog updated in `memu-oss/TASK_BACKLOG.md` with new P2 items (#9-#12).

## Creative Architecture Proposal: “Living Memory Mesh”

### Core Idea
Evolve memU from a single vector recall layer into a **living memory mesh**:
1. **Neuro layer** for fuzzy semantic recall (ANN vectors).
2. **Symbolic layer** for truth constraints, provenance, and contradiction checks.
3. **Temporal vitality layer** to promote memories that repeatedly prove useful.
4. **Local-first sync layer** to survive outages and converge deterministically.

This gives better recall quality, less stale noise, and stronger reliability under real multi-agent load.

## Most Promising Upgrades (ranked)

### 1) Provenance-weighted neuro-symbolic retrieval (highest leverage)
**What changes**
- Store confidence/provenance with each memory (source, timestamp, validation state).
- Keep ANN candidate generation, then run symbolic contradiction and policy filters.
- Final rank = semantic similarity × confidence × recency/vitality.

**Why now**
- Current failure mode is not “can’t find memory,” it’s “finds conflicting or weak memory.”
- This directly attacks contradiction-rate without killing semantic recall breadth.

### 2) Adaptive index maintenance (IVF/HNSW drift repair)
**What changes**
- Monitor shard-level latency + recall proxies.
- Re-cluster only degraded partitions instead of full rebuilds.
- Keep ingest online while tuning indexes.

**Why now**
- Corpus is growing; full rebuild strategy won’t scale operationally.
- Incremental repair improves stability and cost.

### 3) Two-stage context compression (masking → summary)
**What changes**
- Stage 1: mask low-value old context.
- Stage 2: summarize only when token pressure remains high.
- Regression tests for “lost-in-the-middle” behavior.

**Why now**
- Cheap compression-first strategy cuts token burn while preserving quality.
- Prevents summary-overcompression from degrading answer accuracy.

### 4) Event-driven multi-device coherence (delta push + merge ack)
**What changes**
- Publish memory deltas as events; peers apply CRDT merge.
- Track merge acknowledgements and retries.
- Add convergence tests under concurrent updates.

**Why now**
- Required for reliable local-first operation across agents/devices.
- Reduces stale windows after updates.

## Implementation Steps (specific)

### Phase A (Week 1): Retrieval integrity foundation
1. Add `confidence`, `provenance`, and `validation_state` fields to memory metadata.
2. Implement contradiction checker in post-ANN pipeline.
3. Add retrieval trace output (`candidate -> filtered -> final`) for QA.

### Phase B (Week 2): Adaptive vector ops
1. Add index health telemetry by partition (p95, miss proxy, queue depth).
2. Build targeted reindex worker for degraded partitions.
3. Add guardrails to prevent over-aggressive re-clustering.

### Phase C (Week 3): Context compression policy engine
1. Implement masking-first context reducer.
2. Implement structured summarizer fallback triggered by token pressure.
3. Add benchmark suite comparing quality/cost across policies.

### Phase D (Week 4): Coherence and sync hardening
1. Add delta event stream for memory mutations.
2. Add merge ack + retry queue + dead-letter handling.
3. Run 3-peer partition/reconnect convergence tests and publish report.

## Target Metrics
- Contradiction rate: **-40%**
- p95 retrieval latency at 10k+ memory scale: **<120ms**
- Token cost for long-context tasks: **-25%**
- Incremental index maintenance overhead: **<20%** of full rebuild equivalent
- Cross-peer convergence success under partition test: **>=99%**

## Backlog Sync Result
Attempted production task ingestion failed due routing mismatch. Added the most promising upgrades to local fallback backlog:
- #9 Adaptive vector index maintenance
- #10 Provenance-weighted contradiction guardrail
- #11 Two-stage context compression
- #12 Event-driven multi-device memory coherence

These are now ready for implementation sequencing once `/tasks` API route is fixed in prod.
Loading