Persist frame captions in canonical database

This commit is contained in:
Sleeps
2026-10-06 13:58:45 +01:00
parent 26e2054dc0
commit 7ec99eaf26
+16
View File
@@ -32,6 +32,9 @@ CREATE TABLE IF NOT EXISTS frames (
timestamp_ms INTEGER NOT NULL,
thumb_path TEXT NOT NULL,
embedding_f16 BLOB NOT NULL,
caption TEXT,
caption_model TEXT,
captioned_at TEXT,
UNIQUE(media_id, frame_number)
);
@@ -52,9 +55,22 @@ def connect(path: Path) -> Iterator[sqlite3.Connection]:
con.close()
def _ensure_frame_caption_columns(con: sqlite3.Connection) -> None:
columns = {row["name"] for row in con.execute("PRAGMA table_info(frames)")}
additions = {
"caption": "TEXT",
"caption_model": "TEXT",
"captioned_at": "TEXT",
}
for name, sql_type in additions.items():
if name not in columns:
con.execute(f"ALTER TABLE frames ADD COLUMN {name} {sql_type}")
def init_db(path: Path) -> None:
with connect(path) as con:
con.executescript(SCHEMA)
_ensure_frame_caption_columns(con)
def pack_vector(vector: np.ndarray) -> bytes: