|
16 | 16 | if TYPE_CHECKING:
|
17 | 17 | from pinecone.config import Config, OpenApiConfiguration
|
18 | 18 | from pinecone.db_data import _Index as Index, _IndexAsyncio as IndexAsyncio
|
| 19 | + from pinecone.repository_data import _Repository as Repository |
19 | 20 | from pinecone.db_control.index_host_store import IndexHostStore
|
20 | 21 | from pinecone.core.openapi.db_control.api.manage_indexes_api import ManageIndexesApi
|
21 | 22 | from pinecone.db_control.types import CreateIndexForModelEmbedTypedDict, ConfigureIndexEmbed
|
|
42 | 43 | RestoreJobModel,
|
43 | 44 | RestoreJobList,
|
44 | 45 | )
|
| 46 | + from pinecone.repository_control.models import RepositoryModel, RepositoryList, DocumentSchema |
45 | 47 |
|
46 | 48 |
|
47 | 49 | class Pinecone(PluginAware, LegacyPineconeDBControlInterface):
|
@@ -241,6 +243,9 @@ def __init__(
|
241 | 243 | self._db_control = None # Lazy initialization
|
242 | 244 | """ :meta private: """
|
243 | 245 |
|
| 246 | + self._repository_control = None # Lazy initialization |
| 247 | + """ :meta private: """ |
| 248 | + |
244 | 249 | super().__init__() # Initialize PluginAware
|
245 | 250 |
|
246 | 251 | @property
|
@@ -273,6 +278,21 @@ def db(self):
|
273 | 278 | )
|
274 | 279 | return self._db_control
|
275 | 280 |
|
| 281 | + @property |
| 282 | + def repository_ctrl(self): |
| 283 | + """ |
| 284 | + RepositoryControl is a namespace where an instance of the `pinecone.repository_control.RepositoryControl` class is lazily created and cached. |
| 285 | + """ |
| 286 | + if self._repository_control is None: |
| 287 | + from pinecone.repository_control.repository_control import RepositoryControl |
| 288 | + |
| 289 | + self._repository_control = RepositoryControl( |
| 290 | + config=self._config, |
| 291 | + openapi_config=self._openapi_config, |
| 292 | + pool_threads=self._pool_threads, |
| 293 | + ) |
| 294 | + return self._repository_control |
| 295 | + |
276 | 296 | @property
|
277 | 297 | def index_host_store(self) -> "IndexHostStore":
|
278 | 298 | """:meta private:"""
|
@@ -460,6 +480,26 @@ def list_restore_jobs(
|
460 | 480 | def describe_restore_job(self, *, job_id: str) -> "RestoreJobModel":
|
461 | 481 | return self.db.restore_job.describe(job_id=job_id)
|
462 | 482 |
|
| 483 | + def create_repository( |
| 484 | + self, |
| 485 | + name: str, |
| 486 | + spec: Union[Dict, "ServerlessSpec"], |
| 487 | + schema: Union[Dict, "DocumentSchema"], |
| 488 | + timeout: Optional[int] = None, |
| 489 | + ) -> "RepositoryModel": |
| 490 | + return self.repository_ctrl.repository.create( |
| 491 | + name=name, spec=spec, schema=schema, timeout=timeout |
| 492 | + ) |
| 493 | + |
| 494 | + def describe_repository(self, name: str) -> "RepositoryModel": |
| 495 | + return self.repository_ctrl.repository.describe(name=name) |
| 496 | + |
| 497 | + def list_repositories(self) -> "RepositoryList": |
| 498 | + return self.repository_ctrl.repository.list() |
| 499 | + |
| 500 | + def delete_repository(self, name: str, timeout: Optional[int] = None): |
| 501 | + return self.repository_ctrl.repository.delete(name=name, timeout=timeout) |
| 502 | + |
463 | 503 | @staticmethod
|
464 | 504 | def from_texts(*args, **kwargs):
|
465 | 505 | """:meta private:"""
|
@@ -518,6 +558,34 @@ def IndexAsyncio(self, host: str, **kwargs) -> "IndexAsyncio":
|
518 | 558 | **kwargs,
|
519 | 559 | )
|
520 | 560 |
|
| 561 | + def Repository(self, name: str = "", host: str = "", **kwargs) -> "Repository": |
| 562 | + from pinecone.repository_data import _Repository |
| 563 | + |
| 564 | + if name == "" and host == "": |
| 565 | + raise ValueError("Either name or host must be specified") |
| 566 | + |
| 567 | + pt = kwargs.pop("pool_threads", None) or self._pool_threads |
| 568 | + api_key = self._config.api_key |
| 569 | + openapi_config = self._openapi_config |
| 570 | + |
| 571 | + if host != "": |
| 572 | + check_realistic_host(host) |
| 573 | + |
| 574 | + # Use host url if it is provided |
| 575 | + repository_host = normalize_host(host) |
| 576 | + else: |
| 577 | + # Otherwise, get host url from describe_repository using the repo name |
| 578 | + repository_host = self.repository_ctrl.repository._get_host(name) |
| 579 | + |
| 580 | + return _Repository( |
| 581 | + host=repository_host, |
| 582 | + api_key=api_key, |
| 583 | + pool_threads=pt, |
| 584 | + openapi_config=openapi_config, |
| 585 | + source_tag=self.config.source_tag, |
| 586 | + **kwargs, |
| 587 | + ) |
| 588 | + |
521 | 589 |
|
522 | 590 | def check_realistic_host(host: str) -> None:
|
523 | 591 | """:meta private:
|
|
0 commit comments