Skip to content

feat: add Postgres/Supabase backend for memory store#40

Open
Siddhant-K-code wants to merge 2 commits intomainfrom
feat/postgres-memory-backend
Open

feat: add Postgres/Supabase backend for memory store#40
Siddhant-K-code wants to merge 2 commits intomainfrom
feat/postgres-memory-backend

Conversation

@Siddhant-K-code
Copy link
Owner

Memories stored on Render's SQLite are lost on every redeploy (ephemeral filesystem). This adds a Postgres backend so memories persist in Supabase.

Changes

  • pkg/memory/postgres.go — Full Store interface implementation using pgx driver. Same semantics as SQLiteStore: write-time dedup, tag filtering, relevance+recency scoring, touch-on-recall.
  • pkg/memory/postgres_migration.sql — Schema to run in Supabase SQL Editor (memories + memory_tags tables with indexes).
  • cmd/api.go — New --memory-backend (sqlite|postgres) and --memory-dsn flags.
  • cmd/mcp.go — Same new flags for MCP server.
  • cmd/api_memory.goMemoryAPI.store changed from *SQLiteStore to Store interface.
  • cmd/memory.gomemoryStoreFromConfig now routes to SQLite or Postgres based on backend flag.

Usage

# Supabase
distill api --memory --memory-backend postgres \
  --memory-dsn 'postgres://user:pass@db.supabase.co:5432/postgres?sslmode=require'

# SQLite (unchanged, still the default)
distill api --memory

Render deployment

After merging, update the Render start command to:

./distill-api api --port $PORT --memory --memory-backend postgres --memory-dsn $DATABASE_URL --session

And add DATABASE_URL env var with the Supabase connection string.

Tests

All 11 existing memory tests pass. Postgres store implements the same interface — no Postgres-specific tests needed (would require a live database in CI).

Siddhant-K-code and others added 2 commits February 24, 2026 18:37
Adds PostgresStore alongside the existing SQLiteStore, both implementing
the memory.Store interface. This allows persistent memory storage in
Supabase instead of ephemeral SQLite on Render.

Changes:
- pkg/memory/postgres.go: full Store implementation using pgx driver
- pkg/memory/postgres_migration.sql: schema for Supabase SQL editor
- cmd/api.go, cmd/mcp.go: new --memory-backend and --memory-dsn flags
- cmd/api_memory.go: MemoryAPI now uses Store interface, not SQLiteStore
- cmd/memory.go: memoryStoreFromConfig supports 'sqlite' and 'postgres'

Usage:
  distill api --memory --memory-backend postgres \
    --memory-dsn 'postgres://user:pass@host:5432/db?sslmode=require'

Co-authored-by: Ona <no-reply@ona.com>
- Remove dead argIdx increment (ineffectual assignment)
- README: add postgres backend usage, config examples, DATABASE_URL env var
- CHANGELOG: add unreleased section for postgres backend
- FAQ: mention postgres/supabase option in memory description

Co-authored-by: Ona <no-reply@ona.com>
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