class EmbeddingHandler:
def __init__(self, faq_path, embedding_model):
self.embedding_model = embedding_model
self.index_name = os.getenv("PINECONE_INDEX_NAME", "chatbot-index")
# Initialize Pinecone
self.initialize_pinecone()
def initialize_pinecone(self):
try:
# Initialize the Pinecone instance
self.pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"), environment=os.getenv("PINECONE_ENVIRONMENT"))
#self.pc = pinecone.init(api_key=os.getenv("PINECONE_API_KEY"), environment=os.getenv("PINECONE_ENVIRONMENT"))
if self.index_name not in self.pc.list_indexes().names():
self.pc.create_index(
name=self.index_name,
dimension=1536,
metric='cosine',
spec=ServerlessSpec(cloud='aws', region='us-east-1')
)
time.sleep(30) # Ensure the index is ready
index_description = self.pc.describe_index(self.index_name)
host = index_description['host']
self.index = pinecone.Index(self.index_name, host=host) # Connect to the Pinecone index
logger.info("Successfully initialized Pinecone.")
except Exception as e:
logger.error(f"Error initializing Pinecone: {e}")
raise e
Till here it works fine I guess, as I’m seeing successfully initialized pinecone in my logs.
def index_embeddings(self, texts):
"""Index the FAQ and web data into Pinecone"""
vectors = self.embedding_model.embed_documents(texts) # Generate embeddings for the texts
for i, vector in enumerate(vectors):
metadata = {"text": texts[i]} # Store the original text as metadata
try:
self.index.upsert(vectors=[(str(i), vector, metadata)]) # Upsert the vectors into Pinecone
logger.info(f"Successfully upserted vector {i}")
except Exception as e:
logger.error(f"Error during upsert for vector {i}: {e}")
raise e
logger.info("Successfully indexed all embeddings into Pinecone.")
here, im getting, ERROR:app.embeddings:Error during upsert for vector 0: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({‘Date’: ‘Fri, 25 Oct 2024 00:05:09 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’m using free version of pinecone, I didn’t hit any limit. My API key is perfect and index name too. I’m not sure why this error is popping up. Anyone please help is resolve this, its taking alot of time for me.