vectorize_client.models.advanced_query

Vectorize API

API for Vectorize services (Beta)

The version of the OpenAPI document: 0.1.2 Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.

  1# coding: utf-8
  2
  3"""
  4    Vectorize API
  5
  6    API for Vectorize services (Beta)
  7
  8    The version of the OpenAPI document: 0.1.2
  9    Generated by OpenAPI Generator (https://openapi-generator.tech)
 10
 11    Do not edit the class manually.
 12"""  # noqa: E501
 13
 14
 15from __future__ import annotations
 16import pprint
 17import re  # noqa: F401
 18import json
 19
 20from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
 21from typing import Any, ClassVar, Dict, List, Optional, Union
 22from typing import Optional, Set
 23from typing_extensions import Self
 24
 25class AdvancedQuery(BaseModel):
 26    """
 27    AdvancedQuery
 28    """ # noqa: E501
 29    mode: Optional[StrictStr] = 'vector'
 30    text_fields: Optional[List[StrictStr]] = Field(default=None, alias="text-fields")
 31    match_type: Optional[StrictStr] = Field(default=None, alias="match-type")
 32    text_boost: Optional[Union[StrictFloat, StrictInt]] = Field(default=1, alias="text-boost")
 33    filters: Optional[Dict[str, Any]] = None
 34    additional_properties: Dict[str, Any] = {}
 35    __properties: ClassVar[List[str]] = ["mode", "text-fields", "match-type", "text-boost", "filters"]
 36
 37    @field_validator('mode')
 38    def mode_validate_enum(cls, value):
 39        """Validates the enum"""
 40        if value is None:
 41            return value
 42
 43        if value not in set(['text', 'vector', 'hybrid']):
 44            raise ValueError("must be one of enum values ('text', 'vector', 'hybrid')")
 45        return value
 46
 47    @field_validator('match_type')
 48    def match_type_validate_enum(cls, value):
 49        """Validates the enum"""
 50        if value is None:
 51            return value
 52
 53        if value not in set(['match', 'match_phrase', 'multi_match']):
 54            raise ValueError("must be one of enum values ('match', 'match_phrase', 'multi_match')")
 55        return value
 56
 57    model_config = ConfigDict(
 58        populate_by_name=True,
 59        validate_assignment=True,
 60        protected_namespaces=(),
 61    )
 62
 63
 64    def to_str(self) -> str:
 65        """Returns the string representation of the model using alias"""
 66        return pprint.pformat(self.model_dump(by_alias=True))
 67
 68    def to_json(self) -> str:
 69        """Returns the JSON representation of the model using alias"""
 70        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
 71        return json.dumps(self.to_dict())
 72
 73    @classmethod
 74    def from_json(cls, json_str: str) -> Optional[Self]:
 75        """Create an instance of AdvancedQuery from a JSON string"""
 76        return cls.from_dict(json.loads(json_str))
 77
 78    def to_dict(self) -> Dict[str, Any]:
 79        """Return the dictionary representation of the model using alias.
 80
 81        This has the following differences from calling pydantic's
 82        `self.model_dump(by_alias=True)`:
 83
 84        * `None` is only added to the output dict for nullable fields that
 85          were set at model initialization. Other fields with value `None`
 86          are ignored.
 87        * Fields in `self.additional_properties` are added to the output dict.
 88        """
 89        excluded_fields: Set[str] = set([
 90            "additional_properties",
 91        ])
 92
 93        _dict = self.model_dump(
 94            by_alias=True,
 95            exclude=excluded_fields,
 96            exclude_none=True,
 97        )
 98        # puts key-value pairs in additional_properties in the top level
 99        if self.additional_properties is not None:
