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:
Celes Renata
2026-07-13 02:14:59 +00:00
parent 84634a365e
commit a72f336ad1
227 changed files with 50403 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
"""Request/response schemas for the specialist inference service.
Re-exports from models.py for discoverability, plus BatchConfig for
deployment configuration.
"""
from __future__ import annotations
from pydantic import BaseModel, Field
from services.specialist.models import (
MODEL_VERSION,
SCHEMA_VERSION,
BatchResponse,
ClassificationRequest,
ClassificationResult,
EntityResult,
ExtractionRequest,
RelationResult,
StructuredResult,
)
__all__ = [
"BatchConfig",
"BatchResponse",
"ClassificationRequest",
"ClassificationResult",
"EntityResult",
"ExtractionRequest",
"MODEL_VERSION",
"RelationResult",
"SCHEMA_VERSION",
"SpanResult",
"StructuredResult",
]
class SpanResult(BaseModel):
"""Generic span result used across extraction types."""
text: str
start_char: int
end_char: int
label: str
score: float = Field(..., ge=0.0, le=1.0)
model_version: str = MODEL_VERSION
schema_version: str = SCHEMA_VERSION
class BatchConfig(BaseModel):
"""Configuration for dynamic batching behavior."""
max_batch_size: int = Field(default=32, ge=1, le=512, description="Maximum items per batch")
max_wait_ms: float = Field(default=50.0, ge=1.0, le=5000.0, description="Maximum wait time before flushing a partial batch (ms)")
max_queue_size: int = Field(default=256, ge=1, le=10000, description="Maximum pending requests in queue before rejection")
warm_up_on_start: bool = Field(default=True, description="Whether to run a warm-up inference on startup")