# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 0.81.1
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class StageDefsQueryPreprocessing(BaseModel):
    """
    Configuration for query preprocessing — large file decomposition at query time.  When a query input is a large file (video, PDF, long text), preprocessing decomposes it using the same extractor pipeline that indexed the data, generates N embeddings (one per chunk), runs N parallel searches, and fuses the results into a single ranked list.  This is \"ingestion applied to the query\" — same decomposition and embedding, but vectors are used for search instead of storage.
    """ # noqa: E501
    feature_uri: Optional[StrictStr] = Field(default=None, description="Feature URI for the extractor pipeline to use for decomposition. If None, inherits from the parent search's feature_uri.")
    params: Optional[Dict[str, Any]] = Field(default=None, description="Extractor-specific parameter overrides. Same params as ingestion: split_method, time_split_interval, chunk_size, chunk_overlap, etc.")
    max_chunks: Optional[Annotated[int, Field(le=100, strict=True, ge=1)]] = Field(default=20, description="Maximum number of chunks to search with. Caps parallel queries and embedding calls to control cost. Chunks are evenly sampled across the file if the extractor produces more than max_chunks.")
    aggregation: Optional[StrictStr] = Field(default='rrf', description="Fusion strategy for combining results from N chunk queries. 'rrf': Reciprocal Rank Fusion (balanced, recommended). 'max': Keep highest score per document (best for 'find this exact moment'). 'avg': Average scores (best for 'find similar overall content').")
    dedup_field: Optional[StrictStr] = Field(default=None, description="Optional payload field to deduplicate results by. E.g., '_internal.document_id' to collapse chunks from the same parent document.")
    __properties: ClassVar[List[str]] = ["feature_uri", "params", "max_chunks", "aggregation", "dedup_field"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of StageDefsQueryPreprocessing from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of StageDefsQueryPreprocessing from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "feature_uri": obj.get("feature_uri"),
            "params": obj.get("params"),
            "max_chunks": obj.get("max_chunks") if obj.get("max_chunks") is not None else 20,
            "aggregation": obj.get("aggregation") if obj.get("aggregation") is not None else 'rrf',
            "dedup_field": obj.get("dedup_field")
        })
        return _obj


