Skip to content

Commit

Permalink
Merge pull request #121 from pinecone-io/v2.1.0
Browse files Browse the repository at this point in the history
Release V2.1.0
  • Loading branch information
miararoy authored Jan 3, 2023
2 parents 75aaa19 + b627cc3 commit f9c7c2c
Show file tree
Hide file tree
Showing 11 changed files with 1,399 additions and 139 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@

## Unreleased Changes
None
## [2.1.0](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.13...v2.1.0)
- Fix "Connection Reset by peer" error after long idle periods
- Add typing and explicit names for arguments in all client operations
- Add docstrings to all client operations
- Support batch upsert by passing `batch_size` to `upsert` method
- Improve gRPC query results parsing performance

## [2.0.13](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.13...v2.0.12)

## [2.0.13](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.12...v2.0.13)
- Added support for collections
- Users can manage collections using ``create_collection`` , ``describe_collection`` and ``delete_collection`` calls.
- Users can specify additional ``source_collection`` parameter during index creation to create index from a collection
- The ```scale_index``` call is now deprecated in favor of ```configure_index``` , users can now modify both ``pod_type`` and ```replicas``` on existing indexes.
- Added support for vertical scaling. This can be done by changing ```pod_type ``` via the ```configure_index``` call or during index creation.
- Updated dependency requirements for grpc client.

## [2.0.12](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.12...v2.0.11)
## [2.0.12](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.11...v2.0.12)

- Changed grpcio verison to be > 1.44.1
- Sanitized repo by removing leftover files from old versions.
- Added more info to ```describe_index_stats``` call. The call now gives a namespace wise vector count breakdown.

## [2.0.11](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.11...v2.0.10)
## [2.0.11](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.10...v2.0.11)
### Changed
- Added support of querying by a single vector.
- This is a step in deprecating batch queries.
Expand Down
2 changes: 1 addition & 1 deletion pinecone/__version__
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.13
2.1.0
61 changes: 58 additions & 3 deletions pinecone/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
# Copyright (c) 2020-2021 Pinecone Systems Inc. All right reserved.
#
import logging
from typing import NamedTuple
import sys
from typing import NamedTuple, List
import os

import certifi
import requests
import configparser
import socket

from urllib3.connection import HTTPConnection

from pinecone.core.client.exceptions import ApiKeyError
from pinecone.core.api_action import ActionAPI, WhoAmIResponse
from pinecone.core.utils import warn_deprecated
from pinecone.core.utils.constants import CLIENT_VERSION, PARENT_LOGGER_NAME, DEFAULT_PARENT_LOGGER_LEVEL
from pinecone.core.utils.constants import CLIENT_VERSION, PARENT_LOGGER_NAME, DEFAULT_PARENT_LOGGER_LEVEL, \
TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT
from pinecone.core.client.configuration import Configuration as OpenApiConfiguration

__all__ = [
Expand All @@ -37,7 +42,7 @@ class _CONFIG:
Order of configs to load:
- configs specified explictly in reset
- configs specified explicitly in reset
- environment variables
- configs specified in the INI file
- default configs
Expand Down Expand Up @@ -109,6 +114,8 @@ def reset(self, config_file=None, **kwargs):
or default_openapi_config
)

openapi_config.socket_options = self._get_socket_options()

config = config._replace(openapi_config=openapi_config)
self._config = config

Expand Down Expand Up @@ -144,6 +151,54 @@ def _load_config_file(self, config_file: str) -> dict:
config_obj = {**parser["default"]}
return config_obj

@staticmethod
def _get_socket_options(do_keep_alive: bool = True,
keep_alive_idle_sec: int = TCP_KEEPIDLE,
keep_alive_interval_sec: int = TCP_KEEPINTVL,
keep_alive_tries: int = TCP_KEEPCNT
) -> List[tuple]:
"""
Returns the socket options to pass to OpenAPI's Rest client
Args:
do_keep_alive: Whether to enable TCP keep alive mechanism
keep_alive_idle_sec: Time in seconds of connection idleness before starting to send keep alive probes
keep_alive_interval_sec: Interval time in seconds between keep alive probe messages
keep_alive_tries: Number of failed keep alive tries (unanswered KA messages) before terminating the connection
Returns:
A list of socket options for the Rest client's connection pool
"""
# Source: https://www.finbourne.com/blog/the-mysterious-hanging-client-tcp-keep-alives

socket_params = HTTPConnection.default_socket_options
if not do_keep_alive:
return socket_params

socket_params += [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)]

# TCP Keep Alive Probes for different platforms
platform = sys.platform
# TCP Keep Alive Probes for Linux
if platform == 'linux' and hasattr(socket, "TCP_KEEPIDLE") and hasattr(socket, "TCP_KEEPINTVL") \
and hasattr(socket, "TCP_KEEPCNT"):
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, keep_alive_idle_sec)]
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, keep_alive_interval_sec)]
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, keep_alive_tries)]

# TCP Keep Alive Probes for Windows OS
# NOTE: Changing TCP KA params on windows is done via a different mechanism which OpenAPI's Rest client doesn't expose.
# Since the default values work well, it seems setting `(socket.SO_KEEPALIVE, 1)` is sufficient.
# Leaving this code here for future reference.
# elif platform == 'win32' and hasattr(socket, "SIO_KEEPALIVE_VALS"):
# socket.ioctl((socket.SIO_KEEPALIVE_VALS, (1, keep_alive_idle_sec * 1000, keep_alive_interval_sec * 1000)))

# TCP Keep Alive Probes for Mac OS
elif platform == 'darwin':
TCP_KEEPALIVE = 0x10
socket_params += [(socket.IPPROTO_TCP, TCP_KEEPALIVE, keep_alive_interval_sec)]

return socket_params

@property
def ENVIRONMENT(self):
return self._config.environment
Expand Down
2 changes: 1 addition & 1 deletion pinecone/core/client/model/query_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,4 @@ def __init__(self, top_k, *args, **kwargs): # noqa: E501
setattr(self, var_name, var_value)
if var_name in self.read_only_vars:
raise ApiAttributeError(f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate "
f"class with read only attributes.")
f"class with read only attributes.")
Loading

0 comments on commit f9c7c2c

Please sign in to comment.