feat: add entity-relationship knowledge memory to agentic insights
Implements persistent cross-photo knowledge memory so the agentic
insight loop can learn and recall facts about people, places, and
events across the photo collection.
Changes:
- photo_insights: drop UNIQUE(file_path) + INSERT OR REPLACE, replace
with append-only rows + is_current flag for insight history retention
- New tables: entities, entity_facts, entity_photo_links with FK
constraints and confidence scoring
- KnowledgeDao trait + SqliteKnowledgeDao with upsert, merge, and
corroboration (confidence +0.1 on duplicate fact detection)
- Four new agent tools: recall_entities, recall_facts_for_photo,
store_entity, store_fact (with object_entity_id FK support)
- Cameron entity auto-seeded with stable ID injected into system prompt
- Pre-run photo link clearing + post-loop source_insight_id backfill
- Audit REST API: GET/PATCH/DELETE /knowledge/entities/{id},
POST /knowledge/entities/merge, GET/PATCH/DELETE /knowledge/facts/{id},
GET /knowledge/recent
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
25
migrations/2026-04-02-000000_photo_insights_history/up.sql
Normal file
25
migrations/2026-04-02-000000_photo_insights_history/up.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Convert photo_insights to an append-only history table.
|
||||
-- SQLite cannot drop a UNIQUE constraint via ALTER TABLE, so we recreate the table.
|
||||
-- This preserves existing insight IDs so that future entity_facts.source_insight_id
|
||||
-- FK references remain valid.
|
||||
|
||||
CREATE TABLE photo_insights_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
file_path TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
summary TEXT NOT NULL,
|
||||
generated_at BIGINT NOT NULL,
|
||||
model_version TEXT NOT NULL,
|
||||
is_current BOOLEAN NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
-- Migrate existing rows; mark them all as current (one row per path currently).
|
||||
INSERT INTO photo_insights_new (id, file_path, title, summary, generated_at, model_version, is_current)
|
||||
SELECT id, file_path, title, summary, generated_at, model_version, 1
|
||||
FROM photo_insights;
|
||||
|
||||
DROP TABLE photo_insights;
|
||||
ALTER TABLE photo_insights_new RENAME TO photo_insights;
|
||||
|
||||
CREATE INDEX idx_photo_insights_file_path ON photo_insights(file_path);
|
||||
CREATE INDEX idx_photo_insights_current ON photo_insights(file_path, is_current);
|
||||
Reference in New Issue
Block a user