File size: 1,289 Bytes
13fab0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
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)}"