Hello all,
I have been debugging this for a while now and thought I should reach out for help now.
I have searched all similar posts and tried different things…
- venv, py 3.11
- able to echo $PC_API_KEY [set thru env var]
- API Key set explicitly in code (for debugging purposes)
- Able to get Pinecone Index information successfully
- Able to print API_KEY for debugging purpose right before vectorestore function
- Fails at PineconeVectorStore.from_documents
pinecone.exceptions.exceptions.PineconeConfigurationError: You haven't specified an Api-Key.
I am currently on a venv, py3.11.
from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_community.document_loaders import DirectoryLoader
from langchain_community.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from pinecone import ServerlessSpec
from pinecone import Pinecone as PineconeClient
import os
import glob
# Use PyPDFLoader for PDF files
loader = DirectoryLoader("./pdfs", glob="**/*.pdf", loader_cls=PyPDFLoader)
documents = loader.load()
# Retrieve API keys from environment variables
# openai_api_key = os.getenv('OPENAI_API_KEY')
# pinecone_api_key = os.getenv("PC_API_KEY")
os.environ['OPENAI_API_KEY'] = 'sk-....'
os.environ['PC_API_KEY'] = '7b....'
pinecone_api_key = os.environ.get("PC_API_KEY")
print(f"Pinecone API Key -Env: {pinecone_api_key}")
pc = PineconeClient(api_key=pinecone_api_key)
index_name = "agbot"
print(f"Pinecone: {pc.list_indexes()}")
embeddings = OpenAIEmbeddings(
model="text-embedding-3-small"
)
# split our docs into chunks
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
docs = text_splitter.split_documents(documents)
vectorstore_from_docs = PineconeVectorStore.from_documents(
docs,
index_name=index_name,
embedding=embeddings,
pinecone_client=pc,
pinecone_api_key=pinecone_api_key
)