This is the error displayed when running the code.
(403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 08 Nov 2024 22:07:38 GMT', 'Content-Type': 'text/plain', 'Content-Length': '9', 'Connection': 'keep-alive', 'x-pinecone-auth-rejected-reason': 'Wrong API key', 'www-authenticate': 'Wrong API key', 'server': 'envoy'})
HTTP response body: Forbidden
I reissued the API key and tried again, but the same error persists. The API key seems valid, so I’m uncertain why this error keeps occurring.
Additionally, I upgraded to the Standard plan to see if that would help, but the issue still wasn’t resolved.
As an alternative solution, I also added sleep(30)
immediately after creating the Pinecone index, but this didn’t resolve the error either. This approach doesn’t appear to address the underlying issue.
API_KEY = "~"
pinecone = Pinecone(api_key=API_KEY)
index_name = "stock-research"
if index_name not in pinecone.list_indexes().names():
pinecone.create_index(
name=index_name,
dimension=768,
metric='cosine',
spec=ServerlessSpec(cloud='aws', region='us-east-1')
)
time.sleep(30)
index_description = pinecone.describe_index(index_name)
host = index_description.host
index = Index(index_name, host=host)
This function, upsert_data_from_db
, reads data from an SQLite database and uploads it to a Pinecone index.
def upsert_data_from_db(db_path):
# Connect to the database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Select data
cursor.execute("SELECT title, stock_name, broker, date, goal_price, recommendation, sub_title, body FROM research")
rows = cursor.fetchall()
# Upload each row to Pinecone
for row in rows:
title, stock_name, broker, date, goal_price, recommendation, sub_title, body = row
try:
# Generate vector embedding from the body
embedding = get_embedding(body)
# Upload data to Pinecone
index.upsert([
(
title, # Vector ID
embedding, # Embedding vector
{ # Metadata
"stock_name": stock_name,
"broker": broker,
"date": date,
"goal_price": goal_price,
"recommendation": recommendation,
"sub_title": sub_title,
"body": body
}
)
])
print(f"'{title}' data successfully uploaded to Pinecone.")
except Exception as e:
print(f"Error occurred while uploading data: {e}")
When running the code, I can confirm that the index is successfully created on the Pinecone site. However, the data has not been uploaded.
Is there something I’m missing? Please let me know if you need any more information.