Files
t6_mem0_v2/migrations/supabase/README.md
Claude Code 61a4050a8e Complete implementation: REST API, MCP server, and documentation
Implementation Summary:
- REST API with FastAPI (complete CRUD operations)
- MCP Server with Python MCP SDK (7 tools)
- Supabase migrations (pgvector setup)
- Docker Compose orchestration
- Mintlify documentation site
- Environment configuration
- Shared config module

REST API Features:
- POST /v1/memories/ - Add memory
- GET /v1/memories/search - Semantic search
- GET /v1/memories/{id} - Get memory
- GET /v1/memories/user/{user_id} - User memories
- PATCH /v1/memories/{id} - Update memory
- DELETE /v1/memories/{id} - Delete memory
- GET /v1/health - Health check
- GET /v1/stats - Statistics
- Bearer token authentication
- OpenAPI documentation

MCP Server Tools:
- add_memory - Add from messages
- search_memories - Semantic search
- get_memory - Retrieve by ID
- get_all_memories - List all
- update_memory - Update content
- delete_memory - Delete by ID
- delete_all_memories - Bulk delete

Infrastructure:
- Neo4j 5.26 with APOC/GDS
- Supabase pgvector integration
- Docker network: localai
- Health checks and monitoring
- Structured logging

Documentation:
- Introduction page
- Quickstart guide
- Architecture deep dive
- Mintlify configuration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 08:44:16 +02:00

4.3 KiB

Supabase Migrations for T6 Mem0 v2

Overview

This directory contains SQL migrations for setting up the Supabase vector store used by T6 Mem0 v2.

Migrations

001_init_vector_store.sql

Initial setup migration that creates:

  • pgvector extension: Enables vector similarity search
  • t6_memories table: Main storage for memory vectors and metadata
  • Indexes: HNSW for vectors, B-tree for filters, GIN for JSONB
  • Functions:
    • match_t6_memories(): Vector similarity search with filters
    • get_t6_memory_stats(): Memory statistics
    • update_t6_memories_updated_at(): Auto-update timestamp
  • View: t6_recent_memories for quick access to recent entries

Applying Migrations

  1. Open your Supabase project dashboard
  2. Navigate to SQL Editor
  3. Create a new query
  4. Copy and paste the contents of 001_init_vector_store.sql
  5. Click "Run" to execute

Method 2: psql Command Line

# Connect to your Supabase database
psql "postgresql://supabase_admin:PASSWORD@172.21.0.12:5432/postgres"

# Run the migration
\i migrations/supabase/001_init_vector_store.sql

Method 3: Programmatic Application

import psycopg2

# Connect to Supabase
conn = psycopg2.connect(
    "postgresql://supabase_admin:PASSWORD@172.21.0.12:5432/postgres"
)

# Read and execute migration
with open('migrations/supabase/001_init_vector_store.sql', 'r') as f:
    migration_sql = f.read()

with conn.cursor() as cur:
    cur.execute(migration_sql)
    conn.commit()

conn.close()

Verification

After applying the migration, verify the setup:

-- Check if pgvector extension is enabled
SELECT * FROM pg_extension WHERE extname = 'vector';

-- Check if table exists
\d t6_memories

-- Verify indexes
\di t6_memories*

-- Test the similarity search function
SELECT * FROM match_t6_memories(
    '[0.1, 0.2, ...]'::vector(1536),  -- Sample embedding
    10,                                -- Match count
    'test_user',                       -- User ID filter
    NULL,                              -- Agent ID filter
    NULL                               -- Run ID filter
);

-- Get memory statistics
SELECT * FROM get_t6_memory_stats();

Rollback

If you need to rollback the migration:

-- Drop view
DROP VIEW IF EXISTS t6_recent_memories;

-- Drop functions
DROP FUNCTION IF EXISTS get_t6_memory_stats();
DROP FUNCTION IF EXISTS match_t6_memories(vector, INT, TEXT, TEXT, TEXT);
DROP FUNCTION IF EXISTS update_t6_memories_updated_at();

-- Drop trigger
DROP TRIGGER IF EXISTS t6_memories_updated_at_trigger ON t6_memories;

-- Drop table (WARNING: This will delete all data!)
DROP TABLE IF EXISTS t6_memories CASCADE;

-- Optionally remove extension (only if not used elsewhere)
-- DROP EXTENSION IF EXISTS vector CASCADE;

Schema

t6_memories Table

Column Type Description
id UUID Primary key
embedding vector(1536) OpenAI embedding vector
metadata JSONB Flexible metadata
user_id TEXT User identifier
agent_id TEXT Agent identifier
run_id TEXT Run identifier
memory_text TEXT Original memory text
created_at TIMESTAMPTZ Creation timestamp
updated_at TIMESTAMPTZ Last update timestamp
hash TEXT Deduplication hash (unique)

Indexes

  • t6_memories_embedding_idx: HNSW index for fast vector search
  • t6_memories_user_id_idx: B-tree for user filtering
  • t6_memories_agent_id_idx: B-tree for agent filtering
  • t6_memories_run_id_idx: B-tree for run filtering
  • t6_memories_created_at_idx: B-tree for time-based queries
  • t6_memories_metadata_idx: GIN for JSON queries
  • t6_memories_text_search_idx: GIN for full-text search

Notes

  • The HNSW index provides O(log n) approximate nearest neighbor search
  • Cosine distance is used for similarity (1 - cosine similarity)
  • All timestamps are stored in UTC
  • The hash column ensures deduplication of identical memories
  • Metadata is stored as JSONB for flexible schema evolution

Support

For issues or questions about migrations, refer to: