vectorize_client.models.retrieve_documents_request

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, StrictBool, StrictStr
 21from typing import Any, ClassVar, Dict, List, Optional, Union
 22from typing_extensions import Annotated
 23from vectorize_client.models.advanced_query import AdvancedQuery
 24from vectorize_client.models.retrieve_context import RetrieveContext
 25from typing import Optional, Set
 26from typing_extensions import Self
 27
 28class RetrieveDocumentsRequest(BaseModel):
 29    """
 30    RetrieveDocumentsRequest
 31    """ # noqa: E501
 32    question: StrictStr
 33    num_results: Union[Annotated[float, Field(strict=True, ge=1)], Annotated[int, Field(strict=True, ge=1)]] = Field(alias="numResults")
 34    rerank: Optional[StrictBool] = True
 35    metadata_filters: Optional[List[Dict[str, Any]]] = Field(default=None, alias="metadata-filters")
 36    context: Optional[RetrieveContext] = None
 37    advanced_query: Optional[AdvancedQuery] = Field(default=None, alias="advanced-query")
 38    __properties: ClassVar[List[str]] = ["question", "numResults", "rerank", "metadata-filters", "context", "advanced-query"]
 39
 40    model_config = ConfigDict(
 41        populate_by_name=True,
 42        validate_assignment=True,
 43        protected_namespaces=(),
 44    )
 45
 46
 47    def to_str(self) -> str:
 48        """Returns the string representation of the model using alias"""
 49        return pprint.pformat(self.model_dump(by_alias=True))
 50
 51    def to_json(self) -> str:
 52        """Returns the JSON representation of the model using alias"""
 53        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
 54        return json.dumps(self.to_dict())
 55
 56    @classmethod
 57    def from_json(cls, json_str: str) -> Optional[Self]:
 58        """Create an instance of RetrieveDocumentsRequest from a JSON string"""
 59        return cls.from_dict(json.loads(json_str))
 60
 61    def to_dict(self) -> Dict[str, Any]:
 62        """Return the dictionary representation of the model using alias.
 63
 64        This has the following differences from calling pydantic's
 65        `self.model_dump(by_alias=True)`:
 66
 67        * `None` is only added to the output dict for nullable fields that
 68          were set at model initialization. Other fields with value `None`
 69          are ignored.
 70        """
 71        excluded_fields: Set[str] = set([
 72        ])
 73
 74        _dict = self.model_dump(
 75            by_alias=True,
 76            exclude=excluded_fields,
 77            exclude_none=True,
 78        )
 79        # override the default output from pydantic by calling `to_dict()` of context
 80        if self.context:
 81            _dict['context'] = self.context.to_dict()
 82        # override the default output from pydantic by calling `to_dict()` of advanced_query
 83        if self.advanced_query:
 84            _dict['advanced-query'] = self.advanced_query.to_dict()
 85        return _dict
 86
 87    @classmethod
 88    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
 89        """Create an instance of RetrieveDocumentsRequest from a dict"""
 90        if obj is None:
 91            return None
 92
 93        if not isinstance(obj, dict):
 94            return cls.model_validate(obj)
 95
 96        _obj = cls.model_validate({
 97            "question": obj.get("question"),
 98            "numResults": obj.get("numResults"),
 99            "rerank": obj.get("rerank") if obj.get("rerank") is not None else True,
100            "metadata-filters": obj.get("metadata-filters"),
101            "context": RetrieveContext.from_dict(obj["context"]) if obj.get("context") is not None else None,
102            "advanced-query": AdvancedQuery.from_dict(obj["advanced-query"]) if obj.get("advanced-query") is not None else None
103        })
104        return _obj
class RetrieveDocumentsRequest(pydantic.main.BaseModel):
 29class RetrieveDocumentsRequest(BaseModel):
 30    """
 31    RetrieveDocumentsRequest
 32    """ # noqa: E501
 33    question: StrictStr
 34    num_results: Union[Annotated[float, Field(strict=True, ge=1)], Annotated[int, Field(strict=True, ge=1)]] = Field(alias="numResults")
 35    rerank: Optional[StrictBool] = True
 36    metadata_filters: Optional[List[Dict[str, Any]]] = Field(default=None, alias="metadata-filters")
 37    context: Optional[RetrieveContext] = None
 38    advanced_query: Optional[AdvancedQuery] = Field(default=None, alias="advanced-query")
 39    __properties: ClassVar[List[str]] = ["question", "numResults", "rerank", "metadata-filters", "context", "advanced-query"]
 40
 41    model_config = ConfigDict(
 42        populate_by_name=True,
 43        validate_assignment=True,
 44        protected_namespaces=(),
 45    )
 46
 47
 48    def to_str(self) -> str:
 49        """Returns the string representation of the model using alias"""
 50        return pprint.pformat(self.model_dump(by_alias=True))
 51
 52    def to_json(self) -> str:
 53        """Returns the JSON representation of the model using alias"""
 54        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
 55        return json.dumps(self.to_dict())
 56
 57    @classmethod
 58    def from_json(cls, json_str: str) -> Optional[Self]:
 59        """Create an instance of RetrieveDocumentsRequest from a JSON string"""
 60        return cls.from_dict(json.loads(json_str))
 61
 62    def to_dict(self) -> Dict[str, Any]:
 63        """Return the dictionary representation of the model using alias.
 64
 65        This has the following differences from calling pydantic's
 66        `self.model_dump(by_alias=True)`:
 67
 68        * `None` is only added to the output dict for nullable fields that
 69          were set at model initialization. Other fields with value `None`
 70          are ignored.
 71        """
 72        excluded_fields: Set[str] = set([
 73        ])
 74
 75        _dict = self.model_dump(
 76            by_alias=True,
 77            exclude=excluded_fields,
 78            exclude_none=True,
 79        )
 80        # override the default output from pydantic by calling `to_dict()` of context
 81        if self.context:
 82            _dict['context'] = self.context.to_dict()
 83        # override the default output from pydantic by calling `to_dict()` of advanced_query
 84        if self.advanced_query:
 85            _dict['advanced-query'] = self.advanced_query.to_dict()
 86        return _dict
 87
 88    @classmethod
 89    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
 90        """Create an instance of RetrieveDocumentsRequest from a dict"""
 91        if obj is None:
 92            return None
 93
 94        if not isinstance(obj, dict):
 95            return cls.model_validate(obj)
 96
 97        _obj = cls.model_validate({
 98            "question": obj.get("question"),
 99            "numResults": obj.get("numResults"),
100            "rerank": obj.get("rerank") if obj.get("rerank") is not None else True,
101            "metadata-filters": obj.get("metadata-filters"),
102            "context": RetrieveContext.from_dict(obj["context"]) if obj.get("context") is not None else None,
103            "advanced-query": AdvancedQuery.from_dict(obj["advanced-query"]) if obj.get("advanced-query") is not None else None
104        })
105        return _obj

