app/embeddings.py aktualisiert
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 2s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 2s
This commit is contained in:
parent
bee0544c25
commit
7192ead996
|
|
@ -1,11 +1,9 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import List
|
from typing import List
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
from .config import get_settings
|
from .config import get_settings
|
||||||
|
|
||||||
# Lazy import so startup stays fast
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def _load_model():
|
def _load_model():
|
||||||
from sentence_transformers import SentenceTransformer
|
from sentence_transformers import SentenceTransformer
|
||||||
|
|
@ -15,8 +13,6 @@ def _load_model():
|
||||||
|
|
||||||
def embed_texts(texts: List[str]) -> list[list[float]]:
|
def embed_texts(texts: List[str]) -> list[list[float]]:
|
||||||
model = _load_model()
|
model = _load_model()
|
||||||
# Normalize to list of str
|
|
||||||
texts = [t if isinstance(t, str) else str(t) for t in texts]
|
texts = [t if isinstance(t, str) else str(t) for t in texts]
|
||||||
vecs = model.encode(texts, normalize_embeddings=True, convert_to_numpy=False)
|
vecs = model.encode(texts, normalize_embeddings=True, convert_to_numpy=False)
|
||||||
# Ensure pure-python list of floats
|
|
||||||
return [list(map(float, v)) for v in vecs]
|
return [list(map(float, v)) for v in vecs]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user