-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from .base import Engine | ||
from .local import LocalEngine | ||
|
||
try: | ||
from .qdrant import QdrantEngine | ||
except ModuleNotFoundError: | ||
pass | ||
|
||
__all__ = ["LocalEngine", "QdrantEngine"] | ||
__all__ = ["Engine", "LocalEngine", "QdrantEngine"] |
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,31 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from affine.collection import Collection, FilterSet | ||
|
||
|
||
class Engine(ABC): | ||
@abstractmethod | ||
def query(self, filter_set: FilterSet) -> list[Collection]: | ||
pass | ||
|
||
@abstractmethod | ||
def insert(self, record: Collection) -> int: | ||
pass | ||
|
||
@abstractmethod | ||
def delete(self, collection: type, id_: int) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def get_elements_by_ids( | ||
self, collection: type, ids: list[int] | ||
) -> list[Collection]: | ||
pass | ||
|
||
def get_element_by_id(self, collection: type, id_: int) -> Collection: | ||
ret = self.get_elements_by_ids(collection, [id_]) | ||
if len(ret) == 0: | ||
raise ValueError(f"No record found with id {id_}") | ||
if len(ret) > 1: | ||
raise ValueError(f"Multiple records found with id {id_}") | ||
return ret[0] |
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