如何解决Jupyter Notebook中Pinecone的两类报错问题?
两类LangChain-Pinecone向量存储错误的解决方法
错误1:调用vector_store.from_documents()提示Index 'None'不存在
问题原因
from_documents是PineconeVectorStore的类方法,并非实例方法。用已实例化的vector_store对象调用该方法时,内部无法正确读取你已指定的索引信息,因此抛出索引不存在的错误。
解决方法
直接通过PineconeVectorStore类调用from_documents,同时传入索引(或索引名称)与嵌入模型:
# 方案1:传入已创建的index对象 vector_store = PineconeVectorStore.from_documents( documents=documents, embedding=embeddings, index=index ) # 方案2:传入索引名(若环境变量已配置PINECONE_API_KEY,可省略pinecone_api_key参数) vector_store = PineconeVectorStore.from_documents( documents=documents, embedding=embeddings, index_name=index_name, pinecone_api_key=pinecone_api_key )
注意:无需提前实例化vector_store,类调用from_documents会直接返回新的PineconeVectorStore实例。
错误2:add_documents()提示向量维度不匹配(2048 vs 3072)
问题原因
你创建Pinecone索引时指定的维度为3072,但使用的gemma:2b模型生成的嵌入向量维度是2048,Pinecone要求向量维度必须与索引维度完全一致才能存储。
解决方法
有两种可行方案:
- 重建索引,匹配模型维度:
删除现有索引,重新创建维度为2048的索引:# 删除旧索引 pc.delete_index(index_name) # 创建新索引,维度改为2048 pc.create_index( name=index_name, dimension=2048, metric="cosine", spec=ServerlessSpec(cloud="aws", region="us-east-1"), ) # 等待索引就绪 while not pc.describe_index(index_name).status["ready"]: time.sleep(1) index = pc.Index(index_name) - 更换匹配索引维度的嵌入模型:
选用输出维度为3072的嵌入模型(如OpenAI的text-embedding-3-large等),确保模型输出维度与索引维度一致。
内容的提问来源于stack exchange,提问作者Atharva
相关产品推荐
相关产品推荐

