You've already forked RekomenciBackend
feat(): embedder implementation
This commit is contained in:
+22
-6
@@ -5,11 +5,18 @@ description = "template project"
|
|||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"uuid_utils==0.11.1",
|
"uuid_utils==0.11.1",
|
||||||
"adaptix==3.0.0b11",
|
|
||||||
"fastapi==0.119.0",
|
"fastapi==0.119.0",
|
||||||
"uvicorn==0.37.0",
|
"uvicorn==0.37.0",
|
||||||
"sqlalchemy==2.0.44",
|
|
||||||
"dishka==1.7.2",
|
"dishka==1.7.2",
|
||||||
|
"pydantic[email]>=2.12.4",
|
||||||
|
"levenshtein>=0.27.3",
|
||||||
|
"markupsafe",
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
backend = [
|
||||||
|
"adaptix==3.0.0b11",
|
||||||
|
"sqlalchemy==2.0.44",
|
||||||
"argon2_cffi==23.1.0",
|
"argon2_cffi==23.1.0",
|
||||||
"cryptography==46.0.3",
|
"cryptography==46.0.3",
|
||||||
"httpx==0.28.1",
|
"httpx==0.28.1",
|
||||||
@@ -18,12 +25,12 @@ dependencies = [
|
|||||||
"aioboto3==15.5.0",
|
"aioboto3==15.5.0",
|
||||||
"prometheus-fastapi-instrumentator>=7.1.0",
|
"prometheus-fastapi-instrumentator>=7.1.0",
|
||||||
"python-multipart>=0.0.20",
|
"python-multipart>=0.0.20",
|
||||||
"pydantic[email]>=2.12.4",
|
|
||||||
"levenshtein>=0.27.3",
|
|
||||||
"pgvector>=0.4.1",
|
"pgvector>=0.4.1",
|
||||||
]
|
]
|
||||||
|
ml = [
|
||||||
[dependency-groups]
|
"sentence-transformers>=5.1.2",
|
||||||
|
"torch",
|
||||||
|
]
|
||||||
types = [
|
types = [
|
||||||
"types-cachetools==6.2.0.20250827",
|
"types-cachetools==6.2.0.20250827",
|
||||||
]
|
]
|
||||||
@@ -62,6 +69,15 @@ filterwarnings = [
|
|||||||
asyncio_default_test_loop_scope = "session"
|
asyncio_default_test_loop_scope = "session"
|
||||||
asyncio_default_fixture_loop_scope = "session"
|
asyncio_default_fixture_loop_scope = "session"
|
||||||
|
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pytorch"
|
||||||
|
url = "https://download.pytorch.org/whl/cpu"
|
||||||
|
default = false
|
||||||
|
|
||||||
|
[tool.uv.sources]
|
||||||
|
torch = { index = "pytorch" }
|
||||||
|
markupsafe = { git = "https://github.com/pallets/markupsafe", rev = "3.0.2" }
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
strict = true
|
strict = true
|
||||||
strict_bytes = true
|
strict_bytes = true
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
from typing import cast, override
|
||||||
|
|
||||||
|
from sentence_transformers import SentenceTransformer
|
||||||
|
|
||||||
|
from template_project.application.common.embedding import Embedder
|
||||||
|
|
||||||
|
|
||||||
|
class MiniLMEmbedder(Embedder):
|
||||||
|
def __init__(self, model: SentenceTransformer) -> None:
|
||||||
|
self._model = model
|
||||||
|
|
||||||
|
@override
|
||||||
|
async def encode(self, text: str) -> list[float]:
|
||||||
|
embedding = self._model.encode(text)
|
||||||
|
return cast(list[float], embedding.tolist())
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from abc import abstractmethod
|
||||||
|
from typing import Protocol
|
||||||
|
|
||||||
|
|
||||||
|
class Embedder(Protocol):
|
||||||
|
@abstractmethod
|
||||||
|
async def encode(self, text: str) -> list[float]:
|
||||||
|
raise NotImplementedError
|
||||||
Reference in New Issue
Block a user