in datastore/providers/pinecone_datastore.py [0:0]
def __init__(self):
# Check if the index name is specified and exists in Pinecone
if PINECONE_INDEX and PINECONE_INDEX not in pinecone.list_indexes():
# Get all fields in the metadata object in a list
fields_to_index = list(DocumentChunkMetadata.__fields__.keys())
# Create a new index with the specified name, dimension, and metadata configuration
try:
logger.info(
f"Creating index {PINECONE_INDEX} with metadata config {fields_to_index}"
)
pinecone.create_index(
PINECONE_INDEX,
dimension=EMBEDDING_DIMENSION,
metadata_config={"indexed": fields_to_index},
)
self.index = pinecone.Index(PINECONE_INDEX)
logger.info(f"Index {PINECONE_INDEX} created successfully")
except Exception as e:
logger.error(f"Error creating index {PINECONE_INDEX}: {e}")
raise e
elif PINECONE_INDEX and PINECONE_INDEX in pinecone.list_indexes():
# Connect to an existing index with the specified name
try:
logger.info(f"Connecting to existing index {PINECONE_INDEX}")
self.index = pinecone.Index(PINECONE_INDEX)
logger.info(f"Connected to index {PINECONE_INDEX} successfully")
except Exception as e:
logger.error(f"Error connecting to index {PINECONE_INDEX}: {e}")
raise e