base_vector_db.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from embedchain.config.vectordbs.BaseVectorDbConfig import BaseVectorDbConfig
  2. from embedchain.embedder.base_embedder import BaseEmbedder
  3. from embedchain.helper_classes.json_serializable import JSONSerializable
  4. class BaseVectorDB(JSONSerializable):
  5. """Base class for vector database."""
  6. def __init__(self, config: BaseVectorDbConfig):
  7. self.client = self._get_or_create_db()
  8. self.config: BaseVectorDbConfig = config
  9. def _initialize(self):
  10. """
  11. This method is needed because `embedder` attribute needs to be set externally before it can be initialized.
  12. So it's can't be done in __init__ in one step.
  13. """
  14. raise NotImplementedError
  15. def _get_or_create_db(self):
  16. """Get or create the database."""
  17. raise NotImplementedError
  18. def _get_or_create_collection(self):
  19. raise NotImplementedError
  20. def _set_embedder(self, embedder: BaseEmbedder):
  21. self.embedder = embedder
  22. def get(self):
  23. raise NotImplementedError
  24. def add(self):
  25. raise NotImplementedError
  26. def query(self):
  27. raise NotImplementedError
  28. def count(self):
  29. raise NotImplementedError
  30. def delete(self):
  31. raise NotImplementedError
  32. def reset(self):
  33. raise NotImplementedError
  34. def set_collection_name(self, name: str):
  35. raise NotImplementedError