akshansh36 commited on
Commit
a2d8b69
·
verified ·
1 Parent(s): 0911c21

Delete create_embeddings2.py

Browse files
Files changed (1) hide show
  1. create_embeddings2.py +0 -58
create_embeddings2.py DELETED
@@ -1,58 +0,0 @@
1
- import pinecone
2
- from langchain_google_genai import GoogleGenerativeAIEmbeddings
3
- from variables import variables # Import the list of variable names
4
- import uuid
5
-
6
- # Initialize Google Embeddings
7
- google_embeddings = GoogleGenerativeAIEmbeddings(
8
- model="models/embedding-001", # Correct model name
9
- google_api_key="AIzaSyANNRKfEb-YnVIBaSAq6hQ38XpxxGwvaws" # Your API key
10
- )
11
-
12
- # Initialize Pinecone instance
13
- pc = pinecone.Pinecone(
14
- api_key="4a80f293-ae6d-489a-a7d8-33ea3fcdd26b" # Your Pinecone API key
15
- )
16
-
17
- # Define the Pinecone index name (make sure it exists in your Pinecone dashboard)
18
- index_name = "iocl2"
19
- index = pc.Index(index_name)
20
-
21
-
22
- def create_embedding(variable):
23
- try:
24
- content = variable.get("description", None)
25
- url = variable.get("url", "")
26
- tag = variable.get("tag", "")
27
- updated_url = ""
28
-
29
- if isinstance(url, list):
30
- updated_url = ",".join(url)
31
- else:
32
- updated_url = url
33
-
34
- embedding = google_embeddings.embed_query(content)
35
- vectors = []
36
- vectors.append({
37
- 'id': str(uuid.uuid4()),
38
- 'values': embedding,
39
- 'metadata': {
40
- 'chunk': content,
41
- "url": updated_url,
42
- "tag": tag
43
- }
44
- })
45
- index.upsert(vectors)
46
- print(f"Inserted the chunk: {updated_url}")
47
- except Exception as e:
48
- print(f"Error occurred: {e}")
49
-
50
-
51
- # Iterate over the variable names and create embeddings
52
- for variable_name in variables:
53
- # Dynamically import the variable from paragraphs2
54
- variable = __import__('paragraphs2', fromlist=[variable_name])
55
- variable_data = getattr(variable, variable_name)
56
- print(f"trying to create embedding for {variable}")
57
- # Call the create_embedding function with the variable data
58
- create_embedding(variable_data)