import pinecone from langchain_google_genai import GoogleGenerativeAIEmbeddings from variables import variables # Import the list of variable names import uuid # Initialize Google Embeddings 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", None) 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 the chunk: {updated_url}") except Exception as e: print(f"Error occurred: {e}") # Iterate over the variable names and create embeddings for variable_name in variables: # Dynamically import the variable from paragraphs2 variable = __import__('paragraphs2', fromlist=[variable_name]) variable_data = getattr(variable, variable_name) print(f"trying to create embedding for {variable}") # Call the create_embedding function with the variable data create_embedding(variable_data)