kotaemon/knowledgehub/docstores/base.py
Nguyen Trung Duc (john) 2a3a23ecd7 [AUR-420] Provide document store base interface and an in-memory version (#21)
Document store handles storing and indexing Documents. It supports the following interfaces:

- add: add 1 or more documents into document store
- get: get a list of documents
- get_all: get all documents in a document store
- delete: delete 1 or more document
- save: persist a document store into disk
- load: load a document store from disk
2023-09-19 14:49:23 +07:00

55 lines
1.4 KiB
Python

from abc import ABC, abstractmethod
from pathlib import Path
from typing import List, Optional, Union
from ..documents.base import Document
class BaseDocumentStore(ABC):
"""A document store is in charged of storing and managing documents"""
@abstractmethod
def __init__(self, *args, **kwargs):
...
@abstractmethod
def add(
self,
docs: Union[Document, List[Document]],
ids: Optional[Union[List[str], str]] = None,
exist_ok: bool = False,
):
"""Add document into document store
Args:
docs: Document or list of documents
ids: List of ids of the documents. Optional, if not set will use doc.doc_id
exist_ok: If True, will not raise error if document already exist
"""
...
@abstractmethod
def get(self, ids: Union[List[str], str]) -> List[Document]:
"""Get document by id"""
...
@abstractmethod
def get_all(self) -> dict:
"""Get all documents"""
...
@abstractmethod
def delete(self, ids: Union[List[str], str]):
"""Delete document by id"""
...
@abstractmethod
def save(self, path: Union[str, Path]):
"""Save document to path"""
...
@abstractmethod
def load(self, path: Union[str, Path]):
"""Load document store from path"""
...