opensearch.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from typing import Optional
  2. from embedchain.config.vectordb.base import BaseVectorDbConfig
  3. from embedchain.helpers.json_serializable import register_deserializable
  4. @register_deserializable
  5. class OpenSearchDBConfig(BaseVectorDbConfig):
  6. def __init__(
  7. self,
  8. opensearch_url: str,
  9. http_auth: tuple[str, str],
  10. vector_dimension: int = 1536,
  11. collection_name: Optional[str] = None,
  12. dir: Optional[str] = None,
  13. batch_size: Optional[int] = 100,
  14. **extra_params: dict[str, any],
  15. ):
  16. """
  17. Initializes a configuration class instance for an OpenSearch client.
  18. :param collection_name: Default name for the collection, defaults to None
  19. :type collection_name: Optional[str], optional
  20. :param opensearch_url: URL of the OpenSearch domain
  21. :type opensearch_url: str, Eg, "http://localhost:9200"
  22. :param http_auth: Tuple of username and password
  23. :type http_auth: tuple[str, str], Eg, ("username", "password")
  24. :param vector_dimension: Dimension of the vector, defaults to 1536 (openai embedding model)
  25. :type vector_dimension: int, optional
  26. :param dir: Path to the database directory, where the database is stored, defaults to None
  27. :type dir: Optional[str], optional
  28. :param batch_size: Number of items to insert in one batch, defaults to 100
  29. :type batch_size: Optional[int], optional
  30. """
  31. self.opensearch_url = opensearch_url
  32. self.http_auth = http_auth
  33. self.vector_dimension = vector_dimension
  34. self.extra_params = extra_params
  35. self.batch_size = batch_size
  36. super().__init__(collection_name=collection_name, dir=dir)