The image context was backend/, so COPY frontend/ failed. Build from the repo root, place Python modules on the import path, and pin packages that exist on PyPI. The web process no longer loads the LLM at startup.
20 lines
689 B
Python
20 lines
689 B
Python
from sentence_transformers import SentenceTransformer
|
|
import numpy as np
|
|
|
|
class EmbeddingService:
|
|
def __init__(self, model_name="all-MiniLM-L6-v2"):
|
|
self.model = SentenceTransformer(model_name)
|
|
self.dimension = 384
|
|
|
|
def embed(self, texts: list[str]) -> np.ndarray:
|
|
"""Generate embeddings for a list of texts."""
|
|
return self.model.encode(texts, convert_to_numpy=True)
|
|
|
|
def embed_query(self, text: str) -> np.ndarray:
|
|
"""Generate embedding for a single query."""
|
|
return self.model.encode([text], convert_to_numpy=True)[0]
|
|
|
|
def get_dimension(self) -> int:
|
|
"""Return embedding dimension."""
|
|
return self.dimension
|