File size: 1,957 Bytes
1add76f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Clear all data from Pinecone index
One-time script for data cleanup before re-ingestion
"""

import os
from dotenv import load_dotenv
from pinecone import Pinecone

# Load environment variables
load_dotenv()

def clear_pinecone_index():
    """Delete all vectors from Pinecone index"""

    # Initialize Pinecone
    pc = Pinecone(api_key=os.getenv('PINECONE_API_KEY'))
    index = pc.Index(os.getenv('PINECONE_INDEX_NAME', 'hackathon'))

    # Get current stats
    stats = index.describe_index_stats()
    total_vectors = stats['total_vector_count']

    print("="*80)
    print("PINECONE DATA CLEANUP")
    print("="*80)
    print(f"\nIndex: {os.getenv('PINECONE_INDEX_NAME', 'hackathon')}")
    print(f"Current vectors: {total_vectors}")
    print(f"Dimensions: {stats.get('dimension', 'N/A')}")

    if total_vectors == 0:
        print("\n✅ Index is already empty. Nothing to delete.")
        return

    # Confirm deletion
    print(f"\n⚠️  WARNING: This will delete ALL {total_vectors} vectors!")
    confirm = input("Type 'DELETE' to confirm: ")

    if confirm != 'DELETE':
        print("\n❌ Deletion cancelled. No data was removed.")
        return

    print("\n🗑️  Deleting all vectors...")

    try:
        # Delete all vectors
        index.delete(delete_all=True)

        print("✅ Deletion completed!")

        # Verify deletion
        import time
        time.sleep(2)  # Wait for deletion to propagate

        stats = index.describe_index_stats()
        remaining = stats['total_vector_count']

        print(f"\n📊 Final status:")
        print(f"   Remaining vectors: {remaining}")

        if remaining == 0:
            print("   ✅ Index successfully cleared!")
        else:
            print(f"   ⚠️  {remaining} vectors still remain (may need a moment to sync)")

    except Exception as e:
        print(f"\n❌ Error during deletion: {e}")

if __name__ == "__main__":
    clear_pinecone_index()