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.
34 lines
1.7 KiB
Python
34 lines
1.7 KiB
Python
"""Pydantic models for document chunks produced by the segmenter."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
|
|
from pydantic import BaseModel, Field, computed_field
|
|
|
|
|
|
class DocumentChunk(BaseModel):
|
|
"""A contiguous text segment of a source document with offset metadata.
|
|
|
|
The chunk preserves exact source character offsets so that downstream
|
|
evidence spans can always be mapped back to the original document text.
|
|
"""
|
|
|
|
chunk_id: str = Field(description="Deterministic ID: {document_id}:{start_char}")
|
|
document_id: str = Field(description="Parent document identifier")
|
|
document_type: str = Field(description="Type of document: article, filing, transcript, macro_event")
|
|
section_path: list[str] = Field(default_factory=list, description="Hierarchical section/heading path")
|
|
speaker: str | None = Field(default=None, description="Speaker label for transcript chunks")
|
|
start_char: int = Field(ge=0, description="Start character offset in source document")
|
|
end_char: int = Field(gt=0, description="End character offset in source document (exclusive)")
|
|
text: str = Field(min_length=1, description="Chunk text content")
|
|
overlap_left: int = Field(default=0, ge=0, description="Characters of overlap with previous chunk")
|
|
overlap_right: int = Field(default=0, ge=0, description="Characters of overlap with next chunk")
|
|
boilerplate_score: float = Field(default=0.0, ge=0.0, le=1.0, description="Boilerplate likelihood 0.0-1.0")
|
|
|
|
@computed_field # type: ignore[prop-decorator]
|
|
@property
|
|
def checksum(self) -> str:
|
|
"""SHA-256 hex digest of the chunk text."""
|
|
return hashlib.sha256(self.text.encode("utf-8")).hexdigest()
|