:zap: [Enhance] Use JinaAIOnnxEmbedder for better performance
Browse files- apps/app.py +4 -4
apps/app.py
CHANGED
@@ -11,7 +11,7 @@ from pydantic import BaseModel, Field
|
|
11 |
from fastapi.responses import HTMLResponse
|
12 |
from tclogger import logger, OSEnver
|
13 |
|
14 |
-
from transforms.embed import JinaAIEmbedder
|
15 |
from configs.constants import AVAILABLE_MODELS
|
16 |
|
17 |
info_path = Path(__file__).parents[1] / "configs" / "info.json"
|
@@ -26,7 +26,7 @@ class EmbeddingApp:
|
|
26 |
swagger_ui_parameters={"defaultModelsExpandDepth": -1},
|
27 |
version=ENVER["version"],
|
28 |
)
|
29 |
-
self.embedder =
|
30 |
self.setup_routes()
|
31 |
|
32 |
def get_available_models(self):
|
@@ -53,8 +53,8 @@ class EmbeddingApp:
|
|
53 |
|
54 |
def calc_embedding(self, item: CalcEmbeddingPostItem):
|
55 |
logger.note(f"> Encoding text: [{item.text}]", end=" ")
|
56 |
-
if item.model != self.embedder.model:
|
57 |
-
|
58 |
embeddings = self.embedder.encode(item.text).tolist()
|
59 |
logger.success(f"[{len(embeddings[0])}]")
|
60 |
if len(embeddings) == 1:
|
|
|
11 |
from fastapi.responses import HTMLResponse
|
12 |
from tclogger import logger, OSEnver
|
13 |
|
14 |
+
from transforms.embed import JinaAIEmbedder, JinaAIOnnxEmbedder
|
15 |
from configs.constants import AVAILABLE_MODELS
|
16 |
|
17 |
info_path = Path(__file__).parents[1] / "configs" / "info.json"
|
|
|
26 |
swagger_ui_parameters={"defaultModelsExpandDepth": -1},
|
27 |
version=ENVER["version"],
|
28 |
)
|
29 |
+
self.embedder = JinaAIOnnxEmbedder()
|
30 |
self.setup_routes()
|
31 |
|
32 |
def get_available_models(self):
|
|
|
53 |
|
54 |
def calc_embedding(self, item: CalcEmbeddingPostItem):
|
55 |
logger.note(f"> Encoding text: [{item.text}]", end=" ")
|
56 |
+
# if item.model != self.embedder.model:
|
57 |
+
# self.embedder.switch_model(item.model)
|
58 |
embeddings = self.embedder.encode(item.text).tolist()
|
59 |
logger.success(f"[{len(embeddings[0])}]")
|
60 |
if len(embeddings) == 1:
|