Foundation (phase 01, verified): - FastAPI app: /api/health, /api/suggestions, /api/chat (placeholder), static frontend served locally (no CDN) - Postgres 17 + pgvector via db/Containerfile + compose.yaml (podman compose up -d db), Alembic initial migration (documents, chunks with vector(768), query_log) - LLM client targeting https://aipi.reeseapps.com/v1 (turbo/embed); scripts/llm_probe.py verified models + 768-dim embeddings live - Conditional debugpy: imported only when DEBUGPY=1 (attach on demand, :5678); logging config for clean single-line logs - Frontend shell: mobile-first chat + Sources pages, tokens, a11y baselines - Tests: 24 unit+integration (99% coverage on app/), ruff + pyright clean, Playwright smoke E2E (3 tests) against a deterministic mock LLM - Planning: .agent/PLAN.md (architecture + LOCKED decisions), AGENTS.md, 6 user stories, 7 phase files (one story / one phase / one Playwright suite each)
87 lines
3.0 KiB
Python
87 lines
3.0 KiB
Python
"""initial schema: documents, chunks (pgvector), query_log
|
|
|
|
Revision ID: 0001
|
|
Revises:
|
|
Create Date: 2026-08-21
|
|
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy as sa
|
|
from pgvector.sqlalchemy import Vector
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
from alembic import op
|
|
|
|
EMBEDDING_DIM = 768 # keep in sync with app/models.py (PLAN anchor A6)
|
|
|
|
revision = "0001"
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute("CREATE EXTENSION IF NOT EXISTS vector")
|
|
|
|
op.create_table(
|
|
"documents",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
|
sa.Column("source", sa.String(120), nullable=False),
|
|
sa.Column("path", sa.String(1000), nullable=False),
|
|
sa.Column("full_path", sa.String(2000), nullable=False),
|
|
sa.Column("title", sa.String(500), nullable=False),
|
|
sa.Column("content", sa.Text(), nullable=False),
|
|
sa.Column("content_hash", sa.String(64), nullable=False),
|
|
sa.Column(
|
|
"indexed_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.func.now(),
|
|
nullable=False,
|
|
),
|
|
sa.UniqueConstraint("source", "path", name="uq_documents_source_path"),
|
|
)
|
|
op.create_index("ix_documents_source", "documents", ["source"])
|
|
op.create_index("ix_documents_path", "documents", ["path"])
|
|
op.create_index("ix_documents_content_hash", "documents", ["content_hash"])
|
|
|
|
op.create_table(
|
|
"chunks",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
|
sa.Column(
|
|
"document_id",
|
|
postgresql.UUID(as_uuid=True),
|
|
sa.ForeignKey("documents.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("position", sa.Integer(), nullable=False),
|
|
sa.Column("content", sa.Text(), nullable=False),
|
|
sa.Column("embedding", Vector(EMBEDDING_DIM), nullable=True),
|
|
)
|
|
op.create_index("ix_chunks_document_id", "chunks", ["document_id"])
|
|
|
|
op.create_table(
|
|
"query_log",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
|
sa.Column("question", sa.Text(), nullable=False),
|
|
sa.Column("top_score", sa.Float(), nullable=False, server_default="0"),
|
|
sa.Column("chunk_hits", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.Column("deflected", sa.Boolean(), nullable=False, server_default=sa.false()),
|
|
sa.Column("sources", sa.Text(), nullable=False, server_default=""),
|
|
sa.Column("latency_ms", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.func.now(),
|
|
nullable=False,
|
|
),
|
|
)
|
|
op.create_index("ix_query_log_created_at", "query_log", ["created_at"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("query_log")
|
|
op.drop_table("chunks")
|
|
op.drop_table("documents")
|
|
op.execute("DROP EXTENSION IF EXISTS vector")
|