File size: 1,178 Bytes
2719d58
cbeea95
425e09d
cbeea95
425e09d
cbeea95
 
 
 
 
425e09d
cbeea95
 
425e09d
 
e5edc91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8585c16
425e09d
 
 
e5edc91
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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