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