# Open Brain: Vendor-Agnostic Memory Architecture

Category: Memory & Storage
Stack: PostgreSQL, pgvector, Supabase, MCP

## Overview
Treating raw text as permanent relational records and vector embeddings as disposable derivatives, enabling zero-loss re-indexing.

## The Problem
SaaS second-brain systems bind raw content directly to vendor-specific embedding models. Upgrading embedding models requires destructive re-architecting or lock-in.

## Production Rule
Treat raw text as permanent and embeddings as disposable. Store raw notes in relational tables and vector embeddings in a secondary table linked by foreign keys, enabling zero-loss re-indexing.

## Code / Specification
File: `schema_open_brain.sql`

```sql ddl
-- Source records: Permanent relational store
CREATE TABLE documents (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    title TEXT NOT NULL,
    content TEXT NOT NULL,
    source_url TEXT,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Embeddings store: Disposable and regeneratable
CREATE TABLE document_embeddings (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    document_id UUID REFERENCES documents(id) ON DELETE CASCADE,
    chunk_index INT NOT NULL,
    chunk_content TEXT NOT NULL,
    embedding vector(1536),
    embedding_model TEXT NOT NULL,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX ON document_embeddings USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
```
