Spaces:
Runtime error
Runtime error
File size: 714 Bytes
36425a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from sentence_transformers import SentenceTransformer
from typing import List
class EmbeddingService:
def __init__(self):
# Load the sentence-transformers model (all-MiniLM-L6-v2)
self.model = SentenceTransformer('all-MiniLM-L6-v2')
def encode(self, texts: List[str]) -> List[List[float]]:
"""
Encodes a list of texts into embeddings.
Args:
texts: A list of strings to encode.
Returns:
A list of embedding vectors.
"""
if isinstance(texts, str):
texts = [texts] # Ensure texts is a list for batch processing
embeddings = self.model.encode(texts).tolist()
return embeddings
|