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

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel


class SemanticSimilarityAssertion(UncheckedBaseModel):
    """
    Semantic similarity assertion.

    Checks if the actual value is semantically similar to expected value
    using embedding-based similarity (cosine similarity).

    Example:
        assertion = SemanticSimilarityAssertion(
            type="semantic_similarity",
            field_path="response.message",
            expected="Your order has been processed successfully",
            threshold=0.9,
            description="Response should convey order success"
        )
    """

    type: typing.Literal["semantic_similarity"] = "semantic_similarity"
    description: typing.Optional[str] = pydantic.Field(default=None)
    """
    Human-readable description of this assertion
    """

    field_path: typing.Optional[str] = pydantic.Field(default=None)
    """
    JSON path to field (e.g., 'response.products[0].id'). If None, checks whole output.
    """

    expected: typing.Optional[typing.Any] = None
    threshold: typing.Optional[float] = pydantic.Field(default=None)
    """
    Similarity threshold (0-1)
    """

    embedding_model: typing.Optional[str] = pydantic.Field(default=None)
    """
    OpenAI embedding model to use
    """

    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
