@@ -226,12 +226,91 @@ CREATE TABLE truncated_outputs (
226226 FOREIGN KEY (observation_id) REFERENCES observations(id) ON DELETE CASCADE
227227);
228228
229- -- Full-text search index
229+ -- Structured observations (AI/heuristic structured metadata)
230+ CREATE TABLE structured_observations (
231+ id INTEGER PRIMARY KEY AUTOINCREMENT,
232+ session_id TEXT NOT NULL ,
233+ project TEXT NOT NULL ,
234+ type TEXT NOT NULL
235+ CHECK (type IN (' bugfix' , ' feature' , ' refactor' , ' change' , ' discovery' , ' decision' )),
236+ title TEXT NOT NULL ,
237+ subtitle TEXT ,
238+ facts TEXT , -- JSON array of strings
239+ narrative TEXT , -- Brief description (1-2 sentences)
240+ concepts TEXT , -- JSON array: how-it-works, why-it-exists, etc.
241+ files_read TEXT , -- JSON array of file paths
242+ files_modified TEXT , -- JSON array of file paths
243+ content_hash TEXT NOT NULL ,
244+ discovery_tokens INTEGER DEFAULT 0 ,
245+ raw_observation_id INTEGER ,
246+ source TEXT DEFAULT ' ai' -- 'ai', 'heuristic', 'manual'
247+ CHECK (source IN (' ai' , ' heuristic' , ' manual' )),
248+ model TEXT , -- 'kimi-k2.5', 'heuristic', etc.
249+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
250+ FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE ,
251+ FOREIGN KEY (raw_observation_id) REFERENCES observations(id) ON DELETE SET NULL ,
252+ UNIQUE(session_id, content_hash)
253+ );
254+
255+ -- Soft dedup links between structured observations and raw observations
256+ CREATE TABLE structured_observation_links (
257+ id INTEGER PRIMARY KEY AUTOINCREMENT,
258+ existing_structured_id INTEGER NOT NULL ,
259+ linked_raw_observation_id INTEGER ,
260+ content_hash TEXT NOT NULL ,
261+ link_type TEXT DEFAULT ' soft' CHECK (link_type IN (' soft' , ' hard' )),
262+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
263+ FOREIGN KEY (existing_structured_id) REFERENCES structured_observations(id) ON DELETE CASCADE ,
264+ FOREIGN KEY (linked_raw_observation_id) REFERENCES observations(id) ON DELETE CASCADE
265+ );
266+
267+ -- Vector sync state (watermark-based)
268+ CREATE TABLE vec_sync_state (
269+ id INTEGER PRIMARY KEY CHECK (id = 1 ),
270+ last_synced_id INTEGER DEFAULT 0 ,
271+ synced_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
272+ );
273+
274+ -- Knowledge collections
275+ CREATE TABLE observation_collections (
276+ id INTEGER PRIMARY KEY AUTOINCREMENT,
277+ name TEXT UNIQUE NOT NULL ,
278+ description TEXT ,
279+ project TEXT ,
280+ query TEXT ,
281+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
282+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
283+ );
284+
285+ -- Collection items
286+ CREATE TABLE collection_items (
287+ id INTEGER PRIMARY KEY AUTOINCREMENT,
288+ collection_id INTEGER NOT NULL ,
289+ observation_id INTEGER NOT NULL ,
290+ item_type TEXT DEFAULT ' structured' CHECK (item_type IN (' structured' , ' raw' )),
291+ added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
292+ FOREIGN KEY (collection_id) REFERENCES observation_collections(id) ON DELETE CASCADE ,
293+ FOREIGN KEY (observation_id) REFERENCES structured_observations(id) ON DELETE CASCADE ,
294+ UNIQUE(collection_id, observation_id)
295+ );
296+
297+ -- Full-text search index (raw observations)
230298CREATE VIRTUAL TABLE observations_fts USING fts5(
231299 content= ' observations' ,
232300 content_rowid= ' id' ,
233301 tool_name, tool_input, tool_output
234302);
303+
304+ -- Full-text search index (structured observations)
305+ CREATE VIRTUAL TABLE structured_observations_fts USING fts5(
306+ title,
307+ subtitle,
308+ narrative,
309+ facts,
310+ concepts,
311+ content= ' structured_observations' ,
312+ content_rowid= ' id'
313+ );
235314```
236315
237316### sqlite-vec Vector DB
0 commit comments