|
1 | 1 | from tqdm.autonotebook import tqdm
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from typing import Union, List, Optional, Dict, Any
|
4 | 5 |
|
5 | 6 | from pinecone.config import ConfigBuilder
|
6 | 7 |
|
7 | 8 | from pinecone.core.openapi.shared import API_VERSION
|
8 |
| -from pinecone.core.openapi.data.models import SparseValues |
9 | 9 | from pinecone.core.openapi.data import ApiClient
|
10 | 10 | from pinecone.core.openapi.data.models import (
|
11 | 11 | FetchResponse,
|
|
22 | 22 | UpdateRequest,
|
23 | 23 | DescribeIndexStatsRequest,
|
24 | 24 | ListResponse,
|
| 25 | + SparseValues, |
25 | 26 | )
|
26 |
| -from .features.bulk_import import ImportFeatureMixin |
27 | 27 | from pinecone.core.openapi.data.api.data_plane_api import DataPlaneApi
|
28 |
| -from ..utils import setup_openapi_client, parse_non_empty_args |
| 28 | +from ..utils import ( |
| 29 | + setup_openapi_client, |
| 30 | + parse_non_empty_args, |
| 31 | + build_plugin_setup_client, |
| 32 | + validate_and_convert_errors, |
| 33 | +) |
| 34 | +from .features.bulk_import import ImportFeatureMixin |
29 | 35 | from .vector_factory import VectorFactory
|
30 | 36 |
|
| 37 | +from pinecone_plugin_interface import load_and_install as install_plugins |
| 38 | + |
| 39 | +logger = logging.getLogger(__name__) |
| 40 | + |
31 | 41 | __all__ = [
|
32 | 42 | "Index",
|
33 | 43 | "FetchResponse",
|
|
47 | 57 | "SparseValues",
|
48 | 58 | ]
|
49 | 59 |
|
50 |
| -from ..utils.error_handling import validate_and_convert_errors |
51 |
| - |
52 | 60 | _OPENAPI_ENDPOINT_PARAMS = (
|
53 | 61 | "_return_http_data_only",
|
54 | 62 | "_preload_content",
|
@@ -89,20 +97,38 @@ def __init__(
|
89 | 97 | **kwargs,
|
90 | 98 | )
|
91 | 99 |
|
92 |
| - self._config = ConfigBuilder.build( |
| 100 | + self.config = ConfigBuilder.build( |
93 | 101 | api_key=api_key, host=host, additional_headers=additional_headers, **kwargs
|
94 | 102 | )
|
95 |
| - openapi_config = ConfigBuilder.build_openapi_config(self._config, openapi_config) |
| 103 | + self._openapi_config = ConfigBuilder.build_openapi_config(self.config, openapi_config) |
| 104 | + self._pool_threads = pool_threads |
96 | 105 |
|
97 | 106 | self._vector_api = setup_openapi_client(
|
98 | 107 | api_client_klass=ApiClient,
|
99 | 108 | api_klass=DataPlaneApi,
|
100 |
| - config=self._config, |
101 |
| - openapi_config=openapi_config, |
102 |
| - pool_threads=pool_threads, |
| 109 | + config=self.config, |
| 110 | + openapi_config=self._openapi_config, |
| 111 | + pool_threads=self._pool_threads, |
103 | 112 | api_version=API_VERSION,
|
104 | 113 | )
|
105 | 114 |
|
| 115 | + self._load_plugins() |
| 116 | + |
| 117 | + def _load_plugins(self): |
| 118 | + """@private""" |
| 119 | + try: |
| 120 | + # I don't expect this to ever throw, but wrapping this in a |
| 121 | + # try block just in case to make sure a bad plugin doesn't |
| 122 | + # halt client initialization. |
| 123 | + openapi_client_builder = build_plugin_setup_client( |
| 124 | + config=self.config, |
| 125 | + openapi_config=self._openapi_config, |
| 126 | + pool_threads=self._pool_threads, |
| 127 | + ) |
| 128 | + install_plugins(self, openapi_client_builder) |
| 129 | + except Exception as e: |
| 130 | + logger.error(f"Error loading plugins in Index: {e}") |
| 131 | + |
106 | 132 | def __enter__(self):
|
107 | 133 | return self
|
108 | 134 |
|
|
0 commit comments