Skip to content

perf(stats): add bank_id to memory_links for direct filtering#718

Merged
nicoloboschi merged 1 commit intomainfrom
fix/stats-endpoint-performance
Mar 27, 2026
Merged

perf(stats): add bank_id to memory_links for direct filtering#718
nicoloboschi merged 1 commit intomainfrom
fix/stats-endpoint-performance

Conversation

@nicoloboschi
Copy link
Copy Markdown
Collaborator

Summary

  • Adds bank_id column to memory_links table with migration (backfill from memory_units)
  • All 4 link INSERT paths (temporal, semantic, entity, causal) now write bank_id
  • Stats query filters on ml.bank_id instead of mu.bank_id, letting Postgres push the filter before the JOIN

Problem

The stats endpoint JOINs memory_links to memory_units just to filter by bank_id. With 8.2M+ links per bank this takes 18+ seconds, and the control plane polls every 10s — perpetually blocking the server.

Test plan

  • Lint passes
  • 21/21 link utils unit tests pass
  • 89 retain/link/integration tests pass
  • Verify stats endpoint latency on a large bank after migration

The stats endpoint JOINs memory_links to memory_units just to filter
by bank_id.  With 8.2M+ links per bank this takes 18+ seconds, and
the control plane polls every 10s — perpetually blocking the server.

Add bank_id column directly to memory_links so the query can filter
on ml.bank_id instead of mu.bank_id, letting Postgres push the filter
down before the JOIN.

- Migration: add bank_id TEXT NOT NULL, backfill from memory_units
- All 4 INSERT paths (temporal, semantic, entity, causal) now write bank_id
- Stats query filters on ml.bank_id instead of mu.bank_id
@nicoloboschi nicoloboschi merged commit f50cc25 into main Mar 27, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant