Store timestamps as UTC-aware and slim the knowledge context to headlines
タイムゾーン: SQLite の DATETIME は tzinfo を保存できず、DateTime(timezone=True) を 指定してもバインド時に捨てられるため、API のレスポンスがオフセット無しの ISO 文字列になりフロントがローカル時刻として誤解していた。UtcDateTime (TypeDecorator) を追加し、書き込み時は naive な UTC に正規化、読み出し時は UTC の aware として返すようにする。格納フォーマットは変わらないので既存 データはそのまま正しく解釈でき、マイグレーションは不要。 コンテナは TZ 未設定で UTC だったため、天気通知の cron 時刻・深夜スキップ 判定・「明日」の日付計算が9時間ずれていた。TZ=Asia/Tokyo を指定し、slim イメージに無い tzdata を導入する。 蓄積知識: 層1が最新15件の要約全文を毎リクエスト無条件に注入しており、同じ内容が ローカルKB(層3)にも保存されているため重複していた。層1を「クエリ+ 一行要約」の目次に変え、本文は read_knowledge ツールで読み出す形にする。 一行要約は要約生成時の既存 LLM 呼び出しに相乗りするので呼び出し回数は 増えない。headline を持たない既存エントリは本文の先頭行から導出する。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,14 +18,22 @@ def get_db():
|
||||
db.close()
|
||||
|
||||
|
||||
# 既存DBに後から追加されたカラム: (テーブル名, カラム名, 型)
|
||||
_ADDED_COLUMNS = [
|
||||
("note_pages", "section", "VARCHAR"),
|
||||
("knowledge_entries", "headline", "VARCHAR"),
|
||||
]
|
||||
|
||||
|
||||
def _add_missing_columns() -> None:
|
||||
"""マイグレーションフレームワークを使っていないため、既存DBに後から追加されたカラムを
|
||||
ここで簡易的に補う。create_all() は既存テーブルへのカラム追加は行わないので必要。"""
|
||||
with engine.connect() as conn:
|
||||
existing = {row[1] for row in conn.execute(text("PRAGMA table_info(note_pages)"))}
|
||||
if existing and "section" not in existing:
|
||||
conn.execute(text("ALTER TABLE note_pages ADD COLUMN section VARCHAR"))
|
||||
conn.commit()
|
||||
for table, column, column_type in _ADDED_COLUMNS:
|
||||
existing = {row[1] for row in conn.execute(text(f"PRAGMA table_info({table})"))}
|
||||
if existing and column not in existing:
|
||||
conn.execute(text(f"ALTER TABLE {table} ADD COLUMN {column} {column_type}"))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def init_db():
|
||||
|
||||
Reference in New Issue
Block a user