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
+24
View File
@@ -10,6 +10,9 @@ Data model — see ``.agent/PLAN.md`` §Data Model:
the deflection decision, and latency.
* ``steering_notes`` — owner tuning notes injected into the system prompt
of every chat turn (phase 15, ``<tuning>`` section).
* ``kb_overview`` — single-row lite-generated outline of the KB's basic
categories, injected as the ``<knowledge_base>``
section of every chat turn (phase 31).
"""
from __future__ import annotations
@@ -109,3 +112,24 @@ class SteeringNote(Base):
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
note: Mapped[str] = mapped_column(Text) # trimmed, 1–2000 chars (API-enforced)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
class KbOverview(Base):
"""Single-row, lite-generated outline of the knowledge base (phase 31).
Exactly one row (``id = 1``, enforced by the migration 0005 server
defaults) holds a plain-text outline of the KB's basic categories,
generated by the aipi ``lite`` model whenever an import changes the KB.
Chat turns only read this row (one indexed PK lookup) and inject it into
the system prompt of every turn as the ``<knowledge_base>`` section — an
empty row means the section is absent and the prompt stays
byte-identical to the pre-phase text (phase 15 convention).
"""
__tablename__ = "kb_overview"
id: Mapped[int] = mapped_column(Integer, primary_key=True, server_default="1")
content: Mapped[str] = mapped_column(Text, server_default="") # the outline text
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now()
)