-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembeddings.py
More file actions
33 lines (25 loc) · 778 Bytes
/
Copy pathembeddings.py
File metadata and controls
33 lines (25 loc) · 778 Bytes
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
from google import genai
from dotenv import load_dotenv
import os
load_dotenv()
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
def get_embeddings(chunked_docs):
embedded_docs = []
for doc in chunked_docs:
response = client.models.embed_content(
model="gemini-embedding-001",
contents=doc["content"]
)
embedding = response.embeddings[0].values
embedded_docs.append({
"embedding": embedding,
"content": doc["content"],
"metadata": doc["metadata"]
})
return embedded_docs
def embed_query(query):
response = client.models.embed_content(
model="gemini-embedding-001",
contents=query
)
return response.embeddings[0].values