-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from arjbingly/vectordb
Vectordb, Add support for deeplake
- Loading branch information
Showing
15 changed files
with
693 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""Abstract base class for vector database clients. | ||
This module provides: | ||
- VectorDB | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import List, Tuple, Union | ||
|
||
from langchain_community.vectorstores.utils import filter_complex_metadata | ||
from langchain_core.documents import Document | ||
|
||
|
||
class VectorDB(ABC): | ||
"""Abstract base class for vector database clients.""" | ||
|
||
@abstractmethod | ||
def __len__(self) -> int: | ||
"""Number of chunks in the vector database.""" | ||
... | ||
|
||
@abstractmethod | ||
def delete(self) -> None: | ||
"""Delete all chunks in the vector database.""" | ||
|
||
@abstractmethod | ||
def add_docs(self, docs: List[Document], verbose: bool = True) -> None: | ||
"""Adds documents to the vector database. | ||
Args: | ||
docs: List of Documents | ||
verbose: Show progress bar | ||
Returns: | ||
None | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
async def aadd_docs(self, docs: List[Document], verbose: bool = True) -> None: | ||
"""Adds documents to the vector database (asynchronous). | ||
Args: | ||
docs: List of Documents | ||
verbose: Show progress bar | ||
Returns: | ||
None | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def get_chunk( | ||
self, query: str, with_score: bool = False, top_k: int = None | ||
) -> Union[List[Document], List[Tuple[Document, float]]]: | ||
"""Returns the most similar chunks from the vector database. | ||
Args: | ||
query: A query string | ||
with_score: Outputs scores of returned chunks | ||
top_k: Number of top similar chunks to return, if None defaults to self.top_k | ||
Returns: | ||
list of Documents | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
async def aget_chunk( | ||
self, query: str, with_score: bool = False, top_k: int = None | ||
) -> Union[List[Document], List[Tuple[Document, float]]]: | ||
"""Returns the most similar chunks from the vector database (asynchronous). | ||
Args: | ||
query: A query string | ||
with_score: Outputs scores of returned chunks | ||
top_k: Number of top similar chunks to return, if None defaults to self.top_k | ||
Returns: | ||
list of Documents | ||
""" | ||
... | ||
|
||
def _filter_metadata(self, docs: List[Document]) -> List[Document]: | ||
return filter_complex_metadata(docs, allowed_types=self.allowed_metadata_types) |
Oops, something went wrong.