-- Daily conversation summaries for improved RAG quality
-- Each row = one day's conversation with a contact, summarized by LLM and embedded

CREATE TABLE daily_conversation_summaries (
    id INTEGER PRIMARY KEY NOT NULL,
    date TEXT NOT NULL,              -- ISO date "2024-08-15"
    contact TEXT NOT NULL,            -- Contact name
    summary TEXT NOT NULL,            -- LLM-generated 3-5 sentence summary
    message_count INTEGER NOT NULL,   -- Number of messages in this day
    embedding BLOB NOT NULL,          -- 768-dim vector of the summary
    created_at BIGINT NOT NULL,       -- When this summary was generated
    model_version TEXT NOT NULL,      -- "nomic-embed-text:v1.5"
    UNIQUE(date, contact)
);

-- Indexes for efficient querying
CREATE INDEX idx_daily_summaries_date ON daily_conversation_summaries(date);
CREATE INDEX idx_daily_summaries_contact ON daily_conversation_summaries(contact);
CREATE INDEX idx_daily_summaries_date_contact ON daily_conversation_summaries(date, contact);
