Skip to content

docs(plan): pgvector + AGE migration implementation plan - #20

Merged
jphein merged 1 commit into
mainfrom
feat/pgvector-age-impl
May 11, 2026
Merged

docs(plan): pgvector + AGE migration implementation plan#20
jphein merged 1 commit into
mainfrom
feat/pgvector-age-impl

Conversation

@jphein

@jphein jphein commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implementation plan derived from the substrate-migration spec merged via #19. Four phases, 92 bite-sized TDD steps, ready for execution under superpowers:subagent-driven-development or superpowers:executing-plans.

Structure

Phase What ships Independence
0 — Preflight Postgres + extension probe; MemPalace#665 composition decision recorded Required gate
1 — pgvector backend MEMPALACE_BACKEND=postgres opt-in; HNSW + supporting indexes; where-clause translation; CI workflow Ships standalone
2 — AGE-backed KG MEMPALACE_KG_BACKEND=age; Cypher MERGE+CREATE with temporal validation; as_of filter Builds on Phase 1
3 — Migration tool mempalace migrate-to-postgres CLI, 7 sub-phases, restartable, idempotent Builds on 1+2
4 — Operator cutover Dry-run on cp -al snapshot, measure timings, production cutover Operator-driven

Key decisions encoded

  • Bifurcated Phase 1 by Task 0.2's Add optional PostgreSQL backend with pg_sorted_heap support MemPalace/mempalace#665 decision — Tasks 1.A.* compose with upstream PR Add optional PostgreSQL backend with pg_sorted_heap support MemPalace/mempalace#665 (cherry-pick + verify), Tasks 1.B.* fork-port mempalace.backends.postgres ourselves. Plan supports both paths without forking the document.
  • Idempotent everywhere — every phase has explicit re-run semantics (ON CONFLICT DO NOTHING, IF NOT EXISTS, watermark-based skip).
  • AGE Cypher fallback documented inline — apache-age-python package availability is the one TBD; Cypher-via-psycopg-cursor pattern written in Task 2.2 Step 3's _run_cypher so the executor can proceed even if no python AGE wrapper exists.
  • Phase 5 (KG migration) flagged for explicit review — AGE Cypher from Python is the trickiest surface; plan says stop at Phase 5 in subagent-driven execution.

Self-review

  • ✅ Spec coverage: every spec section has a corresponding task; cross-referenced in self-review at end of plan
  • ✅ Placeholder scan: 2 TBDs are documented open questions with fallback paths (not plan failures)
  • ✅ Type consistency: phase_N_<name> + KnowledgeGraphAGE signatures + checkpoint helpers consistent across all tasks
  • ✅ Scope: three phases each with a working-software ship milestone; right granularity for one plan document

Test plan

  • Plan self-review (per writing-plans skill)
  • Copilot review
  • Next: execute under superpowers:subagent-driven-development (recommended for 92-step plan with independent tasks)

After this PR

Plan execution is the next step. Per the writing-plans skill, the choice is:

  1. Subagent-driven (recommended) — fresh subagent per task, two-stage review, fast iteration
  2. Inline execution — batch with checkpoints in a single session

The upstream-coordination comments on MemPalace#665 and MemPalace#574 happen at the very end, after working code is on fork main (per feedback_upstream_comment_timing from this session).

🤖 Generated with Claude Code

…2 steps)

Implementation plan derived from the 2026-05-10 substrate-migration spec.
Three implementable phases + operator cutover, structured TDD:

Phase 0 (preflight) — verify Postgres + extensions on dev host, decide
upstream MemPalace#665 composition stance (wait vs fork-port) in a recorded
internal doc.

Phase 1 (pgvector backend) — bifurcated by 0.2's decision:
  1.A.* — compose with MemPalace#665, cherry-pick + verify against our v3.3.5 main
  1.B.* — fork-port mempalace.backends.postgres ourselves
Plus common tasks: HNSW + supporting indexes (fork rows 1/7/12), where-
clause translation ($eq/$ne/$in), MempalaceConfig.backend + postgres_dsn
properties, postgres CI workflow with pgvector/pgvector service image.

Phase 2 (AGE-backed KG) — KnowledgeGraphAGE skeleton + graph bootstrap,
add_triple via Cypher MERGE+CREATE with temporal validation mirroring
upstream v3.3.5 KG hardening, as_of temporal filter, kg_backend config
property + mcp_server routing.

Phase 3 (migration tool) — mempalace migrate-to-postgres CLI:
  - phase 0: preflight (daemon-stopped check, extension availability)
  - phase 1: schema (extensions + tables + checkpoint helpers)
  - phase 2: batched drawer copy (ON CONFLICT DO NOTHING; idempotent)
  - phase 3-5: closets, indexes, KG -> AGE (Task 3.4 template)
  - phase 6: verify (count parity + sample round-trip)
  - phase 7: done (cleanup checkpoints, print cutover steps)

Phase 4 (operator cutover) — dry-run on cp -al snapshot of canonical
160K-drawer palace, measure phase timings, update spec performance
budget with measured numbers, then production cutover.

Self-review verified: spec coverage complete, type consistency clean
(phase_N_<name> + KnowledgeGraphAGE signatures + _set_checkpoint
helpers all consistent across tasks), no placeholder failures
(the 2 TBDs are open questions with documented fallback paths).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 11, 2026 02:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a detailed, phased implementation plan document for migrating MemPalace’s storage substrate from ChromaDB + sqlite KG to Postgres with pgvector (vectors) and Apache AGE (knowledge graph), including a restartable/idempotent migration CLI plan and task-by-task TDD steps.

Changes:

  • Introduces a multi-phase execution plan (preflight → pgvector backend → AGE KG → migration tool → operator cutover).
  • Specifies concrete TDD task breakdowns, including schema/indexing, where-clause translation, config/env routing, and migration phases/checkpointing.
  • Includes a proposed CI workflow snippet for Postgres backend testing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


**Architecture:** Three phases on top of upstream's `BaseCollection` seam (#413, merged). Phase 1 lands the pgvector backend (composing with upstream #665 or fork-porting). Phase 2 adds the AGE-backed KG layer. Phase 3 ships the `mempalace migrate-to-postgres` CLI tool. Each phase produces working, testable software on its own.

**Tech Stack:** Python 3.9+ (existing mempalace floor), psycopg[binary]>=3.1, pgvector-python>=0.3, apache-age-python (TBD on package availability — fallback is raw Cypher over a psycopg cursor), pytest-postgresql for unit tests, docker-compose Postgres for integration tests.
Comment on lines +736 to +742
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with: { python-version: "3.13" }
- run: pip install -e ".[dev,postgres]"
- run: pip install pgvector
- env:
Comment on lines +739 to +745
with: { python-version: "3.13" }
- run: pip install -e ".[dev,postgres]"
- run: pip install pgvector
- env:
TEST_POSTGRES_DSN: postgresql://palace:palace@localhost:5432/mempalace_test
run: python -m pytest tests/test_backends_postgres.py -v
```
@jphein
jphein merged commit 6827b97 into main May 11, 2026
10 checks passed
@jphein
jphein deleted the feat/pgvector-age-impl branch May 11, 2026 02:46
@jphein jphein added the documentation Improvements or additions to documentation label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants