diff --git a/.github/workflows/testing-integration.yaml b/.github/workflows/testing-integration.yaml index 6a01495ff..6a8da64e9 100644 --- a/.github/workflows/testing-integration.yaml +++ b/.github/workflows/testing-integration.yaml @@ -3,28 +3,6 @@ name: "Integration Tests" workflow_call: {} jobs: - plugin-inference: - name: Test inference plugin - runs-on: ubuntu-latest - strategy: - matrix: - python_version: [3.9, 3.12] - steps: - - uses: actions/checkout@v4 - - name: 'Set up Python ${{ matrix.python_version }}' - uses: actions/setup-python@v5 - with: - python-version: '${{ matrix.python_version }}' - - name: Setup Poetry - uses: ./.github/actions/setup-poetry - with: - include_grpc: 'true' - - name: 'Run integration tests' - run: poetry run pytest tests/integration/inference -s -vv - env: - PINECONE_DEBUG_CURL: 'true' - PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' - data-plane-serverless: name: Data plane serverless integration tests runs-on: ubuntu-latest diff --git a/codegen/build-oas.sh b/codegen/build-oas.sh index d6258e8e7..738b12703 100755 --- a/codegen/build-oas.sh +++ b/codegen/build-oas.sh @@ -8,12 +8,12 @@ is_early_access=$2 # e.g. true # if is_early_access is true, add the "ea" module if [ "$is_early_access" = "true" ]; then destination="pinecone/core_ea/openapi" - modules=("db_control" "db_data") + modules=("db_control" "db_data" "inference") py_module_name="core_ea" template_dir="codegen/python-oas-templates/templates5.2.0" else destination="pinecone/core/openapi" - modules=("db_control" "db_data") + modules=("db_control" "db_data" "inference") py_module_name="core" template_dir="codegen/python-oas-templates/templates5.2.0" fi diff --git a/pinecone/__init__.py b/pinecone/__init__.py index 8ff07279a..014729897 100644 --- a/pinecone/__init__.py +++ b/pinecone/__init__.py @@ -7,6 +7,7 @@ warnings.filterwarnings("ignore", category=TqdmExperimentalWarning) +from .deprecated_plugins import check_for_deprecated_plugins from .deprecation_warnings import * from .config import * from .exceptions import * @@ -18,4 +19,9 @@ import logging +# Raise an exception if the user is attempting to use the SDK with deprecated plugins +# installed in their project. +check_for_deprecated_plugins() + +# Silence annoying log messages from the plugin interface logging.getLogger("pinecone_plugin_interface").setLevel(logging.CRITICAL) diff --git a/pinecone/control/pinecone.py b/pinecone/control/pinecone.py index 3f7193bd4..861403ec2 100644 --- a/pinecone/control/pinecone.py +++ b/pinecone/control/pinecone.py @@ -30,7 +30,7 @@ from .langchain_import_warnings import _build_langchain_attribute_error_message from pinecone.utils import parse_non_empty_args, docslinks -from pinecone.data import _Index, _AsyncioIndex +from pinecone.data import _Index, _AsyncioIndex, _Inference from pinecone_plugin_interface import load_and_install as install_plugins @@ -85,6 +85,8 @@ def __init__( self.openapi_config = ConfigBuilder.build_openapi_config(self.config, **kwargs) self.pool_threads = pool_threads + self._inference = None # Lazy initialization + if index_api: self.index_api = index_api else: @@ -102,6 +104,13 @@ def __init__( self.load_plugins() + @property + def inference(self): + """Dynamically create and cache the Inference instance.""" + if self._inference is None: + self._inference = _Inference(config=self.config, openapi_config=self.openapi_config) + return self._inference + def load_plugins(self): """@private""" try: diff --git a/pinecone/core/openapi/db_control/api/manage_indexes_api.py b/pinecone/core/openapi/db_control/api/manage_indexes_api.py index d03fdf5dd..3349478a2 100644 --- a/pinecone/core/openapi/db_control/api/manage_indexes_api.py +++ b/pinecone/core/openapi/db_control/api/manage_indexes_api.py @@ -40,8 +40,7 @@ class ManageIndexesApi(object): - """NOTE: This class is auto generated by OpenAPI Generator - Ref: https://openapi-generator.tech + """NOTE: This class is auto generated. Do not edit the class manually. """ diff --git a/pinecone/core/openapi/db_data/api/bulk_operations_api.py b/pinecone/core/openapi/db_data/api/bulk_operations_api.py index 8fa30e8ba..64292465a 100644 --- a/pinecone/core/openapi/db_data/api/bulk_operations_api.py +++ b/pinecone/core/openapi/db_data/api/bulk_operations_api.py @@ -34,8 +34,7 @@ class BulkOperationsApi(object): - """NOTE: This class is auto generated by OpenAPI Generator - Ref: https://openapi-generator.tech + """NOTE: This class is auto generated. Do not edit the class manually. """ diff --git a/pinecone/core/openapi/db_data/api/vector_operations_api.py b/pinecone/core/openapi/db_data/api/vector_operations_api.py index 1566f7919..f205196a5 100644 --- a/pinecone/core/openapi/db_data/api/vector_operations_api.py +++ b/pinecone/core/openapi/db_data/api/vector_operations_api.py @@ -45,8 +45,7 @@ class VectorOperationsApi(object): - """NOTE: This class is auto generated by OpenAPI Generator - Ref: https://openapi-generator.tech + """NOTE: This class is auto generated. Do not edit the class manually. """ diff --git a/pinecone/core/openapi/inference/__init__.py b/pinecone/core/openapi/inference/__init__.py new file mode 100644 index 000000000..65e60b9f3 --- /dev/null +++ b/pinecone/core/openapi/inference/__init__.py @@ -0,0 +1,29 @@ +# flake8: noqa + +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +__version__ = "1.0.0" + +# import ApiClient +from pinecone.openapi_support import ApiClient + +# import Configuration +from pinecone.openapi_support import Configuration + +# import exceptions +from pinecone.openapi_support.exceptions import PineconeException +from pinecone.openapi_support.exceptions import PineconeApiAttributeError +from pinecone.openapi_support.exceptions import PineconeApiTypeError +from pinecone.openapi_support.exceptions import PineconeApiValueError +from pinecone.openapi_support.exceptions import PineconeApiKeyError +from pinecone.openapi_support.exceptions import PineconeApiException + +API_VERSION = "2025-01" diff --git a/pinecone/core/openapi/inference/api/__init__.py b/pinecone/core/openapi/inference/api/__init__.py new file mode 100644 index 000000000..533709993 --- /dev/null +++ b/pinecone/core/openapi/inference/api/__init__.py @@ -0,0 +1,3 @@ +# do not import all apis into this module because that uses a lot of memory and stack frames +# if you need the ability to import all apis from one package, import them with +# from pinecone.core.openapi.inference.apis import InferenceApi diff --git a/pinecone/core/openapi/inference/api/inference_api.py b/pinecone/core/openapi/inference/api/inference_api.py new file mode 100644 index 000000000..23ab6c08e --- /dev/null +++ b/pinecone/core/openapi/inference/api/inference_api.py @@ -0,0 +1,346 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( + ApiClient, + Endpoint as _Endpoint, + AsyncioApiClient, + AsyncioEndpoint as _AsyncioEndpoint, +) +from pinecone.openapi_support import ( # noqa: F401 + check_allowed_values, + check_validations, + date, + datetime, + file_type, + none_type, + validate_and_convert_types, +) +from pinecone.core.openapi.inference.model.embed_request import EmbedRequest +from pinecone.core.openapi.inference.model.embeddings_list import EmbeddingsList +from pinecone.core.openapi.inference.model.error_response import ErrorResponse +from pinecone.core.openapi.inference.model.rerank_request import RerankRequest +from pinecone.core.openapi.inference.model.rerank_result import RerankResult + + +class InferenceApi(object): + """NOTE: This class is auto generated. + + Do not edit the class manually. + """ + + def __init__(self, api_client=None): + if api_client is None: + api_client = ApiClient() + self.api_client = api_client + + def __embed(self, **kwargs): + """Embed data # noqa: E501 + + Generate embeddings for input data. For guidance and examples, see [Generate embeddings](https://docs.pinecone.io/guides/inference/generate-embeddings). # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.embed(async_req=True) + >>> result = thread.get() + + + Keyword Args: + embed_request (EmbedRequest): Generate embeddings for inputs. [optional] + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (int/float/tuple): timeout setting for this request. If + one number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int/None): specifies the index of the server + that we want to use. + Default is read from the configuration. + async_req (bool): execute request asynchronously + + Returns: + EmbeddingsList + If the method is called asynchronously, returns the request + thread. + """ + kwargs["async_req"] = kwargs.get("async_req", False) + kwargs["_return_http_data_only"] = kwargs.get("_return_http_data_only", True) + kwargs["_preload_content"] = kwargs.get("_preload_content", True) + kwargs["_request_timeout"] = kwargs.get("_request_timeout", None) + kwargs["_check_input_type"] = kwargs.get("_check_input_type", True) + kwargs["_check_return_type"] = kwargs.get("_check_return_type", True) + kwargs["_host_index"] = kwargs.get("_host_index") + return self.call_with_http_info(**kwargs) + + self.embed = _Endpoint( + settings={ + "response_type": (EmbeddingsList,), + "auth": ["ApiKeyAuth"], + "endpoint_path": "/embed", + "operation_id": "embed", + "http_method": "POST", + "servers": None, + }, + params_map={ + "all": ["embed_request"], + "required": [], + "nullable": [], + "enum": [], + "validation": [], + }, + root_map={ + "validations": {}, + "allowed_values": {}, + "openapi_types": {"embed_request": (EmbedRequest,)}, + "attribute_map": {}, + "location_map": {"embed_request": "body"}, + "collection_format_map": {}, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + callable=__embed, + ) + + def __rerank(self, **kwargs): + """Rerank documents # noqa: E501 + + Rerank documents according to their relevance to a query. For guidance and examples, see [Rerank documents](https://docs.pinecone.io/guides/inference/rerank). # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.rerank(async_req=True) + >>> result = thread.get() + + + Keyword Args: + rerank_request (RerankRequest): Rerank documents for the given query [optional] + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (int/float/tuple): timeout setting for this request. If + one number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int/None): specifies the index of the server + that we want to use. + Default is read from the configuration. + async_req (bool): execute request asynchronously + + Returns: + RerankResult + If the method is called asynchronously, returns the request + thread. + """ + kwargs["async_req"] = kwargs.get("async_req", False) + kwargs["_return_http_data_only"] = kwargs.get("_return_http_data_only", True) + kwargs["_preload_content"] = kwargs.get("_preload_content", True) + kwargs["_request_timeout"] = kwargs.get("_request_timeout", None) + kwargs["_check_input_type"] = kwargs.get("_check_input_type", True) + kwargs["_check_return_type"] = kwargs.get("_check_return_type", True) + kwargs["_host_index"] = kwargs.get("_host_index") + return self.call_with_http_info(**kwargs) + + self.rerank = _Endpoint( + settings={ + "response_type": (RerankResult,), + "auth": ["ApiKeyAuth"], + "endpoint_path": "/rerank", + "operation_id": "rerank", + "http_method": "POST", + "servers": None, + }, + params_map={ + "all": ["rerank_request"], + "required": [], + "nullable": [], + "enum": [], + "validation": [], + }, + root_map={ + "validations": {}, + "allowed_values": {}, + "openapi_types": {"rerank_request": (RerankRequest,)}, + "attribute_map": {}, + "location_map": {"rerank_request": "body"}, + "collection_format_map": {}, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + callable=__rerank, + ) + + +class AsyncioInferenceApi(object): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + def __init__(self, api_client=None): + if api_client is None: + api_client = AsyncioApiClient() + self.api_client = api_client + + async def __embed(self, **kwargs): + """Embed data # noqa: E501 + + Generate embeddings for input data. For guidance and examples, see [Generate embeddings](https://docs.pinecone.io/guides/inference/generate-embeddings). # noqa: E501 + + + + Keyword Args: + embed_request (EmbedRequest): Generate embeddings for inputs. [optional] + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (int/float/tuple): timeout setting for this request. If + one number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int/None): specifies the index of the server + that we want to use. + Default is read from the configuration. + + Returns: + EmbeddingsList + """ + kwargs["_return_http_data_only"] = kwargs.get("_return_http_data_only", True) + kwargs["_preload_content"] = kwargs.get("_preload_content", True) + kwargs["_request_timeout"] = kwargs.get("_request_timeout", None) + kwargs["_check_input_type"] = kwargs.get("_check_input_type", True) + kwargs["_check_return_type"] = kwargs.get("_check_return_type", True) + kwargs["_host_index"] = kwargs.get("_host_index") + return await self.call_with_http_info(**kwargs) + + self.embed = _AsyncioEndpoint( + settings={ + "response_type": (EmbeddingsList,), + "auth": ["ApiKeyAuth"], + "endpoint_path": "/embed", + "operation_id": "embed", + "http_method": "POST", + "servers": None, + }, + params_map={ + "all": ["embed_request"], + "required": [], + "nullable": [], + "enum": [], + "validation": [], + }, + root_map={ + "validations": {}, + "allowed_values": {}, + "openapi_types": {"embed_request": (EmbedRequest,)}, + "attribute_map": {}, + "location_map": {"embed_request": "body"}, + "collection_format_map": {}, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + callable=__embed, + ) + + async def __rerank(self, **kwargs): + """Rerank documents # noqa: E501 + + Rerank documents according to their relevance to a query. For guidance and examples, see [Rerank documents](https://docs.pinecone.io/guides/inference/rerank). # noqa: E501 + + + + Keyword Args: + rerank_request (RerankRequest): Rerank documents for the given query [optional] + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (int/float/tuple): timeout setting for this request. If + one number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int/None): specifies the index of the server + that we want to use. + Default is read from the configuration. + + Returns: + RerankResult + """ + kwargs["_return_http_data_only"] = kwargs.get("_return_http_data_only", True) + kwargs["_preload_content"] = kwargs.get("_preload_content", True) + kwargs["_request_timeout"] = kwargs.get("_request_timeout", None) + kwargs["_check_input_type"] = kwargs.get("_check_input_type", True) + kwargs["_check_return_type"] = kwargs.get("_check_return_type", True) + kwargs["_host_index"] = kwargs.get("_host_index") + return await self.call_with_http_info(**kwargs) + + self.rerank = _AsyncioEndpoint( + settings={ + "response_type": (RerankResult,), + "auth": ["ApiKeyAuth"], + "endpoint_path": "/rerank", + "operation_id": "rerank", + "http_method": "POST", + "servers": None, + }, + params_map={ + "all": ["rerank_request"], + "required": [], + "nullable": [], + "enum": [], + "validation": [], + }, + root_map={ + "validations": {}, + "allowed_values": {}, + "openapi_types": {"rerank_request": (RerankRequest,)}, + "attribute_map": {}, + "location_map": {"rerank_request": "body"}, + "collection_format_map": {}, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + callable=__rerank, + ) diff --git a/pinecone/core/openapi/inference/apis/__init__.py b/pinecone/core/openapi/inference/apis/__init__.py new file mode 100644 index 000000000..647ee6f2e --- /dev/null +++ b/pinecone/core/openapi/inference/apis/__init__.py @@ -0,0 +1,16 @@ +# flake8: noqa + +# Import all APIs into this package. +# If you have many APIs here with many many models used in each API this may +# raise a `RecursionError`. +# In order to avoid this, import only the API that you directly need like: +# +# from .api.inference_api import InferenceApi +# +# or import this package, but before doing it, use: +# +# import sys +# sys.setrecursionlimit(n) + +# Import APIs into API package: +from pinecone.core.openapi.inference.api.inference_api import InferenceApi diff --git a/pinecone/core/openapi/inference/model/__init__.py b/pinecone/core/openapi/inference/model/__init__.py new file mode 100644 index 000000000..cfe32b784 --- /dev/null +++ b/pinecone/core/openapi/inference/model/__init__.py @@ -0,0 +1,5 @@ +# we can not import model classes here because that would create a circular +# reference which would not work in python2 +# do not import all models into this module because that uses a lot of memory and stack frames +# if you need the ability to import all models from one package, import them with +# from {{packageName}.models import ModelA, ModelB diff --git a/pinecone/core/openapi/inference/model/dense_embedding.py b/pinecone/core/openapi/inference/model/dense_embedding.py new file mode 100644 index 000000000..ff981c0e0 --- /dev/null +++ b/pinecone/core/openapi/inference/model/dense_embedding.py @@ -0,0 +1,274 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.vector_type import VectorType + + globals()["VectorType"] = VectorType + + +class DenseEmbedding(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "values": ([float],), # noqa: E501 + "vector_type": (VectorType,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "values": "values", # noqa: E501 + "vector_type": "vector_type", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, values, vector_type, *args, **kwargs): # noqa: E501 + """DenseEmbedding - a model defined in OpenAPI + + Args: + values ([float]): The dense embedding values. + vector_type (VectorType): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.values = values + self.vector_type = vector_type + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, values, vector_type, *args, **kwargs): # noqa: E501 + """DenseEmbedding - a model defined in OpenAPI + + Args: + values ([float]): The dense embedding values. + vector_type (VectorType): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.values = values + self.vector_type = vector_type + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/document.py b/pinecone/core/openapi/inference/model/document.py new file mode 100644 index 000000000..27a3f4426 --- /dev/null +++ b/pinecone/core/openapi/inference/model/document.py @@ -0,0 +1,248 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +class Document(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return {} + + @cached_property + def discriminator(): + return None + + attribute_map = {} + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """Document - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """Document - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/embed_request.py b/pinecone/core/openapi/inference/model/embed_request.py new file mode 100644 index 000000000..d05701d17 --- /dev/null +++ b/pinecone/core/openapi/inference/model/embed_request.py @@ -0,0 +1,278 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.embed_request_inputs import EmbedRequestInputs + + globals()["EmbedRequestInputs"] = EmbedRequestInputs + + +class EmbedRequest(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "model": (str,), # noqa: E501 + "inputs": ([EmbedRequestInputs],), # noqa: E501 + "parameters": ({str: (bool, dict, float, int, list, str, none_type)},), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "model": "model", # noqa: E501 + "inputs": "inputs", # noqa: E501 + "parameters": "parameters", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, model, inputs, *args, **kwargs): # noqa: E501 + """EmbedRequest - a model defined in OpenAPI + + Args: + model (str): The [model](https://docs.pinecone.io/guides/inference/understanding-inference#embedding-models) to use for embedding generation. + inputs ([EmbedRequestInputs]): List of inputs to generate embeddings for. + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + parameters ({str: (bool, dict, float, int, list, str, none_type)}): Additional model-specific parameters. Refer to the [model guide](https://docs.pinecone.io/guides/inference/understanding-inference#embedding-models) for available model parameters. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.inputs = inputs + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, model, inputs, *args, **kwargs): # noqa: E501 + """EmbedRequest - a model defined in OpenAPI + + Args: + model (str): The [model](https://docs.pinecone.io/guides/inference/understanding-inference#embedding-models) to use for embedding generation. + inputs ([EmbedRequestInputs]): List of inputs to generate embeddings for. + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + parameters ({str: (bool, dict, float, int, list, str, none_type)}): Additional model-specific parameters. Refer to the [model guide](https://docs.pinecone.io/guides/inference/understanding-inference#embedding-models) for available model parameters. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.inputs = inputs + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/embed_request_inputs.py b/pinecone/core/openapi/inference/model/embed_request_inputs.py new file mode 100644 index 000000000..e14e6520f --- /dev/null +++ b/pinecone/core/openapi/inference/model/embed_request_inputs.py @@ -0,0 +1,254 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +class EmbedRequestInputs(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + "text": (str,) # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "text": "text" # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """EmbedRequestInputs - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + text (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """EmbedRequestInputs - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + text (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/embedding.py b/pinecone/core/openapi/inference/model/embedding.py new file mode 100644 index 000000000..c9396eec5 --- /dev/null +++ b/pinecone/core/openapi/inference/model/embedding.py @@ -0,0 +1,331 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.dense_embedding import DenseEmbedding + from pinecone.core.openapi.inference.model.sparse_embedding import SparseEmbedding + from pinecone.core.openapi.inference.model.vector_type import VectorType + + globals()["DenseEmbedding"] = DenseEmbedding + globals()["SparseEmbedding"] = SparseEmbedding + globals()["VectorType"] = VectorType + + +class Embedding(ModelComposed): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "vector_type": (VectorType,), # noqa: E501 + "sparse_tokens": ([str],), # noqa: E501 + "values": ([float],), # noqa: E501 + "sparse_values": ([float],), # noqa: E501 + "sparse_indices": ([int],), # noqa: E501 + } + + @cached_property + def discriminator(): + lazy_import() + val = { + "DenseEmbedding": DenseEmbedding, + "SparseEmbedding": SparseEmbedding, + "dense": DenseEmbedding, + "sparse": SparseEmbedding, + } + if not val: + return None + return {"vector_type": val} + + attribute_map = { + "vector_type": "vector_type", # noqa: E501 + "sparse_tokens": "sparse_tokens", # noqa: E501 + "values": "values", # noqa: E501 + "sparse_values": "sparse_values", # noqa: E501 + "sparse_indices": "sparse_indices", # noqa: E501 + } + + read_only_vars = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """Embedding - a model defined in OpenAPI + + Keyword Args: + vector_type (VectorType): + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + sparse_tokens ([str]): The normalized tokens used to create the sparse embedding. [optional] # noqa: E501 + values ([float]): The dense embedding values. [optional] # noqa: E501 + sparse_values ([float]): The sparse embedding values. [optional] # noqa: E501 + sparse_indices ([int]): The sparse embedding indices. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + constant_args = { + "_check_type": _check_type, + "_path_to_item": _path_to_item, + "_spec_property_naming": _spec_property_naming, + "_configuration": _configuration, + "_visited_composed_classes": self._visited_composed_classes, + } + composed_info = validate_get_composed_info(constant_args, kwargs, self) + self._composed_instances = composed_info[0] + self._var_name_to_model_instances = composed_info[1] + self._additional_properties_model_instances = composed_info[2] + discarded_args = composed_info[3] + + for var_name, var_value in kwargs.items(): + if ( + var_name in discarded_args + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self._additional_properties_model_instances + ): + # discard variable. + continue + setattr(self, var_name, var_value) + + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + "_composed_instances", + "_var_name_to_model_instances", + "_additional_properties_model_instances", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """Embedding - a model defined in OpenAPI + + Keyword Args: + vector_type (VectorType): + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + sparse_tokens ([str]): The normalized tokens used to create the sparse embedding. [optional] # noqa: E501 + values ([float]): The dense embedding values. [optional] # noqa: E501 + sparse_values ([float]): The sparse embedding values. [optional] # noqa: E501 + sparse_indices ([int]): The sparse embedding indices. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + constant_args = { + "_check_type": _check_type, + "_path_to_item": _path_to_item, + "_spec_property_naming": _spec_property_naming, + "_configuration": _configuration, + "_visited_composed_classes": self._visited_composed_classes, + } + composed_info = validate_get_composed_info(constant_args, kwargs, self) + self._composed_instances = composed_info[0] + self._var_name_to_model_instances = composed_info[1] + self._additional_properties_model_instances = composed_info[2] + discarded_args = composed_info[3] + + for var_name, var_value in kwargs.items(): + if ( + var_name in discarded_args + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self._additional_properties_model_instances + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) + + @cached_property + def _composed_schemas(): + # we need this here to make our import statements work + # we must store _composed_schemas in here so the code is only run + # when we invoke this method. If we kept this at the class + # level we would get an error beause the class level + # code would be run when this module is imported, and these composed + # classes don't exist yet because their module has not finished + # loading + lazy_import() + return {"anyOf": [], "allOf": [], "oneOf": [DenseEmbedding, SparseEmbedding]} diff --git a/pinecone/core/openapi/inference/model/embeddings_list.py b/pinecone/core/openapi/inference/model/embeddings_list.py new file mode 100644 index 000000000..f8661e5e5 --- /dev/null +++ b/pinecone/core/openapi/inference/model/embeddings_list.py @@ -0,0 +1,288 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.embedding import Embedding + from pinecone.core.openapi.inference.model.embeddings_list_usage import EmbeddingsListUsage + + globals()["Embedding"] = Embedding + globals()["EmbeddingsListUsage"] = EmbeddingsListUsage + + +class EmbeddingsList(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "model": (str,), # noqa: E501 + "vector_type": (str,), # noqa: E501 + "data": ([Embedding],), # noqa: E501 + "usage": (EmbeddingsListUsage,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "model": "model", # noqa: E501 + "vector_type": "vector_type", # noqa: E501 + "data": "data", # noqa: E501 + "usage": "usage", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, model, vector_type, data, usage, *args, **kwargs): # noqa: E501 + """EmbeddingsList - a model defined in OpenAPI + + Args: + model (str): The model used to generate the embeddings + vector_type (str): Indicates whether the response data contains 'dense' or 'sparse' embeddings. + data ([Embedding]): The embeddings generated for the inputs. + usage (EmbeddingsListUsage): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.vector_type = vector_type + self.data = data + self.usage = usage + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, model, vector_type, data, usage, *args, **kwargs): # noqa: E501 + """EmbeddingsList - a model defined in OpenAPI + + Args: + model (str): The model used to generate the embeddings + vector_type (str): Indicates whether the response data contains 'dense' or 'sparse' embeddings. + data ([Embedding]): The embeddings generated for the inputs. + usage (EmbeddingsListUsage): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.vector_type = vector_type + self.data = data + self.usage = usage + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/embeddings_list_usage.py b/pinecone/core/openapi/inference/model/embeddings_list_usage.py new file mode 100644 index 000000000..98b2fe646 --- /dev/null +++ b/pinecone/core/openapi/inference/model/embeddings_list_usage.py @@ -0,0 +1,254 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +class EmbeddingsListUsage(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {("total_tokens",): {"inclusive_minimum": 0}} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + "total_tokens": (int,) # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "total_tokens": "total_tokens" # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """EmbeddingsListUsage - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + total_tokens (int): Total number of tokens consumed across all inputs. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """EmbeddingsListUsage - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + total_tokens (int): Total number of tokens consumed across all inputs. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/error_response.py b/pinecone/core/openapi/inference/model/error_response.py new file mode 100644 index 000000000..6671b17b0 --- /dev/null +++ b/pinecone/core/openapi/inference/model/error_response.py @@ -0,0 +1,274 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.error_response_error import ErrorResponseError + + globals()["ErrorResponseError"] = ErrorResponseError + + +class ErrorResponse(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "status": (int,), # noqa: E501 + "error": (ErrorResponseError,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "status": "status", # noqa: E501 + "error": "error", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, status, error, *args, **kwargs): # noqa: E501 + """ErrorResponse - a model defined in OpenAPI + + Args: + status (int): The HTTP status code of the error. + error (ErrorResponseError): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.status = status + self.error = error + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, status, error, *args, **kwargs): # noqa: E501 + """ErrorResponse - a model defined in OpenAPI + + Args: + status (int): The HTTP status code of the error. + error (ErrorResponseError): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.status = status + self.error = error + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/error_response_error.py b/pinecone/core/openapi/inference/model/error_response_error.py new file mode 100644 index 000000000..c15c0b672 --- /dev/null +++ b/pinecone/core/openapi/inference/model/error_response_error.py @@ -0,0 +1,291 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +class ErrorResponseError(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + ("code",): { + "OK": "OK", + "UNKNOWN": "UNKNOWN", + "INVALID_ARGUMENT": "INVALID_ARGUMENT", + "DEADLINE_EXCEEDED": "DEADLINE_EXCEEDED", + "QUOTA_EXCEEDED": "QUOTA_EXCEEDED", + "NOT_FOUND": "NOT_FOUND", + "ALREADY_EXISTS": "ALREADY_EXISTS", + "PERMISSION_DENIED": "PERMISSION_DENIED", + "UNAUTHENTICATED": "UNAUTHENTICATED", + "RESOURCE_EXHAUSTED": "RESOURCE_EXHAUSTED", + "FAILED_PRECONDITION": "FAILED_PRECONDITION", + "ABORTED": "ABORTED", + "OUT_OF_RANGE": "OUT_OF_RANGE", + "UNIMPLEMENTED": "UNIMPLEMENTED", + "INTERNAL": "INTERNAL", + "UNAVAILABLE": "UNAVAILABLE", + "DATA_LOSS": "DATA_LOSS", + "FORBIDDEN": "FORBIDDEN", + } + } + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + "code": (str,), # noqa: E501 + "message": (str,), # noqa: E501 + "details": ({str: (bool, dict, float, int, list, str, none_type)},), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "code": "code", # noqa: E501 + "message": "message", # noqa: E501 + "details": "details", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, code, message, *args, **kwargs): # noqa: E501 + """ErrorResponseError - a model defined in OpenAPI + + Args: + code (str): + message (str): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + details ({str: (bool, dict, float, int, list, str, none_type)}): Additional information about the error. This field is not guaranteed to be present. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.code = code + self.message = message + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, code, message, *args, **kwargs): # noqa: E501 + """ErrorResponseError - a model defined in OpenAPI + + Args: + code (str): + message (str): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + details ({str: (bool, dict, float, int, list, str, none_type)}): Additional information about the error. This field is not guaranteed to be present. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.code = code + self.message = message + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/ranked_document.py b/pinecone/core/openapi/inference/model/ranked_document.py new file mode 100644 index 000000000..66a52725f --- /dev/null +++ b/pinecone/core/openapi/inference/model/ranked_document.py @@ -0,0 +1,278 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.document import Document + + globals()["Document"] = Document + + +class RankedDocument(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "index": (int,), # noqa: E501 + "score": (float,), # noqa: E501 + "document": (Document,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "index": "index", # noqa: E501 + "score": "score", # noqa: E501 + "document": "document", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, index, score, *args, **kwargs): # noqa: E501 + """RankedDocument - a model defined in OpenAPI + + Args: + index (int): The index position of the document from the original request. + score (float): The relevance of the document to the query, normalized between 0 and 1, with scores closer to 1 indicating higher relevance. + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + document (Document): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.index = index + self.score = score + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, index, score, *args, **kwargs): # noqa: E501 + """RankedDocument - a model defined in OpenAPI + + Args: + index (int): The index position of the document from the original request. + score (float): The relevance of the document to the query, normalized between 0 and 1, with scores closer to 1 indicating higher relevance. + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + document (Document): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.index = index + self.score = score + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/rerank_request.py b/pinecone/core/openapi/inference/model/rerank_request.py new file mode 100644 index 000000000..51ed4a17f --- /dev/null +++ b/pinecone/core/openapi/inference/model/rerank_request.py @@ -0,0 +1,296 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.document import Document + + globals()["Document"] = Document + + +class RerankRequest(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "model": (str,), # noqa: E501 + "query": (str,), # noqa: E501 + "documents": ([Document],), # noqa: E501 + "top_n": (int,), # noqa: E501 + "return_documents": (bool,), # noqa: E501 + "rank_fields": ([str],), # noqa: E501 + "parameters": ({str: (bool, dict, float, int, list, str, none_type)},), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "model": "model", # noqa: E501 + "query": "query", # noqa: E501 + "documents": "documents", # noqa: E501 + "top_n": "top_n", # noqa: E501 + "return_documents": "return_documents", # noqa: E501 + "rank_fields": "rank_fields", # noqa: E501 + "parameters": "parameters", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, model, query, documents, *args, **kwargs): # noqa: E501 + """RerankRequest - a model defined in OpenAPI + + Args: + model (str): The [model](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) to use for reranking. + query (str): The query to rerank documents against. + documents ([Document]): The documents to rerank. + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + top_n (int): The number of results to return sorted by relevance. Defaults to the number of inputs. [optional] # noqa: E501 + return_documents (bool): Whether to return the documents in the response. [optional] if omitted the server will use the default value of True. # noqa: E501 + rank_fields ([str]): The field(s) to consider for reranking. If not provided, the default is `[\"text\"]`. The number of fields supported is [model-specific](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models). [optional] if omitted the server will use the default value of ["text"]. # noqa: E501 + parameters ({str: (bool, dict, float, int, list, str, none_type)}): Additional model-specific parameters. Refer to the [model guide](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) for available model parameters. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.query = query + self.documents = documents + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, model, query, documents, *args, **kwargs): # noqa: E501 + """RerankRequest - a model defined in OpenAPI + + Args: + model (str): The [model](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) to use for reranking. + query (str): The query to rerank documents against. + documents ([Document]): The documents to rerank. + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + top_n (int): The number of results to return sorted by relevance. Defaults to the number of inputs. [optional] # noqa: E501 + return_documents (bool): Whether to return the documents in the response. [optional] if omitted the server will use the default value of True. # noqa: E501 + rank_fields ([str]): The field(s) to consider for reranking. If not provided, the default is `[\"text\"]`. The number of fields supported is [model-specific](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models). [optional] if omitted the server will use the default value of ["text"]. # noqa: E501 + parameters ({str: (bool, dict, float, int, list, str, none_type)}): Additional model-specific parameters. Refer to the [model guide](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) for available model parameters. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.query = query + self.documents = documents + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/rerank_result.py b/pinecone/core/openapi/inference/model/rerank_result.py new file mode 100644 index 000000000..892ee6ec3 --- /dev/null +++ b/pinecone/core/openapi/inference/model/rerank_result.py @@ -0,0 +1,282 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.ranked_document import RankedDocument + from pinecone.core.openapi.inference.model.rerank_result_usage import RerankResultUsage + + globals()["RankedDocument"] = RankedDocument + globals()["RerankResultUsage"] = RerankResultUsage + + +class RerankResult(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "model": (str,), # noqa: E501 + "data": ([RankedDocument],), # noqa: E501 + "usage": (RerankResultUsage,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "model": "model", # noqa: E501 + "data": "data", # noqa: E501 + "usage": "usage", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, model, data, usage, *args, **kwargs): # noqa: E501 + """RerankResult - a model defined in OpenAPI + + Args: + model (str): The model used to rerank documents. + data ([RankedDocument]): The reranked documents. + usage (RerankResultUsage): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.data = data + self.usage = usage + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, model, data, usage, *args, **kwargs): # noqa: E501 + """RerankResult - a model defined in OpenAPI + + Args: + model (str): The model used to rerank documents. + data ([RankedDocument]): The reranked documents. + usage (RerankResultUsage): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.model = model + self.data = data + self.usage = usage + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/rerank_result_usage.py b/pinecone/core/openapi/inference/model/rerank_result_usage.py new file mode 100644 index 000000000..9d8d9e2bb --- /dev/null +++ b/pinecone/core/openapi/inference/model/rerank_result_usage.py @@ -0,0 +1,254 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +class RerankResultUsage(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {("rerank_units",): {"inclusive_minimum": 0}} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + "rerank_units": (int,) # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "rerank_units": "rerank_units" # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """RerankResultUsage - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + rerank_units (int): The number of rerank units consumed by this operation. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """RerankResultUsage - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + rerank_units (int): The number of rerank units consumed by this operation. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/sparse_embedding.py b/pinecone/core/openapi/inference/model/sparse_embedding.py new file mode 100644 index 000000000..47f0f0762 --- /dev/null +++ b/pinecone/core/openapi/inference/model/sparse_embedding.py @@ -0,0 +1,284 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +def lazy_import(): + from pinecone.core.openapi.inference.model.vector_type import VectorType + + globals()["VectorType"] = VectorType + + +class SparseEmbedding(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + lazy_import() + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + lazy_import() + return { + "sparse_values": ([float],), # noqa: E501 + "sparse_indices": ([int],), # noqa: E501 + "vector_type": (VectorType,), # noqa: E501 + "sparse_tokens": ([str],), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + "sparse_values": "sparse_values", # noqa: E501 + "sparse_indices": "sparse_indices", # noqa: E501 + "vector_type": "vector_type", # noqa: E501 + "sparse_tokens": "sparse_tokens", # noqa: E501 + } + + read_only_vars = {} + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, sparse_values, sparse_indices, vector_type, *args, **kwargs): # noqa: E501 + """SparseEmbedding - a model defined in OpenAPI + + Args: + sparse_values ([float]): The sparse embedding values. + sparse_indices ([int]): The sparse embedding indices. + vector_type (VectorType): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + sparse_tokens ([str]): The normalized tokens used to create the sparse embedding. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.sparse_values = sparse_values + self.sparse_indices = sparse_indices + self.vector_type = vector_type + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, sparse_values, sparse_indices, vector_type, *args, **kwargs): # noqa: E501 + """SparseEmbedding - a model defined in OpenAPI + + Args: + sparse_values ([float]): The sparse embedding values. + sparse_indices ([int]): The sparse embedding indices. + vector_type (VectorType): + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + sparse_tokens ([str]): The normalized tokens used to create the sparse embedding. [optional] # noqa: E501 + """ + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _path_to_item = kwargs.pop("_path_to_item", ()) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + self.sparse_values = sparse_values + self.sparse_indices = sparse_indices + self.vector_type = vector_type + for var_name, var_value in kwargs.items(): + if ( + var_name not in self.attribute_map + and self._configuration is not None + and self._configuration.discard_unknown_keys + and self.additional_properties_type is None + ): + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise PineconeApiAttributeError( + f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes." + ) diff --git a/pinecone/core/openapi/inference/model/vector_type.py b/pinecone/core/openapi/inference/model/vector_type.py new file mode 100644 index 000000000..99a0bb6b8 --- /dev/null +++ b/pinecone/core/openapi/inference/model/vector_type.py @@ -0,0 +1,272 @@ +""" +Pinecone Inference API + +Pinecone is a vector database that makes it easy to search and retrieve billions of high-dimensional vectors. # noqa: E501 + +The version of the OpenAPI document: 2025-01 +Contact: support@pinecone.io +Generated by: https://openapi-generator.tech +""" + +import re # noqa: F401 +import sys # noqa: F401 + +from pinecone.openapi_support import ( # noqa: F401 + PineconeApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) +from pinecone.openapi_support.model_utils import OpenApiModel +from pinecone.openapi_support.exceptions import PineconeApiAttributeError + + +class VectorType(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = {("value",): {"DENSE": "dense", "SPARSE": "sparse"}} + + validations = {} + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, dict, float, int, list, str, none_type) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return {"value": (str,)} + + @cached_property + def discriminator(): + return None + + attribute_map = {} + + read_only_vars = set() + + _composed_schemas = None + + required_properties = set( + [ + "_data_store", + "_check_type", + "_spec_property_naming", + "_path_to_item", + "_configuration", + "_visited_composed_classes", + ] + ) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): + """VectorType - a model defined in OpenAPI + + Note that value can be passed either in args or in kwargs, but not in both. + + Args: + args[0] (str): Indicates whether this is a 'dense' or 'sparse' embedding.., must be one of ["dense", "sparse", ] # noqa: E501 + + Keyword Args: + value (str): Indicates whether this is a 'dense' or 'sparse' embedding.., must be one of ["dense", "sparse", ] # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + # required up here when default value is not given + _path_to_item = kwargs.pop("_path_to_item", ()) + + if "value" in kwargs: + value = kwargs.pop("value") + elif args: + args = list(args) + value = args.pop(0) + else: + raise PineconeApiTypeError( + "value is required, but not passed in args or kwargs and doesn't have default", + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise PineconeApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." + % (kwargs, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): + """VectorType - a model defined in OpenAPI + + Note that value can be passed either in args or in kwargs, but not in both. + + Args: + args[0] (str): Indicates whether this is a 'dense' or 'sparse' embedding., must be one of ["dense", "sparse", ] # noqa: E501 + + Keyword Args: + value (str): Indicates whether this is a 'dense' or 'sparse' embedding., must be one of ["dense", "sparse", ] # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + # required up here when default value is not given + _path_to_item = kwargs.pop("_path_to_item", ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if "value" in kwargs: + value = kwargs.pop("value") + elif args: + args = list(args) + value = args.pop(0) + else: + raise PineconeApiTypeError( + "value is required, but not passed in args or kwargs and doesn't have default", + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + _check_type = kwargs.pop("_check_type", True) + _spec_property_naming = kwargs.pop("_spec_property_naming", False) + _configuration = kwargs.pop("_configuration", None) + _visited_composed_classes = kwargs.pop("_visited_composed_classes", ()) + + if args: + raise PineconeApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." + % (args, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise PineconeApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." + % (kwargs, self.__class__.__name__), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + return self diff --git a/pinecone/core/openapi/inference/models/__init__.py b/pinecone/core/openapi/inference/models/__init__.py new file mode 100644 index 000000000..bbb2cd34d --- /dev/null +++ b/pinecone/core/openapi/inference/models/__init__.py @@ -0,0 +1,26 @@ +# flake8: noqa + +# import all models into this package +# if you have many models here with many references from one model to another this may +# raise a RecursionError +# to avoid this, import only the models that you directly need like: +# from from pinecone.core.openapi.inference.model.pet import Pet +# or import this package, but before doing it, use: +# import sys +# sys.setrecursionlimit(n) + +from pinecone.core.openapi.inference.model.dense_embedding import DenseEmbedding +from pinecone.core.openapi.inference.model.document import Document +from pinecone.core.openapi.inference.model.embed_request import EmbedRequest +from pinecone.core.openapi.inference.model.embed_request_inputs import EmbedRequestInputs +from pinecone.core.openapi.inference.model.embedding import Embedding +from pinecone.core.openapi.inference.model.embeddings_list import EmbeddingsList +from pinecone.core.openapi.inference.model.embeddings_list_usage import EmbeddingsListUsage +from pinecone.core.openapi.inference.model.error_response import ErrorResponse +from pinecone.core.openapi.inference.model.error_response_error import ErrorResponseError +from pinecone.core.openapi.inference.model.ranked_document import RankedDocument +from pinecone.core.openapi.inference.model.rerank_request import RerankRequest +from pinecone.core.openapi.inference.model.rerank_result import RerankResult +from pinecone.core.openapi.inference.model.rerank_result_usage import RerankResultUsage +from pinecone.core.openapi.inference.model.sparse_embedding import SparseEmbedding +from pinecone.core.openapi.inference.model.vector_type import VectorType diff --git a/pinecone/data/__init__.py b/pinecone/data/__init__.py index b0e901102..30c09153d 100644 --- a/pinecone/data/__init__.py +++ b/pinecone/data/__init__.py @@ -8,7 +8,12 @@ Vector, ) from .dataclasses import * -from .import_error import Index, IndexClientInstantiationError +from .import_error import ( + Index, + IndexClientInstantiationError, + Inference, + InferenceInstantiationError, +) from .index_asyncio import * from .errors import ( VectorDictionaryMissingKeysError, @@ -21,3 +26,4 @@ ) from .features.bulk_import import ImportErrorMode +from .features.inference import Inference as _Inference, RerankModel, EmbedModel diff --git a/pinecone/data/features/inference/__init__.py b/pinecone/data/features/inference/__init__.py new file mode 100644 index 000000000..30e933301 --- /dev/null +++ b/pinecone/data/features/inference/__init__.py @@ -0,0 +1,6 @@ +from .repl_overrides import install_repl_overrides +from .inference import Inference +from .inference_asyncio import AsyncioInference +from .inference_request_builder import RerankModel, EmbedModel + +install_repl_overrides() diff --git a/pinecone/data/features/inference/inference.py b/pinecone/data/features/inference/inference.py new file mode 100644 index 000000000..5e3613225 --- /dev/null +++ b/pinecone/data/features/inference/inference.py @@ -0,0 +1,180 @@ +import logging +from typing import Optional, Dict, List, Union, Any + +from pinecone.openapi_support import ApiClient +from pinecone.core.openapi.inference.apis import InferenceApi +from pinecone.core.openapi.inference.models import EmbeddingsList, RerankResult +from pinecone.core.openapi.inference import API_VERSION +from pinecone.utils import setup_openapi_client, build_plugin_setup_client + +from pinecone_plugin_interface import load_and_install as install_plugins + +from .inference_request_builder import ( + InferenceRequestBuilder, + EmbedModel as EmbedModelEnum, + RerankModel as RerankModelEnum, +) + +logger = logging.getLogger(__name__) + + +class Inference: + """ + The `Inference` class configures and uses the Pinecone Inference API to generate embeddings and + rank documents. + + :param config: A `pinecone.config.Config` object, configured and built in the Pinecone class. + :type config: `pinecone.config.Config`, required + """ + + EmbedModel = EmbedModelEnum + RerankModel = RerankModelEnum + + def __init__(self, config, openapi_config, **kwargs): + self.config = config + self.openapi_config = openapi_config + self.pool_threads = kwargs.get("pool_threads", 1) + + self.__inference_api = setup_openapi_client( + api_client_klass=ApiClient, + api_klass=InferenceApi, + config=config, + openapi_config=openapi_config, + pool_threads=kwargs.get("pool_threads", 1), + api_version=API_VERSION, + ) + + self.load_plugins() + + def load_plugins(self): + """@private""" + try: + # I don't expect this to ever throw, but wrapping this in a + # try block just in case to make sure a bad plugin doesn't + # halt client initialization. + openapi_client_builder = build_plugin_setup_client( + config=self.config, + openapi_config=self.openapi_config, + pool_threads=self.pool_threads, + ) + install_plugins(self, openapi_client_builder) + except Exception as e: + logger.error(f"Error loading plugins: {e}") + + def embed( + self, + model: Union[EmbedModelEnum, str], + inputs: Union[str, List[Dict], List[str]], + parameters: Optional[Dict[str, Any]] = None, + ) -> EmbeddingsList: + """ + Generates embeddings for the provided inputs using the specified model and (optional) parameters. + + :param model: The model to use for generating embeddings. + :type model: str, required + + :param inputs: A list of items to generate embeddings for. + :type inputs: list, required + + :param parameters: A dictionary of parameters to use when generating embeddings. + :type parameters: dict, optional + + :return: EmbeddingsList object with keys `data`, `model`, and `usage`. The `data` key contains a list of + `n` embeddings, where `n` = len(inputs) and type(n) = Embedding. Precision of returned embeddings is either + float16 or float32, with float32 being the default. `model` key is the model used to generate the embeddings. + `usage` key contains the total number of tokens used at request-time. + + Example: + >>> inputs = ["Who created the first computer?"] + >>> outputs = pc.inference.embed(model="multilingual-e5-large", inputs=inputs, parameters={"input_type": "passage", "truncate": "END"}) + >>> print(outputs) + EmbeddingsList( + model='multilingual-e5-large', + data=[ + {'values': [0.1, ...., 0.2]}, + ], + usage={'total_tokens': 6} + ) + """ + request_body = InferenceRequestBuilder.embed_request( + model=model, inputs=inputs, parameters=parameters + ) + return self.__inference_api.embed(embed_request=request_body) + + def rerank( + self, + model: Union[RerankModelEnum, str], + query: str, + documents: Union[List[str], List[Dict[str, Any]]], + rank_fields: List[str] = ["text"], + return_documents: bool = True, + top_n: Optional[int] = None, + parameters: Optional[Dict[str, Any]] = None, + ) -> RerankResult: + """ + Rerank documents with associated relevance scores that represent the relevance of each document + to the provided query using the specified model. + + :param model: The model to use for reranking. + :type model: str, required + + :param query: The query to compare with documents. + :type query: str, required + + :param documents: A list of documents or strings to rank. + :type documents: list, required + + :param rank_fields: A list of document fields to use for ranking. Defaults to ["text"]. + :type rank_fields: list, optional + + :param return_documents: Whether to include the documents in the response. Defaults to True. + :type return_documents: bool, optional + + :param top_n: How many documents to return. Defaults to len(documents). + :type top_n: int, optional + + :param parameters: A dictionary of parameters to use when ranking documents. + :type parameters: dict, optional + + :return: RerankResult object with keys `data` and `usage`. The `data` key contains a list of + `n` documents, where `n` = `top_n` and type(n) = Document. The documents are sorted in order of + relevance, with the first being the most relevant. The `index` field can be used to locate the document + relative to the list of documents specified in the request. Each document contains a `score` key + representing how close the document relates to the query. + + Example: + >>> result = pc.inference.rerank( + model="bge-reranker-v2-m3", + query="Tell me about tech companies", + documents=[ + "Apple is a popular fruit known for its sweetness and crisp texture.", + "Software is still eating the world.", + "Many people enjoy eating apples as a healthy snack.", + "Acme Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces.", + "An apple a day keeps the doctor away, as the saying goes.", + ], + top_n=2, + return_documents=True, + ) + >>> print(result) + RerankResult( + model='bge-reranker-v2-m3', + data=[ + { index=3, score=0.020980744, + document={text="Acme Inc. has rev..."} }, + { index=1, score=0.00034015716, + document={text="Software is still..."} } + ], + usage={'rerank_units': 1} + ) + """ + rerank_request = InferenceRequestBuilder.rerank( + model=model, + query=query, + documents=documents, + rank_fields=rank_fields, + return_documents=return_documents, + top_n=top_n, + parameters=parameters, + ) + return self.__inference_api.rerank(rerank_request=rerank_request) diff --git a/pinecone/data/features/inference/inference_asyncio.py b/pinecone/data/features/inference/inference_asyncio.py new file mode 100644 index 000000000..43d5a8926 --- /dev/null +++ b/pinecone/data/features/inference/inference_asyncio.py @@ -0,0 +1,149 @@ +from typing import Optional, Dict, List, Union, Any + +from pinecone.openapi_support import AsyncioApiClient +from pinecone.core.openapi.inference.api.inference_api import AsyncioInferenceApi +from pinecone.core.openapi.inference.models import EmbeddingsList, RerankResult +from pinecone.core.openapi.inference import API_VERSION +from pinecone.utils import setup_openapi_client + +from .inference_request_builder import InferenceRequestBuilder + + +class AsyncioInference: + """ + The `Inference` class configures and uses the Pinecone Inference API to generate embeddings and + rank documents. + + :param config: A `pinecone.config.Config` object, configured and built in the Pinecone class. + :type config: `pinecone.config.Config`, required + """ + + def __init__(self, config, openapi_config, **kwargs): + self.config = config + + self.__inference_api = setup_openapi_client( + api_client_klass=AsyncioApiClient, + api_klass=AsyncioInferenceApi, + config=config, + openapi_config=openapi_config, + pool_threads=kwargs.get("pool_threads", 1), + api_version=API_VERSION, + ) + + async def embed( + self, + model: str, + inputs: Union[str, List[Dict], List[str]], + parameters: Optional[Dict[str, Any]] = None, + ) -> EmbeddingsList: + """ + Generates embeddings for the provided inputs using the specified model and (optional) parameters. + + :param model: The model to use for generating embeddings. + :type model: str, required + + :param inputs: A list of items to generate embeddings for. + :type inputs: list, required + + :param parameters: A dictionary of parameters to use when generating embeddings. + :type parameters: dict, optional + + :return: EmbeddingsList object with keys `data`, `model`, and `usage`. The `data` key contains a list of + `n` embeddings, where `n` = len(inputs) and type(n) = Embedding. Precision of returned embeddings is either + float16 or float32, with float32 being the default. `model` key is the model used to generate the embeddings. + `usage` key contains the total number of tokens used at request-time. + + Example: + >>> inputs = ["Who created the first computer?"] + >>> outputs = await pc.inference.embed(model="multilingual-e5-large", inputs=inputs, parameters={"input_type": "passage", "truncate": "END"}) + >>> print(outputs) + EmbeddingsList( + model='multilingual-e5-large', + data=[ + {'values': [0.1, ...., 0.2]}, + ], + usage={'total_tokens': 6} + ) + """ + request_body = InferenceRequestBuilder.embed_request( + model=model, inputs=inputs, parameters=parameters + ) + return await self.__inference_api.embed(embed_request=request_body) + + async def rerank( + self, + model: str, + query: str, + documents: Union[List[str], List[Dict[str, Any]]], + rank_fields: List[str] = ["text"], + return_documents: bool = True, + top_n: Optional[int] = None, + parameters: Optional[Dict[str, Any]] = None, + ) -> RerankResult: + """ + Rerank documents with associated relevance scores that represent the relevance of each document + to the provided query using the specified model. + + :param model: The model to use for reranking. + :type model: str, required + + :param query: The query to compare with documents. + :type query: str, required + + :param documents: A list of documents or strings to rank. + :type documents: list, required + + :param rank_fields: A list of document fields to use for ranking. Defaults to ["text"]. + :type rank_fields: list, optional + + :param return_documents: Whether to include the documents in the response. Defaults to True. + :type return_documents: bool, optional + + :param top_n: How many documents to return. Defaults to len(documents). + :type top_n: int, optional + + :param parameters: A dictionary of parameters to use when ranking documents. + :type parameters: dict, optional + + :return: RerankResult object with keys `data` and `usage`. The `data` key contains a list of + `n` documents, where `n` = `top_n` and type(n) = Document. The documents are sorted in order of + relevance, with the first being the most relevant. The `index` field can be used to locate the document + relative to the list of documents specified in the request. Each document contains a `score` key + representing how close the document relates to the query. + + Example: + >>> result = await pc.inference.rerank( + model="bge-reranker-v2-m3", + query="Tell me about tech companies", + documents=[ + "Apple is a popular fruit known for its sweetness and crisp texture.", + "Software is still eating the world.", + "Many people enjoy eating apples as a healthy snack.", + "Acme Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces.", + "An apple a day keeps the doctor away, as the saying goes.", + ], + top_n=2, + return_documents=True, + ) + >>> print(result) + RerankResult( + model='bge-reranker-v2-m3', + data=[ + { index=3, score=0.020980744, + document={text="Acme Inc. has rev..."} }, + { index=1, score=0.00034015716, + document={text="Software is still..."} } + ], + usage={'rerank_units': 1} + ) + """ + rerank_request = InferenceRequestBuilder.rerank( + model=model, + query=query, + documents=documents, + rank_fields=rank_fields, + return_documents=return_documents, + top_n=top_n, + parameters=parameters, + ) + return await self.__inference_api.rerank(rerank_request=rerank_request) diff --git a/pinecone/data/features/inference/inference_request_builder.py b/pinecone/data/features/inference/inference_request_builder.py new file mode 100644 index 000000000..1c4e7e12a --- /dev/null +++ b/pinecone/data/features/inference/inference_request_builder.py @@ -0,0 +1,87 @@ +from enum import Enum +from typing import Optional, Union, List, Dict, Any + +from pinecone.core.openapi.inference.models import ( + EmbedRequest, + EmbedRequestInputs, + Document, + RerankRequest, +) + + +class EmbedModel(Enum): + Multilingual_E5_Large = "multilingual-e5-large" + Pinecone_Sparse_English_V0 = "pinecone-sparse-english-v0" + + +class RerankModel(Enum): + Bge_Reranker_V2_M3 = "bge-reranker-v2-m3" + Cohere_Rerank_3_5 = "cohere-rerank-3.5" + Pinecone_Rerank_v0 = "pinecone-rerank-v0" + + +class InferenceRequestBuilder: + @staticmethod + def embed_request( + model: Union[EmbedModel, str], + inputs: Union[str, List[Dict], List[str]], + parameters: Optional[Dict[str, Any]] = None, + ) -> EmbedRequest: + if isinstance(model, EmbedModel): + model = model.value + embeddings_inputs: List[EmbedRequestInputs] = [] + if isinstance(inputs, str): + embeddings_inputs = [EmbedRequestInputs(text=inputs)] + elif isinstance(inputs, list) and len(inputs) > 0: + if isinstance(inputs[0], str): + embeddings_inputs = [EmbedRequestInputs(text=i) for i in inputs] + elif isinstance(inputs[0], dict): + embeddings_inputs = [EmbedRequestInputs(**i) for i in inputs] + else: + raise Exception("Invalid type for variable 'inputs'") + else: + raise Exception("Invalid type for variable 'inputs'") + + if parameters: + return EmbedRequest(model=model, inputs=embeddings_inputs, parameters=parameters) + else: + return EmbedRequest(model=model, inputs=embeddings_inputs) + + @staticmethod + def rerank( + model: Union[RerankModel, str], + query: str, + documents: Union[List[str], List[Dict[str, Any]]], + rank_fields: List[str] = ["text"], + return_documents: bool = True, + top_n: Optional[int] = None, + parameters: Optional[Dict[str, Any]] = None, + ) -> RerankRequest: + if isinstance(model, RerankModel): + model = model.value + else: + model = str(model) + + if isinstance(documents, list) and len(documents) > 0: + if isinstance(documents[0], str): + documents = [Document(text=doc) for doc in documents] + elif isinstance(documents[0], dict): + documents = [Document(**doc) for doc in documents] + else: + raise Exception("Invalid type for variable 'documents'") + else: + raise Exception("Invalid type or value for variable 'documents'") + + args: Dict[str, Any] = { + "model": model, + "query": query, + "documents": documents, + "rank_fields": rank_fields, + "return_documents": return_documents, + } + if top_n is not None: + args["top_n"] = top_n + if parameters is not None: + args["parameters"] = parameters + + return RerankRequest(**args) diff --git a/pinecone/data/features/inference/repl_overrides.py b/pinecone/data/features/inference/repl_overrides.py new file mode 100644 index 000000000..ecc50e805 --- /dev/null +++ b/pinecone/data/features/inference/repl_overrides.py @@ -0,0 +1,106 @@ +from pinecone.core.openapi.inference.models import ( + EmbeddingsList as OpenAPIEmbeddingsList, + SparseEmbedding as OpenAPISparseEmbedding, + DenseEmbedding as OpenAPIDenseEmbedding, + Document as OpenAPIDocument, + RerankResult as OpenAPIRerankResult, + RankedDocument as OpenAPIRankedDocument, +) + + +def present_list(mylist): + if not mylist: + return [] + if len(mylist) <= 5: + # Show list as usual when fewer than 5 items. + # This number is arbitrary and can be adjusted + # but it seems silly to show the abbreviated + # message with (2 more) or whatever when the + # number of items is so small and it's no problem + # to display the real values. + return f"[{', '.join(repr(x) for x in mylist)}]" + first_part = ", ".join(repr(x) for x in mylist[:2]) + last_part = ", ".join(repr(x) for x in mylist[-2:]) + formatted_values = f"[{first_part}, ..., {last_part}]" + return formatted_values + + +def sparse_embedding_to_str(self: OpenAPISparseEmbedding): + formatted_sparse_values = present_list(self.sparse_values) + formatted_sparse_indices = present_list(self.sparse_indices) + formatted_sparse_tokens = present_list(self.sparse_tokens) + parts = [ + "'vector_type': sparse", + f"'sparse_values': {formatted_sparse_values}", + f"'sparse_indices': {formatted_sparse_indices}", + ] + if self.sparse_tokens: + parts.append(f"'sparse_tokens': {formatted_sparse_tokens}") + return "{{{}}}".format(", ".join(parts)) + + +def dense_embedding_to_str(self: OpenAPIDenseEmbedding): + formatted_values = present_list(self.values) + parts = ["'vector_type': dense", f"'values': {formatted_values}"] + return "{{{}}}".format(", ".join(parts)) + + +def embedding_list_to_string(self: OpenAPIEmbeddingsList): + if len(self.data) == 0: + formatted_embeddings = "[]" + elif len(self.data) <= 5: + formatted_embeddings = ( + "[\n " + ",\n ".join([embedding.to_str() for embedding in self.data]) + "\n ]" + ) + else: + omitted_msg = f"... ({len(self.data) - 4} more embeddings) ..." + items_to_show = ( + [e.to_str() for e in self.data[:2]] + + [omitted_msg] + + [e.to_str() for e in self.data[-2:]] + ) + formatted_embeddings = "[\n " + ",\n ".join(items_to_show) + "\n ]" + + return """EmbeddingsList( + model='{self.model}', + vector_type='{self.vector_type}', + data={formatted_embeddings}, + usage={self.usage} +)""".format(self=self, formatted_embeddings=formatted_embeddings) + + +def rank_result_document_to_str(self: OpenAPIDocument): + return ",\n ".join([f"{k}={repr(v)}" for k, v in self.to_dict().items()]) + + +def rank_result_item_to_str(self: OpenAPIRankedDocument): + if self.document is None: + document_str = "" + else: + document_str = f"document={{\n {self.document}\n }}" + + return f"{{\n index={self.index},\n score={self.score},\n {document_str}\n }}" + + +def rerank_result_to_str(self: OpenAPIRerankResult): + if len(self.data) == 0: + formatted_rerank = "[]" + else: + formatted_rerank = ( + "[" + ",".join([rank_result_item.to_str() for rank_result_item in self.data]) + "]" + ) + + return f"""RerankResult( + model='{self.model}', + data={formatted_rerank}, + usage={self.usage} +)""" + + +def install_repl_overrides(): + OpenAPIDenseEmbedding.to_str = dense_embedding_to_str + OpenAPISparseEmbedding.to_str = sparse_embedding_to_str + OpenAPIEmbeddingsList.to_str = embedding_list_to_string + OpenAPIDocument.to_str = rank_result_document_to_str + OpenAPIRankedDocument.to_str = rank_result_item_to_str + OpenAPIRerankResult.to_str = rerank_result_to_str diff --git a/pinecone/data/import_error.py b/pinecone/data/import_error.py index 751872fdd..6da76a434 100644 --- a/pinecone/data/import_error.py +++ b/pinecone/data/import_error.py @@ -25,6 +25,38 @@ def __init__(self, index_args, index_kwargs): super().__init__(self.message) +class InferenceInstantiationError(Exception): + def __init__(self): + self.message = """You are attempting to access the Inference client directly from the pinecone module. Inference functionality such as `embed` and `rerank` should only be accessed through the parent Pinecone client instance. + + INCORRECT USAGE: + ``` + import pinecone + + pinecone.Inference().embed(...) + ``` + + CORRECT USAGE: + ``` + from pinecone import Pinecone + + pc = Pinecone(api_key='your-api-key') + + embeddings = pc.inference.embed( + model='multilingual-e5-large', + inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], + parameters={"input_type": "query", "truncate": "END"}, + ) + ``` + """ + super().__init__(self.message) + + class Index: def __init__(self, *args, **kwargs): raise IndexClientInstantiationError(args, kwargs) + + +class Inference: + def __init__(self, *args, **kwargs): + raise InferenceInstantiationError() diff --git a/pinecone/deprecated_plugins.py b/pinecone/deprecated_plugins.py new file mode 100644 index 000000000..c412ba302 --- /dev/null +++ b/pinecone/deprecated_plugins.py @@ -0,0 +1,17 @@ +class DeprecatedPluginError(Exception): + def __init__(self, message): + super().__init__(message) + + +def check_for_deprecated_plugins(): + try: + from pinecone_plugins.inference import __installables__ # type: ignore + + if __installables__ is not None: + raise DeprecatedPluginError( + "The `pinecone-plugin-inference` package has been deprecated. The embed and rerank functionality has been incorporated into the main `pinecone` package with no need for additional plugins. Please remove the `pinecone-plugin-inference` package from your dependencies to ensure you have the most up-to-date version of these features." + ) + except ImportError: + # ImportError is expected if the plugin is not installed, + # which is the good case. + pass diff --git a/pinecone/openapi_support/api_version.py b/pinecone/openapi_support/api_version.py index 6194b0306..5bb584158 100644 --- a/pinecone/openapi_support/api_version.py +++ b/pinecone/openapi_support/api_version.py @@ -2,4 +2,4 @@ # Do not edit this file manually. API_VERSION = "2025-01" -APIS_REPO_SHA = "4d632eeba4c110aec798f95cf8b4ae8d0953996d" +APIS_REPO_SHA = "63e97dcd8a46cfb0687e23eab1f02300824f6e9d" diff --git a/poetry.lock b/poetry.lock index effc66254..b2ac36c89 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1166,20 +1166,6 @@ pygments = ">=2.12.0" [package.extras] dev = ["hypothesis", "mypy", "pdoc-pyo3-sample-library (==1.0.11)", "pygments (>=2.14.0)", "pytest", "pytest-cov", "pytest-timeout", "ruff", "tox", "types-pygments"] -[[package]] -name = "pinecone-plugin-inference" -version = "2.0.0" -description = "Embeddings plugin for Pinecone SDK" -optional = false -python-versions = "<4.0,>=3.8" -files = [ - {file = "pinecone_plugin_inference-2.0.0-py3-none-any.whl", hash = "sha256:260368b5584b12196d9031322c115c2329fb6c948a43952e3534061382f0d522"}, - {file = "pinecone_plugin_inference-2.0.0.tar.gz", hash = "sha256:b29709cd5d82829f8d0361a3f5b51dab622da59533578097be04e73eeecf3ee5"}, -] - -[package.dependencies] -pinecone-plugin-interface = ">=0.0.7,<0.0.8" - [[package]] name = "pinecone-plugin-interface" version = "0.0.7" @@ -1924,4 +1910,4 @@ grpc = ["googleapis-common-protos", "grpcio", "grpcio", "lz4", "protobuf", "prot [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "2f6cf4f5393190aa4b8db33f40aa2a56967ee7325713f1e5abea0abac5f2929e" +content-hash = "ed686662d6a59d70a89367d84a17857aef9143eeff20610190c95dcb5be7c71b" diff --git a/pyproject.toml b/pyproject.toml index 36c637e1b..911cb5ef9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,6 @@ lz4 = { version = ">=3.1.3", optional = true } protobuf = { version = "^5.29", optional = true } protoc-gen-openapiv2 = {version = "^0.0.1", optional = true } pinecone-plugin-interface = "^0.0.7" -pinecone-plugin-inference = "^2.0.0" python-dateutil = ">=2.5.3" aiohttp = "^3.11.5" httpx = "^0.28.1" diff --git a/tests/integration/data/test_inference.py b/tests/integration/data/test_inference.py new file mode 100644 index 000000000..900981cb8 --- /dev/null +++ b/tests/integration/data/test_inference.py @@ -0,0 +1,219 @@ +import pytest +from pinecone import Pinecone, PineconeApiException, RerankModel, EmbedModel + + +class TestEmbed: + @pytest.mark.parametrize( + "model_input,model_output", + [ + (EmbedModel.Multilingual_E5_Large, "multilingual-e5-large"), + ("multilingual-e5-large", "multilingual-e5-large"), + ], + ) + def test_create_embeddings(self, client: Pinecone, model_input, model_output): + embeddings = client.inference.embed( + model=model_input, + inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], + parameters={"input_type": "query", "truncate": "END"}, + ) + assert embeddings.vector_type == "dense" + assert embeddings.model == model_output + assert len(embeddings.data) == 2 + assert len(embeddings.data[0].values) == 1024 + assert len(embeddings.data[1].values) == 1024 + + # Dict-style bracket accessors + assert embeddings["vector_type"] == "dense" + assert embeddings["model"] == model_output + assert len(embeddings["data"]) == 2 + + # Dict-style get accessors for embeddings + assert embeddings.get("vector_type") == "dense" + assert embeddings.get("model") == model_output + assert len(embeddings.get("data")) == 2 + assert len(embeddings.get("data")[0]["values"]) == 1024 + assert len(embeddings.get("data")[1]["values"]) == 1024 + assert embeddings.get("model") == model_output + + @pytest.mark.parametrize( + "model_input,model_output", + [ + (EmbedModel.Pinecone_Sparse_English_V0, "pinecone-sparse-english-v0"), + ("pinecone-sparse-english-v0", "pinecone-sparse-english-v0"), + ], + ) + def test_create_sparse_embeddings(self, client: Pinecone, model_input, model_output): + embeddings = client.inference.embed( + model=model_input, + inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], + parameters={"input_type": "query", "truncate": "END"}, + ) + assert embeddings.vector_type == "sparse" + assert embeddings.model == model_output + assert len(embeddings.data) == 2 + print(embeddings.data[0].sparse_values) + + def test_create_embeddings_input_objects(self, client): + embeddings = client.inference.embed( + model=client.inference.EmbedModel.Multilingual_E5_Large, + inputs=[ + {"text": "The quick brown fox jumps over the lazy dog."}, + {"text": "lorem ipsum"}, + ], + parameters={"input_type": "query", "truncate": "END"}, + ) + assert len(embeddings.get("data")) == 2 + assert len(embeddings.get("data")[0]["values"]) == 1024 + assert len(embeddings.get("data")[1]["values"]) == 1024 + assert embeddings.get("model") == "multilingual-e5-large" + + def test_create_embeddings_input_string(self, client): + embeddings = client.inference.embed( + model=EmbedModel.Multilingual_E5_Large, + inputs="The quick brown fox jumps over the lazy dog.", + parameters={"input_type": "query", "truncate": "END"}, + ) + assert len(embeddings.get("data")) == 1 + assert len(embeddings.get("data")[0]["values"]) == 1024 + assert embeddings.get("model") == "multilingual-e5-large" + + def test_create_embeddings_invalid_input_empty_list(self, client): + embedding_model = "multilingual-e5-large" + with pytest.raises(Exception) as excinfo: + client.inference.embed( + model=embedding_model, + inputs=[], + parameters={"input_type": "query", "truncate": "END"}, + ) + assert str(excinfo.value).find("Invalid type") >= 0 + + def test_create_embeddings_invalid_input(self, client): + embedding_model = "multilingual-e5-large" + with pytest.raises(Exception) as excinfo: + client.inference.embed( + model=embedding_model, + inputs=[{"INVALID_FIELD": "this should be rejected"}], + parameters={"input_type": "query", "truncate": "END"}, + ) + assert str(excinfo.value).find("INVALID_FIELD") >= 0 + + def test_can_attempt_to_use_unknown_models(self, client): + # We don't want to reject these requests client side because we want + # to remain forwards compatible with any new models that become available + model = "unknown-model" + with pytest.raises(PineconeApiException) as excinfo: + client.inference.embed( + model=model, + inputs="The quick brown fox jumps over the lazy dog.", + parameters={"input_type": "query", "truncate": "END"}, + ) + assert "Model 'unknown-model' not found" in str(excinfo.value) + + +class TestRerank: + @pytest.mark.parametrize( + "model_input,model_output", + [ + (RerankModel.Bge_Reranker_V2_M3, "bge-reranker-v2-m3"), + ("bge-reranker-v2-m3", "bge-reranker-v2-m3"), + ], + ) + def test_rerank_basic(self, client, model_input, model_output): + # Rerank model can be passed as string or enum + result = client.inference.rerank( + model=model_input, + query="i love dogs", + documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], + top_n=1, + return_documents=True, + ) + assert len(result.data) == 1 + assert result.data[0].index == 1 + assert result.data[0].document.text == "everyone loves dogs" + assert result.model == model_output + assert isinstance(result.usage.rerank_units, int) + assert result.usage.rerank_units == 1 + + def test_rerank_basic_document_dicts(self, client): + model = "bge-reranker-v2-m3" + result = client.inference.rerank( + model="bge-reranker-v2-m3", + query="i love dogs", + documents=[ + {"id": "123", "text": "dogs are pretty cool"}, + {"id": "789", "text": "I'm a cat person"}, + {"id": "456", "text": "everyone loves dogs"}, + ], + top_n=1, + return_documents=True, + ) + assert len(result.data) == 1 + assert result.data[0].index == 2 + assert result.data[0].document.text == "everyone loves dogs" + assert result.model == model + assert isinstance(result.usage.rerank_units, int) + assert result.usage.rerank_units == 1 + + def test_rerank_document_dicts_custom_field(self, client): + model = "bge-reranker-v2-m3" + result = client.inference.rerank( + model="bge-reranker-v2-m3", + query="i love dogs", + documents=[ + {"id": "123", "my_field": "dogs are pretty cool"}, + {"id": "456", "my_field": "everyone loves dogs"}, + {"id": "789", "my_field": "I'm a cat person"}, + ], + rank_fields=["my_field"], + top_n=1, + return_documents=True, + ) + assert len(result.data) == 1 + assert result.data[0].index == 1 + assert result.data[0].document.my_field == "everyone loves dogs" + assert result.model == model + assert isinstance(result.usage.rerank_units, int) + assert result.usage.rerank_units == 1 + + def test_rerank_basic_default_top_n(self, client): + model = "bge-reranker-v2-m3" + result = client.inference.rerank( + model=model, + query="i love dogs", + documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], + return_documents=True, + ) + assert len(result.data) == 3 + assert result.data[0].index == 1 + assert result.data[0].document.text == "everyone loves dogs" + assert result.model == model + assert isinstance(result.usage.rerank_units, int) + assert result.usage.rerank_units == 1 + + def test_rerank_no_return_documents(self, client: Pinecone): + model = client.inference.RerankModel.Bge_Reranker_V2_M3 + result = client.inference.rerank( + model=model, + query="i love dogs", + documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], + return_documents=False, + ) + assert len(result.data) == 3 + assert result.data[0].index == 1 + assert not result.data[0].document + assert result.model == model.value + assert isinstance(result.usage.rerank_units, int) + assert result.usage.rerank_units == 1 + + def test_rerank_allows_unknown_models_to_be_passed(self, client: Pinecone): + # We don't want to reject these requests client side because we want + # to remain forwards compatible with any new models that become available + model = "unknown-model" + with pytest.raises(PineconeApiException) as excinfo: + client.inference.rerank( + model=model, + query="i love dogs", + documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], + return_documents=False, + ) + assert "Model 'unknown-model' not found" in str(excinfo.value) diff --git a/tests/integration/inference/__init__.py b/tests/integration/inference/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integration/inference/conftest.py b/tests/integration/inference/conftest.py deleted file mode 100644 index 2c345033d..000000000 --- a/tests/integration/inference/conftest.py +++ /dev/null @@ -1,7 +0,0 @@ -import pytest -from ..helpers import get_environment_var - - -@pytest.fixture() -def api_key(): - return get_environment_var("PINECONE_API_KEY") diff --git a/tests/integration/inference/test_embed.py b/tests/integration/inference/test_embed.py deleted file mode 100644 index 0e52ec2c2..000000000 --- a/tests/integration/inference/test_embed.py +++ /dev/null @@ -1,48 +0,0 @@ -import pytest -from pinecone import Pinecone -from pinecone.grpc import PineconeGRPC -from pinecone.exceptions import PineconeApiException - - -class TestInferencePlugin: - def test_embed(self, api_key): - pc = Pinecone(api_key=api_key) - - embedding_model = "multilingual-e5-large" - embeddings = pc.inference.embed( - model=embedding_model, - inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], - parameters={"input_type": "query", "truncate": "END"}, - ) - - assert len(embeddings.get("data")) == 2 - assert len(embeddings.get("data")[0]["values"]) == 1024 - assert len(embeddings.get("data")[1]["values"]) == 1024 - assert embeddings.get("model") == embedding_model - - def test_embed_grpc(self, api_key): - pc = PineconeGRPC(api_key=api_key) - - embedding_model = "multilingual-e5-large" - embeddings = pc.inference.embed( - model=embedding_model, - inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], - parameters={"input_type": "query", "truncate": "END"}, - ) - - assert len(embeddings.get("data")) == 2 - assert len(embeddings.get("data")[0]["values"]) == 1024 - assert len(embeddings.get("data")[1]["values"]) == 1024 - assert embeddings.get("model") == embedding_model - - def test_embed_exception(self, api_key): - pc = Pinecone(api_key=api_key) - - with pytest.raises(PineconeApiException) as e_info: - embedding_model = "DOES NOT EXIST" - pc.inference.embed( - model=embedding_model, - inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], - parameters={"input_type": "query", "truncate": "END"}, - ) - assert e_info.value.status == 404 diff --git a/tests/integration/inference/test_rerank.py b/tests/integration/inference/test_rerank.py deleted file mode 100644 index 6c8ee5d56..000000000 --- a/tests/integration/inference/test_rerank.py +++ /dev/null @@ -1,55 +0,0 @@ -import pytest -from pinecone import Pinecone -from pinecone.grpc import PineconeGRPC -from pinecone.exceptions import PineconeApiException - - -class TestInferencePluginRerank: - def test_rerank(self, api_key): - pc = Pinecone(api_key=api_key) - - model = "bge-reranker-v2-m3" - result = pc.inference.rerank( - model=model, - query="i love dogs", - documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], - top_n=1, - return_documents=True, - ) - assert len(result.data) == 1 - assert result.data[0].index == 1 - assert result.data[0].document.text == "everyone loves dogs" - assert result.model == model - assert isinstance(result.usage.rerank_units, int) - assert result.usage.rerank_units == 1 - - def test_rerank_grpc(self, api_key): - pc = PineconeGRPC(api_key=api_key) - - model = "bge-reranker-v2-m3" - result = pc.inference.rerank( - model=model, - query="i love dogs", - documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], - top_n=1, - return_documents=True, - ) - assert len(result.data) == 1 - assert result.data[0].index == 1 - assert result.data[0].document.text == "everyone loves dogs" - assert result.model == model - assert isinstance(result.usage.rerank_units, int) - assert result.usage.rerank_units == 1 - - def test_rerank_exception(self, api_key): - pc = Pinecone(api_key=api_key) - with pytest.raises(PineconeApiException) as e_info: - pc.inference.rerank( - model="DOES NOT EXIST", - query="i love dogs", - documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"], - rank_fields=["custom-field"], - top_n=1, - return_documents=True, - ) - assert e_info.value.status == 404