from langchain_huggingface import HuggingFaceEmbeddings # embedding_instance = HuggingFaceEmbeddings( # model_name="all-MiniLM-L6-v2", # model_kwargs={"device": "cpu"}, # ) # def all_minilm_l6_v2(): # """ # Return the embedding instance. # """ # return embedding_instance # from sentence_transformers import SentenceTransformer # from langchain.embeddings import HuggingFaceEmbeddings # # Load the sentence-transformers model directly # model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2") # # Wrap it in LangChain HuggingFaceEmbeddings by passing the model instance # embedding_instance = HuggingFaceEmbeddings(model=model) # def all_minilm_l6_v2(): # """ # Return the embedding instance. # """ # return embedding_instance from langchain_huggingface import HuggingFaceEmbeddings def all_minilm_l6_v2(): model_kwargs = {"device":"cpu"} encode_kwargs = {"normalize_embeddings": True} all_minilm_object = HuggingFaceEmbeddings( model_name="sentence-transformers/all-MiniLM-L6-v2", model_kwargs=model_kwargs, encode_kwargs=encode_kwargs ) return all_minilm_object