Skip to content

Commit c0f2a47

Browse files
committed
fix types
1 parent 933f226 commit c0f2a47

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

  • integrations/pinecone/src/haystack_integrations/document_stores/pinecone

integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def write_documents(self, documents: list[Document], policy: DuplicatePolicy = D
246246
vectors=documents_for_pinecone, namespace=self.namespace, batch_size=self.batch_size
247247
)
248248

249-
written_docs = result["upserted_count"]
250-
return written_docs
249+
# if the operation is successful, result will have the upserted_count attribute
250+
return result.upserted_count # type: ignore[union-attr]
251251

252252
async def write_documents_async(
253253
self, documents: list[Document], policy: DuplicatePolicy = DuplicatePolicy.NONE
@@ -270,9 +270,8 @@ async def write_documents_async(
270270
vectors=documents_for_pinecone, namespace=self.namespace, batch_size=self.batch_size
271271
)
272272

273-
written_docs = result["upserted_count"]
274-
275-
return written_docs
273+
# if the operation is successful, result will have the upserted_count attribute
274+
return result.upserted_count # type: ignore[union-attr]
276275

277276
def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
278277
"""
@@ -473,8 +472,8 @@ def _convert_meta_to_int(metadata: dict[str, Any]) -> dict[str, Any]:
473472

474473
return metadata
475474

476-
def _convert_query_result_to_documents(self, query_result: dict[str, Any]) -> list[Document]:
477-
pinecone_docs = query_result["matches"]
475+
def _convert_query_result_to_documents(self, query_result: Any) -> list[Document]:
476+
pinecone_docs = query_result.matches
478477
documents = []
479478
for pinecone_doc in pinecone_docs:
480479
content = pinecone_doc["metadata"].pop("content", None)
@@ -524,7 +523,9 @@ def valid_type(value: Any) -> bool:
524523

525524
document.meta = new_meta
526525

527-
def _convert_documents_to_pinecone_format(self, documents: list[Document]) -> list[dict[str, Any]]:
526+
def _convert_documents_to_pinecone_format(
527+
self, documents: list[Document]
528+
) -> list[tuple[str, list[float], dict[str, Any]]]:
528529
documents_for_pinecone = []
529530
for document in documents:
530531
embedding = copy(document.embedding)
@@ -538,11 +539,11 @@ def _convert_documents_to_pinecone_format(self, documents: list[Document]) -> li
538539
if document.meta:
539540
self._discard_invalid_meta(document)
540541

541-
doc_for_pinecone: dict[str, Any] = {"id": document.id, "values": embedding, "metadata": dict(document.meta)}
542+
metadata = dict(document.meta) if document.meta else {}
542543

543544
# we save content as metadata
544545
if document.content is not None:
545-
doc_for_pinecone["metadata"]["content"] = document.content
546+
metadata["content"] = document.content
546547

547548
# currently, storing blob in Pinecone is not supported
548549
if document.blob is not None:
@@ -559,12 +560,12 @@ def _convert_documents_to_pinecone_format(self, documents: list[Document]) -> li
559560
document_id=document.id,
560561
)
561562

562-
documents_for_pinecone.append(doc_for_pinecone)
563+
documents_for_pinecone.append((document.id, embedding, metadata))
563564
return documents_for_pinecone
564565

565566
def _prepare_documents_for_writing(
566567
self, documents: list[Document], policy: DuplicatePolicy
567-
) -> list[dict[str, Any]]:
568+
) -> list[tuple[str, list[float], dict[str, Any]]]:
568569
"""
569570
Helper method to prepare documents for writing to Pinecone.
570571
"""

0 commit comments

Comments
 (0)