File size: 519 Bytes
b93b2dc
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from sentence_transformers import SentenceTransformer


class Embeddings:
    def __init__(self, model_name: str = 'BAAI/bge-small-en-v1.5'):
        self.model = SentenceTransformer(model_name, trust_remote_code=True, revision="main")

    def get_query_embedding(self, query):
        query_embed = self.model.encode([query], normalize_embeddings=True)
        return query_embed

    def get_embeddings(self, texts):
        embeddings = self.model.encode(texts, normalize_embeddings=True)
        return embeddings