chatbot2 / embeddings.py
Nguyen5's picture
commit
ed084d7
raw
history blame contribute delete
602 Bytes
"""
BƯỚC 3: EMBEDDINGS – local & free
"""
from langchain_huggingface import HuggingFaceEmbeddings
EMBEDDING_MODEL = "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
def get_embeddings():
print(f">>> Loading embedding model: {EMBEDDING_MODEL}")
embeddings = HuggingFaceEmbeddings(
model_name=EMBEDDING_MODEL,
model_kwargs={"device": "cpu"},
encode_kwargs={"normalize_embeddings": True},
)
print(">>> Embedding model loaded.\n")
return embeddings
if __name__ == "__main__":
emb = get_embeddings()
print(emb.embed_query("Test"))