-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathembeddings.py
More file actions
51 lines (27 loc) · 1.31 KB
/
embeddings.py
File metadata and controls
51 lines (27 loc) · 1.31 KB
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
48
49
50
51
# Model Dimensions Cost per 1M tokens Best For
# text-embedding-3-small 1536 $0.02 General use
# text-embedding-3-large 3072 $0.13 High accuracy
# text-embedding-ada-002 1536 $0.10 Legacy
from langchain_openai.embeddings import OpenAIEmbeddings
from langchain_community.embeddings import HuggingFaceEmbeddings
from dotenv import load_dotenv
load_dotenv()
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2") # 384 dimensions
# Ollama
from langchain_ollama import OllamaEmbeddings
embeddings = OllamaEmbeddings(model="llama2-7b-embedding-q4_0")
# embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
# # single text
# text = "This is a sample text to be embedded."
# embedding = embeddings.embed_query(text)
# # print(f"Embedding for single text: {embedding}")
# print(len(embedding)) # Should print 1536 for text-embedding-3-small
# # multiple texts
# embeds = embeddings.embed_documents(
# ["This is the first document.", "This is the second document."]
# )
# print(f"Embeddings for multiple texts: {embeds}")
# print(f"Number of embeddings returned: {len(embeds)}") # Should print 2
# print(
# f"Length of each embedding: {len(embeds[0])}"
# ) # Should print 1536 for text-embedding-3-small