100            for _key, _value in self.additional_properties.items():
101                _dict[_key] = _value
102
103        return _dict
104
105    @classmethod
106    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
107        """Create an instance of AdvancedQuery from a dict"""
108        if obj is None:
109            return None
110
111        if not isinstance(obj, dict):
112            return cls.model_validate(obj)
113
114        _obj = cls.model_validate({
115            "mode": obj.get("mode") if obj.get("mode") is not None else 'vector',
116            "text-fields": obj.get("text-fields"),
117            "match-type": obj.get("match-type"),
118            "text-boost": obj.get("text-boost") if obj.get("text-boost") is not None else 1,
119            "filters": obj.get("filters")
120        })
121        # store additional fields in additional_properties
122        for _key in obj.keys():
123            if _key not in cls.__properties:
124                _obj.additional_properties[_key] = obj.get(_key)
125
126        return _obj
class AdvancedQuery(pydantic.main.BaseModel):
 26class AdvancedQuery(BaseModel):
 27    """
 28    AdvancedQuery
 29    """ # noqa: E501
 30    mode: Optional[StrictStr] = 'vector'
 31    text_fields: Optional[List[StrictStr]] = Field(default=None, alias="text-fields")
 32    match_type: Optional[StrictStr] = Field(default=None, alias="match-type")
 33    text_boost: Optional[Union[StrictFloat, StrictInt]] = Field(default=1, alias="text-boost")
 34    filters: Optional[Dict[str, Any]] = None
 35    additional_properties: Dict[str, Any] = {}
 36    __properties: ClassVar[List[str]] = ["mode", "text-fields", "match-type", "text-boost", "filters"]
 37
 38    @field_validator('mode')
 39    def mode_validate_enum(cls, value):
 40        """Validates the enum"""
 41        if value is None:
 42            return value
 43
 44        if value not in set(['text', 'vector', 'hybrid']):
 45            raise ValueError("must be one of enum values ('text', 'vector', 'hybrid')")
 46        return value
 47
 48    @field_validator('match_type')
 49    def match_type_validate_enum(cls, value):
 50        """Validates the enum"""
 51        if value is None:
 52            return value
 53
 54        if value not in set(['match', 'match_phrase', 'multi_match']):
 55            raise ValueError("must be one of enum values ('match', 'match_phrase', 'multi_match')")
 56        return value
 57
 58    model_config = ConfigDict(
 59        populate_by_name=True,
 60        validate_assignment=True,
 61        protected_namespaces=(),
 62    )
 63
 64
 65    def to_str(self) -> str:
 66        """Returns the string representation of the model using alias"""
 67        return pprint.pformat(self.model_dump(by_alias=True))
 68
 69    def to_json(self) -> str:
 70        """Returns the JSON representation of the model using alias"""
 71        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
 72        return json.dumps(self.to_dict())
 73
 74    @classmethod
 75    def from_json(cls, json_str: str) -> Optional[Self]:
 76        """Create an instance of AdvancedQuery from a JSON string"""
 77        return cls.from_dict(json.loads(json_str))
 78
 79    def to_dict(self) -> Dict[str, Any]:
 80        """Return the dictionary representation of the model using alias.
 81
 82        This has the following differences from calling pydantic's
 83        `self.model_dump(by_alias=True)`:
 84
 85        * `None` is only added to the output dict for nullable fields that
 86          were set at model initialization. Other fields with value `None`
 87          are ignored.
 88        * Fields in `self.additional_properties` are added to the output dict.
 89        """
 90        excluded_fields: Set[str] = set([
 91            "additional_properties",
 92        ])
 93
 94        _dict = self.model_dump(
 95            by_alias=True,
 96            exclude=excluded_fields,
 97            exclude_none=True,
 98        )
 99        # puts key-value pairs in additional_properties in the top level
