zilliz.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 ZillizDBConfig(BaseVectorDbConfig):
  7. def __init__(
  8. self,
  9. collection_name: Optional[str] = None,
  10. dir: Optional[str] = None,
  11. uri: Optional[str] = None,
  12. token: Optional[str] = None,
  13. vector_dim: Optional[str] = None,
  14. metric_type: Optional[str] = None,
  15. ):
  16. """
  17. Initializes a configuration class instance for the vector database.
  18. :param collection_name: Default name for the collection, defaults to None
  19. :type collection_name: Optional[str], optional
  20. :param dir: Path to the database directory, where the database is stored, defaults to "db"
  21. :type dir: str, optional
  22. :param uri: Cluster endpoint obtained from the Zilliz Console, defaults to None
  23. :type uri: Optional[str], optional
  24. :param token: API Key, if a Serverless Cluster, username:password, if a Dedicated Cluster, defaults to None
  25. :type token: Optional[str], optional
  26. """
  27. self.uri = uri or os.environ.get("ZILLIZ_CLOUD_URI")
  28. if not self.uri:
  29. raise AttributeError(
  30. "Zilliz needs a URI attribute, "
  31. "this can either be passed to `ZILLIZ_CLOUD_URI` or as `ZILLIZ_CLOUD_URI` in `.env`"
  32. )
  33. self.token = token or os.environ.get("ZILLIZ_CLOUD_TOKEN")
  34. if not self.token:
  35. raise AttributeError(
  36. "Zilliz needs a token attribute, "
  37. "this can either be passed to `ZILLIZ_CLOUD_TOKEN` or as `ZILLIZ_CLOUD_TOKEN` in `.env`,"
  38. "if having a username and password, pass it in the form 'username:password' to `ZILLIZ_CLOUD_TOKEN`"
  39. )
  40. self.metric_type = metric_type if metric_type else "L2"
  41. self.vector_dim = vector_dim
  42. super().__init__(collection_name=collection_name, dir=dir)