Skip to content

Commit 051ccb8

Browse files
chore: exposing PineconeDocumentStore show_progress bar parameter and disabling it for tests (#2799)
* exposing show_progress bar parameter and disabling it for tests * fixing unit test
1 parent 312e463 commit 051ccb8

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
dimension: int = 768,
4444
spec: dict[str, Any] | None = None,
4545
metric: Literal["cosine", "euclidean", "dotproduct"] = "cosine",
46+
show_progress: bool = True,
4647
):
4748
"""
4849
Creates a new PineconeDocumentStore instance.
@@ -62,6 +63,8 @@ def __init__(
6263
If not provided, a default spec with serverless deployment in the `us-east-1` region will be used
6364
(compatible with the free tier).
6465
:param metric: The metric to use for similarity search. This parameter is only used when creating a new index.
66+
:param show_progress: Whether to show a progress bar when upserting documents. Set to False to disable
67+
(e.g. in tests or scripts where quiet output is preferred).
6568
6669
"""
6770
self.api_key = api_key
@@ -72,6 +75,7 @@ def __init__(
7275
self.spec = spec
7376
self.dimension = dimension
7477
self.index_name = index
78+
self.show_progress = show_progress
7579

7680
self._index: _Index | None = None
7781
self._async_index: _IndexAsyncio | None = None
@@ -199,6 +203,7 @@ def to_dict(self) -> dict[str, Any]:
199203
namespace=self.namespace,
200204
batch_size=self.batch_size,
201205
metric=self.metric,
206+
show_progress=self.show_progress,
202207
)
203208

204209
def count_documents(self) -> int:
@@ -244,7 +249,10 @@ def write_documents(self, documents: list[Document], policy: DuplicatePolicy = D
244249
documents_for_pinecone = self._prepare_documents_for_writing(documents, policy)
245250

246251
result = self._index.upsert(
247-
vectors=documents_for_pinecone, namespace=self.namespace, batch_size=self.batch_size
252+
vectors=documents_for_pinecone,
253+
namespace=self.namespace,
254+
batch_size=self.batch_size,
255+
show_progress=self.show_progress,
248256
)
249257

250258
# if the operation is successful, result will have the upserted_count attribute
@@ -268,7 +276,10 @@ async def write_documents_async(
268276
documents_for_pinecone = self._prepare_documents_for_writing(documents, policy)
269277

270278
result = await self._async_index.upsert(
271-
vectors=documents_for_pinecone, namespace=self.namespace, batch_size=self.batch_size
279+
vectors=documents_for_pinecone,
280+
namespace=self.namespace,
281+
batch_size=self.batch_size,
282+
show_progress=self.show_progress,
272283
)
273284

274285
# if the operation is successful, result will have the upserted_count attribute

integrations/pinecone/tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def document_store(request):
3434
index=index,
3535
namespace=namespace,
3636
dimension=dimension,
37+
show_progress=False,
3738
)
3839

3940
# Override some methods to wait for the documents to be available
@@ -75,6 +76,7 @@ async def document_store_async(request):
7576
index=index,
7677
namespace=namespace,
7778
dimension=dimension,
79+
show_progress=False,
7880
)
7981

8082
# Override some methods to wait for the documents to be available

integrations/pinecone/tests/test_document_store.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_to_from_dict(mock_pinecone, monkeypatch):
9999
"batch_size": 50,
100100
"metric": "euclidean",
101101
"spec": {"serverless": {"region": "us-east-1", "cloud": "aws"}},
102+
"show_progress": True,
102103
},
103104
}
104105
assert document_store.to_dict() == dict_output
@@ -111,6 +112,7 @@ def test_to_from_dict(mock_pinecone, monkeypatch):
111112
assert document_store.dimension == 60
112113
assert document_store.metric == "euclidean"
113114
assert document_store.spec == {"serverless": {"region": "us-east-1", "cloud": "aws"}}
115+
assert document_store.show_progress is True
114116

115117

116118
def test_init_fails_wo_api_key(monkeypatch):
@@ -238,6 +240,7 @@ def test_serverless_index_creation_from_scratch(delete_sleep_time):
238240
dimension=30,
239241
metric="euclidean",
240242
spec={"serverless": {"region": "us-east-1", "cloud": "aws"}},
243+
show_progress=False,
241244
)
242245
# Trigger the connection
243246
_ = ds._initialize_index()

integrations/pinecone/tests/test_embedding_retriever.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
45
from unittest.mock import Mock, patch
56

67
import pytest
@@ -36,6 +37,7 @@ def test_to_dict(mock_pinecone, monkeypatch):
3637
namespace="test-namespace",
3738
batch_size=50,
3839
dimension=512,
40+
show_progress=False,
3941
)
4042
retriever = PineconeEmbeddingRetriever(document_store=document_store)
4143
res = retriever.to_dict()
@@ -53,6 +55,7 @@ def test_to_dict(mock_pinecone, monkeypatch):
5355
},
5456
"index": "default",
5557
"namespace": "test-namespace",
58+
"show_progress": False,
5659
"batch_size": 50,
5760
"dimension": 512,
5861
"spec": {"serverless": {"region": "us-east-1", "cloud": "aws"}},

0 commit comments

Comments
 (0)