feat: Intelligence Pipeline v3 — full implementation
Multi-stage evidence-grounded inference architecture replacing the monolithic 9B model extraction pipeline. CPU-first specialist services handle routine extraction while the 9B vLLM model is preserved for semantic adjudication of ambiguous cases. Key components: - Capability-aware inference gateway (OpenAI-compatible + Ollama) - Endpoint registry with DB migrations and REST API - Sentence-aware document segmenter (property tests) - Deterministic financial parsing with offset integrity - Symbol resolution with ambiguity detection - Specialist service (GLiNER2, dynamic batching, K8s deployment) - Company-specific sentiment (FinBERT, calibration) - Retrieval-based novelty and duplicate detection - Confidence calibration pipeline - Deterministic routing engine (property tests) - 9B adjudication layer with VRAM gating - Stock-specific impact model (features, labels, baseline, trained) - Pipeline orchestrator (state machine, queues, leases, feature flags) - Bounded parallelism (async workers, semaphore, load shedding) - Observability (tracing, metrics, alerts) - Compatibility adapter (v3→v2 golden mapping tests) - Shadow/canary promotion framework - Active learning and fine-tuning pipeline Test results: 1,161 tests pass, ruff lint clean. All 282 spec tasks completed.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""Pydantic models for parsed financial candidates."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class CandidateType(str, Enum):
|
||||
"""Types of financial entities detected by the deterministic parser."""
|
||||
|
||||
TICKER = "ticker"
|
||||
CURRENCY = "currency"
|
||||
MONEY = "money"
|
||||
PERCENTAGE = "percentage"
|
||||
BASIS_POINTS = "basis_points"
|
||||
RANGE = "range"
|
||||
EPS = "eps"
|
||||
REVENUE = "revenue"
|
||||
DATE = "date"
|
||||
FISCAL_PERIOD = "fiscal_period"
|
||||
|
||||
|
||||
class PeriodAnnotation(BaseModel):
|
||||
"""Optional period context for a parsed candidate (e.g., Q1, FY2025)."""
|
||||
|
||||
period_type: str = Field(description="Type: quarter, year, fiscal_year, half")
|
||||
period_value: str = Field(description="Normalized period: Q1, Q2, H1, FY")
|
||||
year: int | None = Field(default=None, description="Calendar or fiscal year")
|
||||
|
||||
|
||||
class ParsedCandidate(BaseModel):
|
||||
"""A single parsed financial entity with source offset and normalization.
|
||||
|
||||
Stores both the literal text as it appeared in the source document and the
|
||||
normalized numeric value (if applicable). Exact character offsets allow
|
||||
downstream evidence linking back to the source.
|
||||
"""
|
||||
|
||||
candidate_type: CandidateType = Field(description="Classification of the parsed entity")
|
||||
literal_value: str = Field(min_length=1, description="Exact text as it appears in source")
|
||||
normalized_value: float | None = Field(default=None, description="Normalized numeric value")
|
||||
unit: str | None = Field(default=None, description="Unit: USD, EUR, %, bps, etc.")
|
||||
start_char: int = Field(ge=0, description="Start character offset in source text")
|
||||
end_char: int = Field(gt=0, description="End character offset in source text (exclusive)")
|
||||
period: PeriodAnnotation | None = Field(default=None, description="Optional fiscal/calendar period")
|
||||
Reference in New Issue
Block a user