feat(ingestion): extend domain types, ports, and configuration for ingestion pipeline
- Add ExtractedBlock, ExtractionEnvelope, and StagedDocument data models in types.py - Define ingestion repository, file store, vision, and extraction ports in ports.py - Extend IngestionSettings with limits, policies, vision, and embedding configuration - Update database compatibility verification to support worker and review schema revisions - Add PyMuPDF, Pillow, defusedxml, and tiktoken dependencies to pyproject.toml
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""Ports only; concrete intake, embedding and publication arrive in later phases."""
|
||||
"""Provider-neutral ports; publication arrives in a later phase."""
|
||||
from typing import Mapping, Protocol, Sequence
|
||||
from uuid import UUID
|
||||
|
||||
from .types import EmbeddingProfile
|
||||
from .types import EmbeddingProfile, ExtractedBlock, ExtractionEnvelope
|
||||
|
||||
|
||||
class FileStore(Protocol):
|
||||
@@ -12,12 +12,30 @@ class FileStore(Protocol):
|
||||
|
||||
def read(self, storage_key: str) -> bytes: ...
|
||||
|
||||
def inventory(self) -> Mapping[str, Sequence[str]]:
|
||||
"""Report originals, temporary_files and unexpected_entries; never delete."""
|
||||
...
|
||||
|
||||
def discard_unused(self, storage_key: str) -> None:
|
||||
"""Delete this request's candidate only after a confirmed unused outcome.
|
||||
|
||||
Ambiguous commit outcomes must retain it for report-only reconciliation.
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
class EmbeddingProvider(Protocol):
|
||||
@property
|
||||
def profile(self) -> EmbeddingProfile: ...
|
||||
|
||||
def embed(self, texts: Sequence[str]) -> Sequence[Sequence[float]]: ...
|
||||
@property
|
||||
def request_policy(self) -> Mapping[str, object]:
|
||||
"""Secret-free, endpoint-specific frozen request limits and capabilities."""
|
||||
...
|
||||
|
||||
def embed(self, texts: Sequence[str]) -> Sequence[Sequence[float]]:
|
||||
"""One validated batch, input order restored; no internal retries."""
|
||||
...
|
||||
|
||||
|
||||
class DocumentRepository(Protocol):
|
||||
@@ -28,3 +46,31 @@ class DocumentRepository(Protocol):
|
||||
def get_enabled_administrator(self, user_id: UUID) -> Mapping[str, object] | None:
|
||||
"""Resolve scope from a trusted operator's persisted administrator identity."""
|
||||
...
|
||||
|
||||
|
||||
class ExtractionProvider(Protocol):
|
||||
def extract(self, *, document_id: UUID, title: str, original_sha256: str,
|
||||
content: bytes, mime_type: str, processing_profile: Mapping[str, object]) -> ExtractionEnvelope:
|
||||
"""Faithful ordered evidence; no native responses escape."""
|
||||
...
|
||||
|
||||
|
||||
class VisionProvider(Protocol):
|
||||
def transcribe(self, image: bytes, *, page: int | None, section: str | None,
|
||||
processing_profile: Mapping[str, object]) -> Sequence[ExtractedBlock]: ...
|
||||
|
||||
|
||||
class IntakeRepository(Protocol):
|
||||
def lookup(self, settings, administrator_id: UUID, request_id: UUID):
|
||||
"""Short transaction: embedding compatibility, locked admin, scoped key."""
|
||||
...
|
||||
|
||||
def replay(self, org: UUID, administrator_id: UUID, previous, submitted_hash: str): ...
|
||||
|
||||
def create(self, settings, prepared, key: str, administrator_id: UUID, request_id: UUID, expected_org: UUID):
|
||||
"""Locked admin + scoped uniqueness + atomic document/job/audit; returns after commit."""
|
||||
...
|
||||
|
||||
def status(self, administrator_id: UUID, document_id: UUID): ...
|
||||
|
||||
def original_references(self): ...
|
||||
|
||||
Reference in New Issue
Block a user