waxwing/app/models/schemas/knowledge.py
pyr0ball 5f5cb99db6 feat: bootstrap Waxwing Phase 1 scaffold
Plant registry, grow event calendar, and gardening knowledge base
populated via cf-harvest ingest endpoint. All 23 tests passing.

Stack:
- FastAPI + SQLite (cf-core migrations) on port 8522
- Vue 3 + Vite + Pinia SPA on port 8521
- 5 SQL migrations: locations → plants → grow_events, knowledge_sources → knowledge_facts
- Earthy green theme (--color-primary: #4a7c59) matching CF theme system

Knowledge ingest contract:
- POST /api/v1/knowledge/ingest — idempotent on fact_hash (sha256 of type+payload+video_path)
- 8 fact types: companion_planting, soil_amendment, propagation, pest_diagnosis,
  harvest_timing, instruction, medicinal, history_context
- Partial batch failure: malformed facts collected in rejected[], valid facts inserted
- Re-ingesting same video batch: facts_skipped_duplicate > 0, no duplicates

Wired views: RegistryView (plant CRUD), KnowledgeView (facts + type filter chips)
Stub views: CalendarView, SettingsView
2026-06-10 00:03:41 -07:00

68 lines
1.5 KiB
Python

"""Pydantic schemas for the cf-harvest knowledge ingest contract."""
from __future__ import annotations
from typing import Any, Literal, Optional
from pydantic import BaseModel, field_validator
FactType = Literal[
"companion_planting",
"soil_amendment",
"propagation",
"pest_diagnosis",
"harvest_timing",
"instruction",
"medicinal",
"history_context",
]
class KnowledgeSourceSpec(BaseModel):
video_path: str
presenter: Optional[str] = None
location: Optional[str] = None
source_domain: Optional[str] = "gardening"
class SegmentKnowledge(BaseModel):
"""One extracted fact from cf-harvest."""
fact_type: FactType
confidence: float = 1.0
payload: dict[str, Any]
@field_validator("confidence")
@classmethod
def clamp_confidence(cls, v: float) -> float:
return max(0.0, min(1.0, v))
class KnowledgeIngestRequest(BaseModel):
source: KnowledgeSourceSpec
facts: list[SegmentKnowledge]
class RejectedFact(BaseModel):
index: int
reason: str
class IngestResponse(BaseModel):
source_id: int
video_path: str
facts_received: int
facts_inserted: int
facts_skipped_duplicate: int
rejected: list[RejectedFact] = []
class KnowledgeFactOut(BaseModel):
id: int
source_id: int
fact_type: str
subject: Optional[str]
payload: dict[str, Any]
presenter: Optional[str]
confidence: Optional[float]
fact_hash: str
created_at: str
video_path: Optional[str] = None
location: Optional[str] = None