Skip to content

Commit 938c379

Browse files
committed
upsert working?
1 parent 46539e7 commit 938c379

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

pinecone/pinecone.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
if TYPE_CHECKING:
1717
from pinecone.config import Config, OpenApiConfiguration
1818
from pinecone.db_data import _Index as Index, _IndexAsyncio as IndexAsyncio
19+
from pinecone.repository.data import _Repository as Repository
1920
from pinecone.db_control.index_host_store import IndexHostStore
2021
from pinecone.core.openapi.db_control.api.manage_indexes_api import ManageIndexesApi
2122
from pinecone.db_control.types import CreateIndexForModelEmbedTypedDict, ConfigureIndexEmbed
@@ -518,6 +519,35 @@ def IndexAsyncio(self, host: str, **kwargs) -> "IndexAsyncio":
518519
**kwargs,
519520
)
520521

522+
def Repository(self, name: str = "", host: str = "", **kwargs) -> "Repository":
523+
from pinecone.repository.data import _Repository
524+
525+
if name == "" and host == "":
526+
raise ValueError("Either name or host must be specified")
527+
528+
pt = kwargs.pop("pool_threads", None) or self._pool_threads
529+
api_key = self._config.api_key
530+
openapi_config = self._openapi_config
531+
532+
if host != "":
533+
check_realistic_host(host)
534+
535+
# Use host url if it is provided
536+
repository_host = normalize_host(host)
537+
else:
538+
# TODO, get host url from describe_kb using the index name
539+
# index_host = self.db.index._get_host(name)
540+
raise ValueError("host lookup not yet supported, specify host parameter")
541+
542+
return _Repository(
543+
host=repository_host,
544+
api_key=api_key,
545+
pool_threads=pt,
546+
openapi_config=openapi_config,
547+
source_tag=self.config.source_tag,
548+
**kwargs,
549+
)
550+
521551

522552
def check_realistic_host(host: str) -> None:
523553
""":meta private:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .repository import Repository, DocumentForUpsert, UpsertDocumentResponse
2+
3+
4+
_Repository = Repository # alias for backwards compatibility
5+
6+
7+
__all__ = ["_Repository", "DocumentForUpsert", "UpsertDocumentResponse"]
8+
9+
10+
def __getattr__(name):
11+
if name in locals():
12+
return locals()[name]
13+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

pinecone/repository/data/repository.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,14 @@ def __init__(
6666
api_version=API_VERSION,
6767
)
6868

69-
self._api_client = self._vector_api.api_client
70-
71-
self._bulk_import_resource = None
72-
""" :meta private: """
73-
74-
self._namespace_resource = None
75-
""" :meta private: """
76-
77-
# Pass the same api_client to the ImportFeatureMixin
78-
super().__init__(api_client=self._api_client)
69+
self._api_client = self._repository_api.api_client
7970

8071
def upsert(
8172
self, namespace: str, document: Union[Dict[str, Any], DocumentForUpsert], **kwargs
8273
) -> UpsertDocumentResponse:
83-
self._repository_api.upsert_document(namespace=namespace, document=document, **kwargs)
74+
if isinstance(document, dict):
75+
document = DocumentForUpsert(**document)
76+
77+
return self._repository_api.upsert_document(
78+
namespace=namespace, document_for_upsert=document, **kwargs
79+
)

0 commit comments

Comments
 (0)