pinecone.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. from typing import Optional
  3. from embedchain.config.vectordb.base import BaseVectorDbConfig
  4. from embedchain.helpers.json_serializable import register_deserializable
  5. @register_deserializable
  6. class PineconeDBConfig(BaseVectorDbConfig):
  7. def __init__(
  8. self,
  9. index_name: Optional[str] = None,
  10. api_key: Optional[str] = None,
  11. vector_dimension: int = 1536,
  12. metric: Optional[str] = "cosine",
  13. pod_config: Optional[dict[str, any]] = None,
  14. serverless_config: Optional[dict[str, any]] = None,
  15. hybrid_search: bool = False,
  16. bm25_encoder: any = None,
  17. **extra_params: dict[str, any],
  18. ):
  19. self.metric = metric
  20. self.api_key = api_key
  21. self.index_name = index_name
  22. self.vector_dimension = vector_dimension
  23. self.extra_params = extra_params
  24. self.hybrid_search = hybrid_search
  25. self.bm25_encoder = bm25_encoder
  26. if pod_config is None and serverless_config is None:
  27. # If no config is provided, use the default pod spec config
  28. pod_environment = os.environ.get("PINECONE_ENV", "gcp-starter")
  29. self.pod_config = {"environment": pod_environment, "metadata_config": {"indexed": ["*"]}}
  30. else:
  31. self.pod_config = pod_config
  32. self.serverless_config = serverless_config
  33. if self.pod_config and self.serverless_config:
  34. raise ValueError("Only one of pod_config or serverless_config can be provided.")
  35. if self.hybrid_search and self.metric != "dotproduct":
  36. raise ValueError(
  37. "Hybrid search is only supported with dotproduct metric in Pinecone. See full docs here: https://docs.pinecone.io/docs/hybrid-search#limitations"
  38. ) # noqa:E501
  39. super().__init__(collection_name=self.index_name, dir=None)