pinecone / indexes.py
abhishek kumar
Add application file
13fab0d
raw
history blame
1.29 kB
import os
from PyPDF2 import PdfReader
import pinecone
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Pinecone
from pinecone import init, create_index, Index
#from langchain.vectorstores import OpenAIEmbeddings
#from langchain.processing import PDFProcessor
#from langchain import configuration
debug_mode = os.getenv('DEBUG', 'False') == 'True'
verbose_mode = os.getenv('VERBOSE', 'False') == 'True'
def clear_indexes(pinecone_api_key: str, pinecone_environment: str, pinecone_index_name: str) -> str:
try:
print("Initializing Pinecone for clearing indexes...")
pinecone.init(api_key=pinecone_api_key, environment=pinecone_environment)
print("Checking existing Pinecone indexes for clearing...")
indexes_list = pinecone.list_indexes()
if pinecone_index_name in indexes_list:
print(f"Deleting Pinecone index: {pinecone_index_name}")
pinecone.delete_index(name=pinecone_index_name)
print("Index cleared.")
else:
print(f"No index named {pinecone_index_name} found to clear.")
return 'Indexes cleared.'
except Exception as e:
print(f"Error occurred in clear_indexes: {str(e)}")
return f"Error occurred: {str(e)}"