100        if self.additional_properties is not None:
101            for _key, _value in self.additional_properties.items():
102                _dict[_key] = _value
103
104        return _dict
105
106    @classmethod
107    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
108        """Create an instance of AdvancedQuery from a dict"""
109        if obj is None:
110            return None
111
112        if not isinstance(obj, dict):
113            return cls.model_validate(obj)
114
115        _obj = cls.model_validate({
116            "mode": obj.get("mode") if obj.get("mode") is not None else 'vector',
117            "text-fields": obj.get("text-fields"),
118            "match-type": obj.get("match-type"),
119            "text-boost": obj.get("text-boost") if obj.get("text-boost") is not None else 1,
120            "filters": obj.get("filters")
121        })
122        # store additional fields in additional_properties
123        for _key in obj.keys():
124            if _key not in cls.__properties:
125                _obj.additional_properties[_key] = obj.get(_key)
126
127        return _obj

AdvancedQuery

mode: Optional[Annotated[str, Strict(strict=True)]]
text_fields: Optional[List[Annotated[str, Strict(strict=True)]]]
match_type: Optional[Annotated[str, Strict(strict=True)]]
text_boost: Union[Annotated[float, Strict(strict=True)], Annotated[int, Strict(strict=True)], NoneType]
filters: Optional[Dict[str, Any]]
additional_properties: Dict[str, Any]
@field_validator('mode')
def mode_validate_enum(cls, value):
38    @field_validator('mode')
39    def mode_validate_enum(cls, value):
40        """Validates the enum"""
41        if value is None:
42            return value
43
44        if value not in set(['text', 'vector', 'hybrid']):
45            raise ValueError("must be one of enum values ('text', 'vector', 'hybrid')")
46        return value

Validates the enum

@field_validator('match_type')
def match_type_validate_enum(cls, value):
48    @field_validator('match_type')
49    def match_type_validate_enum(cls, value):
50        """Validates the enum"""
51        if value is None:
52            return value
53
54        if value not in set(['match', 'match_phrase', 'multi_match']):
55            raise ValueError("must be one of enum values ('match', 'match_phrase', 'multi_match')")
56        return value

Validates the enum

model_config = {'populate_by_name': True, 'validate_assignment': True, 'protected_namespaces': (), 'validate_by_alias': True, 'validate_by_name': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

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

Returns the string representation of the model using alias

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

Returns the JSON representation of the model using alias

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

Create an instance of AdvancedQuery from a JSON string

def to_dict(self) -> Dict[str, Any]:
 79    def to_dict(self) -> Dict[str, Any]:
 80        """Return the dictionary representation of the model using alias.
 81
 82        This has the following differences from calling pydantic's
 83        `self.model_dump(by_alias=True)`:
 84
 85        * `None` is only added to the output dict for nullable fields that
 86          were set at model initialization. Other fields with value `None`
 87          are ignored.
 88        * Fields in `self.additional_properties` are added to the output dict.
 89        """
 90        excluded_fields: Set[str] = set([
 91            "additional_properties",
 92        ])
 93
 94        _dict = self.model_dump(
 95            by_alias=True,
 96            exclude=excluded_fields,
 97            exclude_none=True,
 98        )
 99        # puts key-value pairs in additional_properties in the top level
100        if self.additional_properties is not None:
101            for _key, _value in self.additional_properties.items():
102                _dict[_key] = _value
103
104        return _dict

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.
  • Fields in self.additional_properties are added to the output dict.
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
106    @classmethod
107    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
108        """Create an instance of AdvancedQuery from a dict"""
109        if obj is None:
110            return None
111
112        if not isinstance(obj, dict):
113            return cls.model_validate(obj)
114
115        _obj = cls.model_validate({
116            "mode": obj.get("mode") if obj.get("mode") is not None else 'vector',
117            "text-fields": obj.get("text-fields"),
118            "match-type": obj.get("match-type"),
119            "text-boost": obj.get("text-boost") if obj.get("text-boost") is not None else 1,
120            "filters": obj.get("filters")
121        })
122        # store additional fields in additional_properties
123        for _key in obj.keys():
124            if _key not in cls.__properties:
125                _obj.additional_properties[_key] = obj.get(_key)
126
127        return _obj

Create an instance of AdvancedQuery from a dict