Spaces:
Running
Running
import pinecone | |
from langchain_google_genai import GoogleGenerativeAIEmbeddings | |
from paragraphs2 import podcasts | |
import uuid | |
google_embeddings = GoogleGenerativeAIEmbeddings( | |
model="models/embedding-001", # Correct model name | |
google_api_key="AIzaSyANNRKfEb-YnVIBaSAq6hQ38XpxxGwvaws" # Your API key | |
) | |
# Initialize Pinecone instance | |
pc = pinecone.Pinecone( | |
api_key="4a80f293-ae6d-489a-a7d8-33ea3fcdd26b" # Your Pinecone API key | |
) | |
# Define the Pinecone index name (make sure it exists in your Pinecone dashboard) | |
index_name = "iocl2" | |
index = pc.Index(index_name) | |
def create_embedding(variable): | |
try: | |
content=variable.get("description") | |
url=variable.get("url") | |
tag=variable.get("tag") | |
updated_url="" | |
if isinstance(url,list): | |
updated_url=",".join(url) | |
else: | |
updated_url=url | |
embedding=google_embeddings.embed_query(content) | |
vectors=[] | |
vectors.append({ | |
'id': str(uuid.uuid4()), | |
'values': embedding, | |
'metadata': { | |
'chunk': content, | |
"url":updated_url, | |
"tag":tag | |
} | |
}) | |
index.upsert(vectors) | |
print(f"inserted : {updated_url}") | |
except Exception as e: | |
print(f"error occured {e}") | |
create_embedding(podcasts) | |