Skip to content

Commit 5918ded

Browse files
Fix mypy and pylint issues
1 parent 24031b3 commit 5918ded

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

haystack/document_stores/pinecone.py

+18-20
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,13 @@ def _delete_vectors(self, index: str, ids: List[str], namespace: Optional[str])
394394

395395
def _upsert_vectors(
396396
self,
397-
index: str,
397+
index_name: str,
398398
data: List[Tuple],
399399
namespace: Optional[str],
400400
use_async: bool = False,
401401
batch_size: int = DEFAULT_BATCH_SIZE,
402402
) -> None:
403-
index = self.pinecone_indexes[index]
403+
index = self.pinecone_indexes[index_name]
404404
results = [
405405
index.upsert(vectors=batch, namespace=namespace, async_req=use_async)
406406
for batch in get_batches_from_generator(data, batch_size)
@@ -580,13 +580,15 @@ def write_documents(
580580
pool_threads = self.pinecone_indexes[index].pool_threads
581581
if use_async and pool_threads == 1:
582582
logger.warning(
583-
f"Documents will be upserted synchronosly, because the number of threads for Pinecone index is set to {pool_threads}. "
584-
f"To enable upsert in parallel, initialize PineconeDocumentStore() again setting parameter `pool_threads`."
583+
"Documents will be upserted synchronosly, because the number of threads for Pinecone index is set to %s. "
584+
"To enable upsert in parallel, initialize PineconeDocumentStore() again setting parameter `pool_threads`.",
585+
pool_threads,
585586
)
586587
elif not use_async and pool_threads != 1:
587588
logger.warning(
588-
f"Parameter `use_async` set to `False` will be ignored and documents will be upserted asynchronously, "
589-
f"because the number of threads for Pinecone index is set to {pool_threads}."
589+
"Parameter `use_async` set to `False` will be ignored and documents will be upserted asynchronously, "
590+
"because the number of threads for Pinecone index is set to %s.",
591+
pool_threads,
590592
)
591593

592594
field_map = self._create_document_field_map()
@@ -674,13 +676,7 @@ def write_documents(
674676

675677
data_to_write_to_pinecone = list(zip(ids, embeddings, metadata))
676678
# Store chunk by chunk (for regular upsert) or chunk by chunk (for async upsert) in vector store
677-
self._upsert_vectors(
678-
index=index,
679-
data=data_to_write_to_pinecone,
680-
namespace=namespace,
681-
use_async=use_async,
682-
batch_size=batch_size,
683-
)
679+
self._upsert_vectors(index, data_to_write_to_pinecone, namespace, use_async, batch_size) # type: ignore
684680
# Add IDs to ID list
685681
self._add_local_ids(index, ids)
686682
progress_bar.update(chunk_size)
@@ -753,13 +749,15 @@ def update_embeddings(
753749
pool_threads = self.pinecone_indexes[index].pool_threads
754750
if use_async and pool_threads == 1:
755751
logger.warning(
756-
f"Embeddings will be upserted synchronosly, because the number of threads for Pinecone index is {pool_threads}. "
757-
f"To enable upsert in parallel, initialize PineconeDocumentStore() again setting parameter `pool_threads`."
752+
"Embeddings will be upserted synchronosly, because the number of threads for Pinecone index is %s. "
753+
"To enable upsert in parallel, initialize PineconeDocumentStore() again setting parameter `pool_threads`.",
754+
pool_threads,
758755
)
759756
elif not use_async and pool_threads > 1:
760757
logger.warning(
761-
f"Parameter `use_async` set to `False` will be ignored and embeddings will be upserted asynchronously, "
762-
f"because the number of threads for Pinecone index is set to {pool_threads}."
758+
"Parameter `use_async` set to `False` will be ignored and embeddings will be upserted asynchronously, "
759+
"because the number of threads for Pinecone index is set to %s.",
760+
pool_threads,
763761
)
764762

765763
document_count = self.get_document_count(
@@ -828,7 +826,7 @@ def update_embeddings(
828826
ids.append(doc.id)
829827
# Update existing vectors in pinecone index
830828
data = list(zip(ids, embeddings.tolist(), metadata))
831-
self._upsert_vectors(index, data, namespace, use_async, batch_size)
829+
self._upsert_vectors(index, data, namespace, use_async, batch_size) # type: ignore
832830
# Add these vector IDs to local store
833831
self._add_local_ids(index, ids)
834832
progress_bar.set_description_str("Documents Processed")
@@ -1088,7 +1086,7 @@ def _move_documents_by_id_namespace(
10881086
embedding_matrix = [result["vectors"][_id]["values"] for _id in vector_id_matrix]
10891087
data_to_write_to_pinecone = list(zip(vector_id_matrix, embedding_matrix, meta_matrix))
10901088
# Store metadata nd embeddings in new target_namespace
1091-
self._upsert_vectors(index, data_to_write_to_pinecone, target_namespace, use_async=False)
1089+
self._upsert_vectors(index, data_to_write_to_pinecone, target_namespace, use_async=False) # type: ignore
10921090
# Delete vectors from source_namespace
10931091
self.delete_documents(index=index, ids=id_batch, namespace=source_namespace, drop_ids=False)
10941092
progress_bar.set_description_str("Documents Moved")
@@ -1214,7 +1212,7 @@ def update_document_meta(self, id: str, meta: Dict[str, str], index: Optional[st
12141212
if doc.embedding is not None:
12151213
meta = {"content": doc.content, "content_type": doc.content_type, **meta}
12161214
data = [(id, doc.embedding.tolist(), meta)]
1217-
self._upsert_vectors(index, data, self.namespace, use_async=False)
1215+
self._upsert_vectors(index, data, self.namespace, use_async=False) # type: ignore
12181216

12191217
def delete_documents(
12201218
self,

0 commit comments

Comments
 (0)