nordabiz/database/migrations/092_ai_user_memory.sql
Maciej Pienczyn f953648c7d feat(nordagpt): add memory tables and ORM models
- Migration 092: ai_user_memory (per-user facts with expiry)
- Migration 093: ai_conversation_summary (auto-generated summaries)
- SQLAlchemy models: AIUserMemory, AIConversationSummary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 05:44:30 +01:00

21 lines
904 B
SQL

-- 092_ai_user_memory.sql
-- Persistent memory for NordaGPT — per-user facts extracted from conversations
CREATE TABLE IF NOT EXISTS ai_user_memory (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
fact TEXT NOT NULL,
category VARCHAR(50) DEFAULT 'general',
source_conversation_id INTEGER REFERENCES ai_chat_conversations(id) ON DELETE SET NULL,
confidence FLOAT DEFAULT 1.0,
created_at TIMESTAMP DEFAULT NOW(),
expires_at TIMESTAMP DEFAULT (NOW() + INTERVAL '12 months'),
is_active BOOLEAN DEFAULT TRUE
);
CREATE INDEX idx_ai_user_memory_user_active ON ai_user_memory(user_id, is_active, confidence DESC);
CREATE INDEX idx_ai_user_memory_expires ON ai_user_memory(expires_at) WHERE is_active = TRUE;
GRANT ALL ON TABLE ai_user_memory TO nordabiz_app;
GRANT USAGE, SELECT ON SEQUENCE ai_user_memory_id_seq TO nordabiz_app;