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,69 @@
|
||||
"""Lineage recording for inference results.
|
||||
|
||||
Extracts persistence fields from InferenceResult so that actual endpoint,
|
||||
model, and route lineage are recorded — fixing the hardcoded
|
||||
``model_provider = 'ollama'`` pattern.
|
||||
|
||||
Requirements: 2.9, 13.6
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from services.shared.inference.models import InferenceResult, ModelLineage
|
||||
|
||||
|
||||
def build_lineage_from_result(result: InferenceResult, trace_id: str = "") -> ModelLineage:
|
||||
"""Extract a ModelLineage record from an InferenceResult.
|
||||
|
||||
This replaces hardcoded ``model_provider = 'ollama'`` persistence
|
||||
by capturing the actual endpoint, deployment, model, protocol,
|
||||
structured mode, request ID, latency, and retries from the result.
|
||||
|
||||
Args:
|
||||
result: The completed inference result.
|
||||
trace_id: Optional distributed trace ID for correlation.
|
||||
|
||||
Returns:
|
||||
A ModelLineage with all required persistence fields.
|
||||
"""
|
||||
return ModelLineage(
|
||||
endpoint_id=result.endpoint_id,
|
||||
deployment_id=result.deployment_id,
|
||||
model=result.model,
|
||||
protocol=result.protocol,
|
||||
structured_mode=result.structured_mode,
|
||||
request_id=result.request_id,
|
||||
latency_ms=result.latency_ms,
|
||||
retries=result.retries,
|
||||
trace_id=trace_id,
|
||||
)
|
||||
|
||||
|
||||
def lineage_to_persistence_dict(lineage: ModelLineage) -> dict:
|
||||
"""Convert a ModelLineage to a flat dict for database persistence.
|
||||
|
||||
Returns fields suitable for inserting into agent_performance_log,
|
||||
document_intelligence, or similar tables.
|
||||
|
||||
The ``model_provider`` field is derived from the protocol:
|
||||
- ``ollama_native`` → ``"ollama"``
|
||||
- ``openai_chat`` → ``"openai_compatible"`` (covers vLLM, OpenAI, etc.)
|
||||
- ``specialist_http`` → ``"specialist"``
|
||||
"""
|
||||
protocol_to_provider = {
|
||||
"ollama_native": "ollama",
|
||||
"openai_chat": "openai_compatible",
|
||||
"specialist_http": "specialist",
|
||||
}
|
||||
|
||||
return {
|
||||
"model_provider": protocol_to_provider.get(lineage.protocol, lineage.protocol),
|
||||
"model_name": lineage.model,
|
||||
"endpoint_id": str(lineage.endpoint_id) if lineage.endpoint_id else None,
|
||||
"deployment_id": str(lineage.deployment_id) if lineage.deployment_id else None,
|
||||
"protocol": lineage.protocol,
|
||||
"structured_mode": lineage.structured_mode,
|
||||
"request_id": lineage.request_id,
|
||||
"latency_ms": lineage.latency_ms,
|
||||
"retries": lineage.retries,
|
||||
"trace_id": lineage.trace_id,
|
||||
}
|
||||
Reference in New Issue
Block a user