I created a Pinecone index and now upserting or querying fails with a dimension error.
Why this happens
A Pinecone index's dimension is fixed when the index is created and can't be changed afterwards. Many tutorials create indexes with dimension=1536 because that matched OpenAI's older embedding model. If you then use a sentence-transformers model with 384 or 768 dimensions, every upsert fails.
Answer 1: Create an index with the dimension of your model
Read the dimension from your model and create a new index with it:
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(api_key="...")
dim = model.get_sentence_embedding_dimension()
pc.create_index(
name="docs-minilm",
dimension=dim,
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-east-1"),
)
Delete the old index with pc.delete_index("old-name") if you no longer need it.
