Files
ds_task_scp_bolade/src/reset_pinecone_index.py
T

42 lines
1.4 KiB
Python
Raw Normal View History

from pinecone import Pinecone
from services.config import config
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler("reset_pinecone.log"),
logging.StreamHandler()
]
)
def reset_pinecone_index():
try:
# Initialize Pinecone client
pinecone = Pinecone(api_key=config.PINECONE_API_KEY)
# Check if index exists
if config.PINECONE_INDEX_NAME in pinecone.list_indexes().names():
logging.info(f"Deleting existing index '{config.PINECONE_INDEX_NAME}'")
pinecone.delete_index(config.PINECONE_INDEX_NAME)
# Create a new index with the correct dimension
logging.info(f"Creating new index '{config.PINECONE_INDEX_NAME}' with dimension {config.VECTOR_DIMENSION}")
pinecone.create_index(
name=config.PINECONE_INDEX_NAME,
dimension=config.VECTOR_DIMENSION,
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-east-1")
)
logging.info("Pinecone index reset successfully")
return True
except Exception as e:
logging.error(f"Error resetting Pinecone index: {str(e)}")
return False
if __name__ == "__main__":
from pinecone import ServerlessSpec
reset_pinecone_index()