base.py 973 B

12345678910111213141516171819202122232425262728293031323334
  1. from abc import ABC, abstractmethod
  2. from typing import Optional
  3. from llama_index import ServiceContext, GPTVectorStoreIndex
  4. from llama_index.data_structs import Node
  5. from llama_index.vector_stores.types import VectorStore
  6. class BaseVectorStoreClient(ABC):
  7. @abstractmethod
  8. def get_index(self, service_context: ServiceContext, config: dict) -> GPTVectorStoreIndex:
  9. raise NotImplementedError
  10. @abstractmethod
  11. def to_index_config(self, index_id: str) -> dict:
  12. raise NotImplementedError
  13. class BaseGPTVectorStoreIndex(GPTVectorStoreIndex):
  14. def delete_node(self, node_id: str):
  15. self._vector_store.delete_node(node_id)
  16. def exists_by_node_id(self, node_id: str) -> bool:
  17. return self._vector_store.exists_by_node_id(node_id)
  18. class EnhanceVectorStore(ABC):
  19. @abstractmethod
  20. def delete_node(self, node_id: str):
  21. pass
  22. @abstractmethod
  23. def exists_by_node_id(self, node_id: str) -> bool:
  24. pass