Title: Pinecone Error when connecting with OpenAi: MaxRetryError
Tags: python,openai-api,langchain

Question: I have a simple app that lets you upload a pdf, splits it in chunks, make the embeddings and then uploads it to pinecone. But when I run
docsearch = Pinecone.from_texts([t.page_content for t in texts], embeddings, index_name=index_name)
I get the following error:
SSLEOFError                               Traceback (most recent call last)
File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:699, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    698 # Make the request on the httplib connection object.
--> 699 httplib_response = self._make_request(
    700     conn,
    701     method,
    702     url,
    703     timeout=timeout_obj,
    704     body=body,
    705     headers=headers,
    706     chunked=chunked,
    707 )
    709 # If we're going to release the connection in ``finally:``, then
    710 # the response doesn't need to know about the connection. Otherwise
    711 # it will also try to release it and we'll have a double-release
    712 # mess.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:394, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    393     else:
--> 394         conn.request(method, url, **httplib_request_kw)
    396 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
    397 # legitimately able to close the connection after sending a valid response.
    398 # With this behaviour, the received response is still readable.
...
--> 574     raise MaxRetryError(_pool, url, error or ResponseError(cause))
    576 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)
    578 return new_retry

MaxRetryError: HTTPSConnectionPool(host='langchain2-e630e5d.svc.asia-northeast1-gcp.pinecone.io', port=443): Max retries exceeded with url: /vectors/upsert (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))

I dont know what the error is.
here is the rest of the code:
from langchain.text_splitter import RecursiveCharacterTextSplitter

Load your data

loader = UnstructuredPDFLoader("../data/field-guide-to-data-science.pdf")
# loader = OnlinePDFLoader("https://wolfpaulus.com/wp-content/uploads/2017/05/field-guide-to-data-science.pdf")

data = loader.load()

print (f'You have {len(data)} document(s) in your data')
print (f'There are {len(data[0].page_content)} characters in your document')

You have 1 document(s) in your data
There are 176584 characters in your document

Chunk your data up into smaller documents

text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(data)

print (f'Now you have {len(texts)} documents')

Now you have 228 documents

Create embeddings of your documents to get ready for semantic search

from langchain.vectorstores import Chroma, Pinecone
from langchain.embeddings.openai import OpenAIEmbeddings
import pinecone

OPENAI_API_KEY = '...'
PINECONE_API_KEY = '...'
PINECONE_API_ENV = 'us-east1-gcp'

embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)

# initialize pinecone
pinecone.init(
    api_key=PINECONE_API_KEY,  # find at app.pinecone.io
    environment=PINECONE_API_ENV  # next to api key in console
)
index_name = "langchain2"

docsearch = Pinecone.from_texts([t.page_content for t in texts], embeddings, index_name=index_name)```

Answer: Check your PINECONE_ENVIRONMENT set