File size: 497 Bytes
ef26a79
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
# Methods to encode text
import numpy as np
from langchain_community.embeddings import HuggingFaceEmbeddings

def encode_text(text, embedding_model='sentence-transformers/all-MiniLM-L6-v2', as_array=True):
    """Encodes the input text using the provided embedding model."""
    embedding_model = HuggingFaceEmbeddings(model_name=embedding_model)
    encoded_input =  embedding_model.embed_query(text)
    if as_array:
        return np.array(encoded_input)
    else:
        return encoded_input