Skip to content

Base

BaseDocumentStore

Bases: ABC

A document store is in charged of storing and managing documents

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
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,
        **kwargs,
    ):
        """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
        """
        ...

    @abstractmethod
    def get(self, ids: Union[List[str], str]) -> List[Document]:
        """Get document by id"""
        ...

    @abstractmethod
    def get_all(self) -> List[Document]:
        """Get all documents"""
        ...

    @abstractmethod
    def count(self) -> int:
        """Count number of documents"""
        ...

    @abstractmethod
    def query(
        self, query: str, top_k: int = 10, doc_ids: Optional[list] = None
    ) -> List[Document]:
        """Search document store using search query"""
        ...

    @abstractmethod
    def delete(self, ids: Union[List[str], str]):
        """Delete document by id"""
        ...

    @abstractmethod
    def drop(self):
        """Drop the document store"""
        ...

add abstractmethod

add(docs, ids=None, **kwargs)

Add document into document store

Parameters:

Name Type Description Default
docs Union[Document, List[Document]]

Document or list of documents

required
ids Optional[Union[List[str], str]]

List of ids of the documents. Optional, if not set will use doc.doc_id

None
Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def add(
    self,
    docs: Union[Document, List[Document]],
    ids: Optional[Union[List[str], str]] = None,
    **kwargs,
):
    """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
    """
    ...

get abstractmethod

get(ids)

Get document by id

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def get(self, ids: Union[List[str], str]) -> List[Document]:
    """Get document by id"""
    ...

get_all abstractmethod

get_all()

Get all documents

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def get_all(self) -> List[Document]:
    """Get all documents"""
    ...

count abstractmethod

count()

Count number of documents

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def count(self) -> int:
    """Count number of documents"""
    ...

query abstractmethod

query(query, top_k=10, doc_ids=None)

Search document store using search query

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def query(
    self, query: str, top_k: int = 10, doc_ids: Optional[list] = None
) -> List[Document]:
    """Search document store using search query"""
    ...

delete abstractmethod

delete(ids)

Delete document by id

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def delete(self, ids: Union[List[str], str]):
    """Delete document by id"""
    ...

drop abstractmethod

drop()

Drop the document store

Source code in libs/kotaemon/kotaemon/storages/docstores/base.py
@abstractmethod
def drop(self):
    """Drop the document store"""
    ...