File size: 1,349 Bytes
1acea00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- ── Run this once in your Supabase SQL editor ──────────────────────
-- Two tables only. No chat_history table β€” raw messages live in
-- session_state; only distilled knowledge is persisted.

-- Per-paper memory: corrections, self-revisions, established facts,
-- and compressed conversation summaries (sliding window).
CREATE TABLE IF NOT EXISTS memory_paper (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    paper_id    TEXT NOT NULL,
    type        TEXT NOT NULL,   -- 'correction' | 'self_revision' | 'established_fact' | 'conversation_summary'
    content     TEXT NOT NULL,
    turn_range  TEXT,            -- e.g. "1-5" β€” which turns this summary covers
    created_at  TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_memory_paper_paper_id ON memory_paper(paper_id);
CREATE INDEX IF NOT EXISTS idx_memory_paper_type     ON memory_paper(type);

-- Global user memory: expertise signals and style preferences
-- that carry across all papers.
CREATE TABLE IF NOT EXISTS memory_user (
    id         UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    type       TEXT NOT NULL,   -- 'expertise_signal' | 'style_preference'
    content    TEXT NOT NULL,
    created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_memory_user_type ON memory_user(type);