File size: 2,050 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
"""
Check Pinecone index status and statistics
Quick utility to inspect vector database
"""

import os
from dotenv import load_dotenv
from pinecone import Pinecone

# Load environment variables
load_dotenv()

def check_pinecone_status():
    """Display Pinecone index information"""

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

        # Get index statistics
        stats = index.describe_index_stats()

        print("="*80)
        print("PINECONE INDEX STATUS")
        print("="*80)

        print(f"\n📊 Index Information:")
        print(f"   Name: {index_name}")
        print(f"   Total Vectors: {stats.get('total_vector_count', 0):,}")
        print(f"   Dimensions: {stats.get('dimension', 'N/A')}")

        # Check namespaces if any
        if 'namespaces' in stats and stats['namespaces']:
            print(f"\n📁 Namespaces:")
            for ns_name, ns_stats in stats['namespaces'].items():
                ns_display = ns_name if ns_name else "(default)"
                print(f"   {ns_display}: {ns_stats.get('vector_count', 0):,} vectors")

        # Index configuration
        print(f"\n⚙️  Configuration:")
        print(f"   API Key: {os.getenv('PINECONE_API_KEY')[:10]}..." if os.getenv('PINECONE_API_KEY') else "   API Key: Not set")

        # Connection status
        if stats.get('total_vector_count', 0) > 0:
            print(f"\n✅ Status: Connected and populated")
        else:
            print(f"\n⚠️  Status: Connected but empty")

    except Exception as e:
        print("="*80)
        print("PINECONE CONNECTION ERROR")
        print("="*80)
        print(f"\n❌ Error: {e}")
        print("\nPlease check:")
        print("  1. PINECONE_API_KEY in .env file")
        print("  2. PINECONE_INDEX_NAME in .env file")
        print("  3. Index exists in your Pinecone account")

if __name__ == "__main__":
    check_pinecone_status()