forked from innovacion/searchbox
Add engine abstraction
This commit is contained in:
43
src/vector_search_mcp/engine/base_engine.py
Normal file
43
src/vector_search_mcp/engine/base_engine.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from ..models import Condition, SearchRow
|
||||
|
||||
ResponseType = TypeVar("ResponseType")
|
||||
ConditionType = TypeVar("ConditionType")
|
||||
|
||||
__all__ = ["BaseEngine"]
|
||||
|
||||
|
||||
class BaseEngine(ABC, Generic[ResponseType, ConditionType]):
|
||||
@abstractmethod
|
||||
def transform_conditions(
|
||||
self, conditions: list[Condition] | None
|
||||
) -> ConditionType | None: ...
|
||||
|
||||
@abstractmethod
|
||||
def transform_response(self, response: ResponseType) -> list[SearchRow]: ...
|
||||
|
||||
@abstractmethod
|
||||
async def run_similarity_query(
|
||||
self,
|
||||
embedding: list[float],
|
||||
collection: str,
|
||||
limit: int = 10,
|
||||
conditions: ConditionType | None = None,
|
||||
threshold: float | None = None,
|
||||
) -> ResponseType: ...
|
||||
|
||||
async def semantic_search(
|
||||
self,
|
||||
vector: list[float],
|
||||
collection: str,
|
||||
limit: int = 10,
|
||||
conditions: list[Condition] | None = None,
|
||||
threshold: float | None = None,
|
||||
) -> list[SearchRow]:
|
||||
transformed_conditions = self.transform_conditions(conditions)
|
||||
response = await self.run_similarity_query(
|
||||
vector, collection, limit, transformed_conditions, threshold
|
||||
)
|
||||
return self.transform_response(response)
|
||||
Reference in New Issue
Block a user