empty_docstore.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from typing import Any, Dict, Optional, Sequence
  2. from llama_index.docstore.types import BaseDocumentStore
  3. from llama_index.schema import BaseDocument
  4. class EmptyDocumentStore(BaseDocumentStore):
  5. @classmethod
  6. def from_dict(cls, config_dict: Dict[str, Any]) -> "EmptyDocumentStore":
  7. return cls()
  8. def to_dict(self) -> Dict[str, Any]:
  9. """Serialize to dict."""
  10. return {}
  11. @property
  12. def docs(self) -> Dict[str, BaseDocument]:
  13. return {}
  14. def add_documents(
  15. self, docs: Sequence[BaseDocument], allow_update: bool = True
  16. ) -> None:
  17. pass
  18. def document_exists(self, doc_id: str) -> bool:
  19. """Check if document exists."""
  20. return False
  21. def get_document(
  22. self, doc_id: str, raise_error: bool = True
  23. ) -> Optional[BaseDocument]:
  24. return None
  25. def delete_document(self, doc_id: str, raise_error: bool = True) -> None:
  26. pass
  27. def set_document_hash(self, doc_id: str, doc_hash: str) -> None:
  28. """Set the hash for a given doc_id."""
  29. pass
  30. def get_document_hash(self, doc_id: str) -> Optional[str]:
  31. """Get the stored hash for a document, if it exists."""
  32. return None
  33. def update_docstore(self, other: "BaseDocumentStore") -> None:
  34. """Update docstore.
  35. Args:
  36. other (BaseDocumentStore): docstore to update from
  37. """
  38. self.add_documents(list(other.docs.values()))