singhankur01 commited on
Commit
a5b881d
·
verified ·
1 Parent(s): 0db54f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -81,26 +81,27 @@ def verify_api_key(authorization: str = Header(...)):
81
  if token != TEAM_API_KEY:
82
  raise HTTPException(status_code=403, detail="Invalid or missing API key")
83
 
84
- def create_serverless_index(pc, index_name):
85
- """Create a Pinecone serverless index using managed model dimensions."""
86
- existing_indexes = [index.name for index in pc.list_indexes()]
87
-
88
  if index_name not in existing_indexes:
89
- pc.create_index(
 
90
  name=index_name,
91
- dimension=1024, # multilingual-e5-large output dimension
92
- metric="cosine",
93
  spec={
94
- "serverless": {
95
- cloud='gcp', # ✅ Use GCP for Free Tier
96
- region='us-central1' # ✅ Free Tier supported region
97
  }
98
  }
99
  )
100
- print(f"✅ Created serverless index: {index_name}")
101
-
102
- # Return index object
103
- return pc.Index(index_name)
 
104
 
105
  async def embed_with_pinecone_inference(pc, texts, model="multilingual-e5-large"):
106
  """Use Pinecone's hosted inference model for embeddings."""
 
81
  if token != TEAM_API_KEY:
82
  raise HTTPException(status_code=403, detail="Invalid or missing API key")
83
 
84
+ def create_serverless_index(pinecone_client, index_name):
85
+ """Creates a Pinecone serverless index if it doesn't already exist."""
86
+ existing_indexes = [index_info.name for index_info in pinecone_client.list_indexes().indexes]
 
87
  if index_name not in existing_indexes:
88
+ print(f"🪄 Creating serverless index: {index_name}")
89
+ pinecone_client.create_index(
90
  name=index_name,
91
+ dimension=768, # or 384 depending on your embedding model
92
+ metric='cosine',
93
  spec={
94
+ 'serverless': {
95
+ 'cloud': 'gcp', # ✅ Required for Free Tier
96
+ 'region': 'gcp-starter' # ✅ Required for Free Tier
97
  }
98
  }
99
  )
100
+ print("✅ Index created.")
101
+ else:
102
+ print(f"⚠️ Index '{index_name}' already exists.")
103
+ return pinecone_client.Index(index_name)
104
+
105
 
106
  async def embed_with_pinecone_inference(pc, texts, model="multilingual-e5-large"):
107
  """Use Pinecone's hosted inference model for embeddings."""