Files
Celes Renata a72f336ad1 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.
2026-07-13 02:14:59 +00:00

66 lines
2.0 KiB
Python

"""Routing decision storage.
Stores every routing decision with the full feature snapshot for audit,
recalibration, and explainability. Backed by the v3_routing_decisions table.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from uuid import UUID
from services.intelligence_pipeline_v3.routing.router import RoutingDecision
@dataclass
class RoutingDecisionStore:
"""In-memory store for routing decisions.
In production, this would be backed by the ``v3_routing_decisions`` table.
This implementation provides the storage interface for use in the pipeline
orchestrator and for testing.
The store is append-only — decisions are immutable once stored.
"""
_decisions: list[RoutingDecision] = field(default_factory=list)
_by_pipeline_run: dict[UUID, list[RoutingDecision]] = field(default_factory=dict)
def store(self, decision: RoutingDecision) -> None:
"""Store a routing decision.
Parameters
----------
decision:
The routing decision to persist. Must have a unique id.
"""
self._decisions.append(decision)
run_decisions = self._by_pipeline_run.setdefault(
decision.pipeline_run_id, []
)
run_decisions.append(decision)
def get_by_pipeline_run(self, run_id: UUID) -> list[RoutingDecision]:
"""Retrieve all routing decisions for a pipeline run.
Parameters
----------
run_id:
The pipeline run identifier.
Returns
-------
list[RoutingDecision]
All decisions for the given run, in insertion order.
Returns empty list if no decisions exist for the run.
"""
return list(self._by_pipeline_run.get(run_id, []))
def get_all(self) -> list[RoutingDecision]:
"""Retrieve all stored decisions in insertion order."""
return list(self._decisions)
def count(self) -> int:
"""Return the total number of stored decisions."""
return len(self._decisions)