# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .extract_request_config_chunking_method import ExtractRequestConfigChunkingMethod
from .extract_request_config_consistency_effort import ExtractRequestConfigConsistencyEffort
from .extract_request_config_validation_method import ExtractRequestConfigValidationMethod


class ExtractRequestConfig(UniversalBaseModel):
    chunking_method: typing.Optional[ExtractRequestConfigChunkingMethod] = pydantic.Field(default=None)
    """
    Method for splitting input text into chunks before code extraction
    """

    max_codes_per_chunk: typing.Optional[int] = pydantic.Field(default=None)
    """
    Maximum number of codes to extract per chunk. If not specified, uses system-specific defaults:
    * SNOMED: 10
    * LOINC, HPO, RXNORM: 20
    * All other systems: 5
    """

    code_similarity_filter: typing.Optional[float] = pydantic.Field(default=None)
    """
    Threshold for filtering similar codes (0.0-1.0)
    """

    validation_method: typing.Optional[ExtractRequestConfigValidationMethod] = pydantic.Field(default=None)
    """
    Method for validating extracted codes:
    * none - No validation, returns all candidate codes
    * simple - LLM-based validation
    * medication_search - LLM-based validation tailored for medication concepts
    """

    include_rationale: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether to include explanations for why each code was extracted
    """

    include_ancestors: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether to include ancestor/parent codes in the results
    """

    include_invalid: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether to include codes that failed validation in the results
    """

    include_citations: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether to include source text citations for each extracted code.
    Citations show the exact text spans (with character offsets) that led to each code.
    Only available when using chunking_method: "sentences".
    The "none" method returns full text as one chunk (not useful for citations).
    LLM-based chunking (paragraphs, topics, soap_note) does not support citations.
    """

    extraction_context: typing.Optional[str] = pydantic.Field(default=None)
    """
    Optional context describing the goal of the extraction.
    Required when min_context_relevance is greater than 0.
    """

    min_context_relevance: typing.Optional[float] = pydantic.Field(default=None)
    """
    Minimum relevance score (0.0–1.0) a chunk must reach to proceed to code extraction.
    Chunks are scored by an LLM against the extraction_context goal. Chunks below this
    threshold are dropped, reducing noise and extraction cost.
    Set to 0 (the default) to disable relevance filtering and extract from all chunks.
    Requires the "extraction_context" field when set above 0.
    """

    consistency_effort: typing.Optional[ExtractRequestConfigConsistencyEffort] = pydantic.Field(default=None)
    """
    How much effort to spend ensuring consistent results across repeated requests.
    Higher levels apply stricter filtering to remove borderline codes that may
    vary between calls, improving determinism at the cost of additional latency.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