RetrieveDocumentsRequest

question: typing.Annotated[str, Strict(strict=True)]
num_results: Union[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1)])], Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1)])]]
rerank: Optional[Annotated[bool, Strict(strict=True)]]
metadata_filters: Optional[List[Dict[str, Any]]]
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:
48    def to_str(self) -> str:
49        """Returns the string representation of the model using alias"""
50        return pprint.pformat(self.model_dump(by_alias=True))

Returns the string representation of the model using alias

def to_json(self) -> str:
52    def to_json(self) -> str:
53        """Returns the JSON representation of the model using alias"""
54        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
55        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]:
57    @classmethod
58    def from_json(cls, json_str: str) -> Optional[Self]:
59        """Create an instance of RetrieveDocumentsRequest from a JSON string"""
60        return cls.from_dict(json.loads(json_str))

Create an instance of RetrieveDocumentsRequest from a JSON string

def to_dict(self) -> Dict[str, Any]:
62    def to_dict(self) -> Dict[str, Any]:
63        """Return the dictionary representation of the model using alias.
64
65        This has the following differences from calling pydantic's
66        `self.model_dump(by_alias=True)`:
67
68        * `None` is only added to the output dict for nullable fields that
69          were set at model initialization. Other fields with value `None`
70          are ignored.
71        """
72        excluded_fields: Set[str] = set([
73        ])
74
75        _dict = self.model_dump(
76            by_alias=True,
77            exclude=excluded_fields,
78            exclude_none=True,
79        )
80        # override the default output from pydantic by calling `to_dict()` of context
81        if self.context:
82            _dict['context'] = self.context.to_dict()
83        # override the default output from pydantic by calling `to_dict()` of advanced_query
84        if self.advanced_query:
85            _dict['advanced-query'] = self.advanced_query.to_dict()
86        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.
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
 88    @classmethod
 89    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
 90        """Create an instance of RetrieveDocumentsRequest from a dict"""
 91        if obj is None:
 92            return None
 93
 94        if not isinstance(obj, dict):
 95            return cls.model_validate(obj)
 96
 97        _obj = cls.model_validate({
 98            "question": obj.get("question"),
 99            "numResults": obj.get("numResults"),
100            "rerank": obj.get("rerank") if obj.get("rerank") is not None else True,
101            "metadata-filters": obj.get("metadata-filters"),
102            "context": RetrieveContext.from_dict(obj["context"]) if obj.get("context") is not None else None,
103            "advanced-query": AdvancedQuery.from_dict(obj["advanced-query"]) if obj.get("advanced-query") is not None else None
104        })
105        return _obj

Create an instance of RetrieveDocumentsRequest from a dict