Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions haystack/document_stores/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def __init__(
environment: str = "us-west1-gcp",
pinecone_index: Optional["pinecone.Index"] = None,
embedding_dim: int = 768,
pods: int = 1,
pod_type: str = "p1.x1",
return_embedding: bool = False,
index: str = "document",
similarity: str = "cosine",
Expand All @@ -98,6 +100,8 @@ def __init__(
regions are supported, contact Pinecone [here](https://www.pinecone.io/contact/) if required.
:param pinecone_index: pinecone-client Index object, an index will be initialized or loaded if not specified.
:param embedding_dim: The embedding vector size.
:param pods: The number of pods for the index to use, including replicas. Defaults to 1.
:param pod_type: The type of pod to use. Defaults to `"p1.x1"`.
:param return_embedding: Whether to return document embeddings.
:param index: Name of index in document store to use.
:param similarity: The similarity function used to compare document vectors. `"cosine"` is the default
Expand Down Expand Up @@ -151,6 +155,8 @@ def __init__(
self.duplicate_documents = duplicate_documents

# Pinecone index params
self.pods = pods
self.pod_type = pod_type
self.replicas = replicas
self.shards = shards
self.namespace = namespace
Expand Down Expand Up @@ -182,6 +188,8 @@ def __init__(
else:
self.pinecone_indexes[self.index] = self._create_index(
embedding_dim=self.embedding_dim,
pods=self.pods,
pod_type=self.pod_type,
index=self.index,
metric_type=self.metric_type,
replicas=self.replicas,
Expand All @@ -199,6 +207,8 @@ def _index(self, index) -> str:
def _create_index(
self,
embedding_dim: int,
pods: int = 1,
pod_type: str = "p1.x1",
index: Optional[str] = None,
metric_type: Optional[str] = "cosine",
replicas: Optional[int] = 1,
Expand All @@ -225,6 +235,8 @@ def _create_index(
pinecone.create_index(
name=index,
dimension=embedding_dim,
pods=pods,
pod_type=pod_type,
metric=metric_type,
replicas=replicas,
shards=shards,
Expand Down Expand Up @@ -254,6 +266,8 @@ def _index_connection_exists(self, index: str, create: bool = False) -> Optional
if create:
return self._create_index(
embedding_dim=self.embedding_dim,
pods=self.pods,
pod_type=self.pod_type,
index=index,
metric_type=self.metric_type,
replicas=self.replicas,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
enhancements:
- |
Users can now define the number of pods and pod type directly when creating a PineconeDocumentStore instance.
5 changes: 5 additions & 0 deletions test/document_stores/test_pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ def ds(self, monkeypatch, request) -> PineconeDocumentStore:
monkeypatch.setattr(f"pinecone.{fname}", function, raising=False)
for cname, class_ in getmembers(pinecone_mock, isclass):
monkeypatch.setattr(f"pinecone.{cname}", class_, raising=False)
params = getattr(request, "param", {})
pods = params.get("pods", None)
pod_type = params.get("pod_type", None)

return PineconeDocumentStore(
api_key=os.environ.get("PINECONE_API_KEY") or "fake-pinecone-test-key",
embedding_dim=768,
embedding_field="embedding",
pods=pods,
pod_type=pod_type,
index="haystack_tests",
similarity="cosine",
recreate_index=True,
Expand Down
8 changes: 8 additions & 0 deletions test/mocks/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(
api_key: Optional[str] = None,
environment: Optional[str] = None,
dimension: Optional[int] = None,
pods: Optional[int] = None,
pod_type: Optional[str] = None,
metric: Optional[str] = None,
replicas: Optional[int] = None,
shards: Optional[int] = None,
Expand All @@ -55,6 +57,8 @@ def __init__(
self.environment = environment
self.dimension = dimension
self.metric = metric
self.pods = pods
self.pod_type = pod_type
self.replicas = replicas
self.shards = shards
self.metadata_config = metadata_config
Expand Down Expand Up @@ -338,6 +342,8 @@ def create_index(
dimension: int,
metric: str = "cosine",
replicas: int = 1,
pods: int = 1,
pod_type: str = "p1.x1",
shards: int = 1,
metadata_config: Optional[dict] = None,
):
Expand All @@ -348,6 +354,8 @@ def create_index(
dimension=dimension,
metric=metric,
replicas=replicas,
pods=pods,
pod_type=pod_type,
shards=shards,
metadata_config=metadata_config,
)
Expand Down