feat(rag): lite-generated KB overview in the system prompt — stored single row, regenerated on import, <knowledge_base> section in HIGH+LOW prompts

This commit is contained in:
2026-08-25 20:22:51 -04:00
parent 572a4190a6
commit 0654b304e1
23 changed files with 2276 additions and 34 deletions
+12 -10
View File
@@ -3,14 +3,15 @@
Drives the **real Alembic engine** against the live dev database
(``podman compose up -d db``), mirroring the style of
``test_migration_0002.py`` (information_schema assertions on the state the
migration must leave):
migration must leave). The tests target revision ``0004`` explicitly so
later migrations (0005, …) cannot break them:
* upgrade to head → ``documents.summary`` (TEXT, nullable) and
* upgrade 0003 → 0004 → ``documents.summary`` (TEXT, nullable) and
``chunks.is_summary`` (BOOLEAN NOT NULL, default false) both exist, and a
chunk inserted without the column gets ``is_summary = false`` (pre-0004
insert paths stay valid);
* downgrade to 0003 → both columns are gone;
* upgrade to head again → both are back (round-trip).
* upgrade 0003 → 0004 again → both are back (round-trip).
The ``alembic`` fixture guarantees the DB ends at head even if a test
fails or the process is interrupted.
@@ -65,13 +66,13 @@ def _version(db: Session) -> str | None:
return db.execute(text("SELECT version_num FROM alembic_version")).scalar()
def test_upgrade_to_head_adds_summary_columns(db: Session, alembic: Config) -> None:
"""Upgrade to head: both columns exist with the locked types/defaults."""
def test_upgrade_to_0004_adds_summary_columns(db: Session, alembic: Config) -> None:
"""Upgrade 0003 → 0004: both columns exist with the locked types/defaults."""
command.downgrade(alembic, "0003") # start from the pre-0004 state
assert _version(db) == "0003"
command.upgrade(alembic, "head")
assert _version(db) == "0004", "alembic_version must be at 0004 (head)"
command.upgrade(alembic, "0004")
assert _version(db) == "0004", "alembic_version must be at 0004"
summary = _column(db, "documents", "summary")
assert summary is not None, "documents.summary is missing"
@@ -130,9 +131,10 @@ def test_downgrade_to_0003_removes_columns(db: Session, alembic: Config) -> None
def test_upgrade_round_trip_restores_columns(db: Session, alembic: Config) -> None:
"""Upgrade back to head after the downgrade: both columns are back."""
command.upgrade(alembic, "head")
assert _version(db) == "0004", "round-trip upgrade must land at 0004 (head)"
"""Downgrade to 0003, then upgrade 0003 → 0004: both columns are back."""
command.downgrade(alembic, "0003")
command.upgrade(alembic, "0004")
assert _version(db) == "0004", "round-trip upgrade must land at 0004"
summary = _column(db, "documents", "summary")
assert summary is not None and summary[1] == "YES", "documents.summary must be back"