APIConnectionError: Connection error exception persisting confluence data to vectorDB

I could successfully load and process my confluence data with scale like:

  • 868 documents
  • 1 million splits

However when I tried to persist it in vectorDB with something like:

vectordb = Chroma.from_documents(
    documents=splits,
    embedding=embedding,
    persist_directory=persist_directory
)

it ran over a couple of hours on my modest laptop eventually throwing an exception of APIConnectionError: Connection error.

Is it some kind of timeout? If so, how do I get around it?

Any ideas?

Here is the complete stack:

---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\httpcore\_exceptions.py:10, in map_exceptions(map)
      9 try:
---> 10     yield
     11 except Exception as exc:  # noqa: PIE786

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_backends\sync.py:100, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
     99 with map_exceptions(exc_map):
--> 100     sock = socket.create_connection(
    101         address,
    102         timeout,
    103         source_address=source_address,
    104     )
    105     for option in socket_options:

File ~\AppData\Local\Programs\Python\Python310\lib\socket.py:824, in create_connection(address, timeout, source_address)
    823 err = None
--> 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    825     af, socktype, proto, canonname, sa = res

File ~\AppData\Local\Programs\Python\Python310\lib\socket.py:955, in getaddrinfo(host, port, family, type, proto, flags)
    954 addrlist = []
--> 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    956     af, socktype, proto, canonname, sa = res

gaierror: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

ConnectError                              Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:60, in map_httpcore_exceptions()
     59 try:
---> 60     yield
     61 except Exception as exc:  # noqa: PIE-786

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:218, in HTTPTransport.handle_request(self, request)
    217 with map_httpcore_exceptions():
--> 218     resp = self._pool.handle_request(req)
    220 assert isinstance(resp.stream, typing.Iterable)

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection_pool.py:262, in ConnectionPool.handle_request(self, request)
    261         self.response_closed(status)
--> 262     raise exc
    263 else:

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection_pool.py:245, in ConnectionPool.handle_request(self, request)
    244 try:
--> 245     response = connection.handle_request(request)
    246 except ConnectionNotAvailable:
    247     # The ConnectionNotAvailable exception is a special case, that
    248     # indicates we need to retry the request on a new connection.
   (...)
    252     # might end up as an HTTP/2 connection, but which actually ends
    253     # up as HTTP/1.1.

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:92, in HTTPConnection.handle_request(self, request)
     91         self._connect_failed = True
---> 92         raise exc
     93 elif not self._connection.is_available():

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:69, in HTTPConnection.handle_request(self, request)
     68 try:
---> 69     stream = self._connect(request)
     71     ssl_object = stream.get_extra_info("ssl_object")

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:117, in HTTPConnection._connect(self, request)
    116 with Trace("connect_tcp", logger, request, kwargs) as trace:
--> 117     stream = self._network_backend.connect_tcp(**kwargs)
    118     trace.return_value = stream

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_backends\sync.py:99, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
     94 exc_map: ExceptionMapping = {
     95     socket.timeout: ConnectTimeout,
     96     OSError: ConnectError,
     97 }
---> 99 with map_exceptions(exc_map):
    100     sock = socket.create_connection(
    101         address,
    102         timeout,
    103         source_address=source_address,
    104     )

File ~\AppData\Local\Programs\Python\Python310\lib\contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    152 try:
--> 153     self.gen.throw(typ, value, traceback)
    154 except StopIteration as exc:
    155     # Suppress StopIteration *unless* it's the same exception that
    156     # was passed to throw().  This prevents a StopIteration
    157     # raised inside the "with" statement from being suppressed.

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_exceptions.py:14, in map_exceptions(map)
     13     if isinstance(exc, from_exc):
---> 14         raise to_exc(exc) from exc
     15 raise

ConnectError: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

ConnectError                              Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:882, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    881 try:
--> 882     response = self._client.send(
    883         request,
    884         auth=self.custom_auth,
    885         stream=stream or self._should_stream_response_body(request=request),
    886     )
    887     log.debug(
    888         'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
    889     )

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:901, in Client.send(self, request, stream, auth, follow_redirects)
    899 auth = self._build_request_auth(request, auth)
--> 901 response = self._send_handling_auth(
    902     request,
    903     auth=auth,
    904     follow_redirects=follow_redirects,
    905     history=[],
    906 )
    907 try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:929, in Client._send_handling_auth(self, request, auth, follow_redirects, history)
    928 while True:
--> 929     response = self._send_handling_redirects(
    930         request,
    931         follow_redirects=follow_redirects,
    932         history=history,
    933     )
    934     try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:966, in Client._send_handling_redirects(self, request, follow_redirects, history)
    964     hook(request)
--> 966 response = self._send_single_request(request)
    967 try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:1002, in Client._send_single_request(self, request)
   1001 with request_context(request=request):
-> 1002     response = transport.handle_request(request)
   1004 assert isinstance(response.stream, SyncByteStream)

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:217, in HTTPTransport.handle_request(self, request)
    205 req = httpcore.Request(
    206     method=request.method,
    207     url=httpcore.URL(
   (...)
    215     extensions=request.extensions,
    216 )
--> 217 with map_httpcore_exceptions():
    218     resp = self._pool.handle_request(req)

File ~\AppData\Local\Programs\Python\Python310\lib\contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    152 try:
--> 153     self.gen.throw(typ, value, traceback)
    154 except StopIteration as exc:
    155     # Suppress StopIteration *unless* it's the same exception that
    156     # was passed to throw().  This prevents a StopIteration
    157     # raised inside the "with" statement from being suppressed.

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:77, in map_httpcore_exceptions()
     76 message = str(exc)
---> 77 raise mapped_exc(message) from exc

ConnectError: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

gaierror                                  Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\httpcore\_exceptions.py:10, in map_exceptions(map)
      9 try:
---> 10     yield
     11 except Exception as exc:  # noqa: PIE786

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_backends\sync.py:100, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
     99 with map_exceptions(exc_map):
--> 100     sock = socket.create_connection(
    101         address,
    102         timeout,
    103         source_address=source_address,
    104     )
    105     for option in socket_options:

File ~\AppData\Local\Programs\Python\Python310\lib\socket.py:824, in create_connection(address, timeout, source_address)
    823 err = None
--> 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    825     af, socktype, proto, canonname, sa = res

File ~\AppData\Local\Programs\Python\Python310\lib\socket.py:955, in getaddrinfo(host, port, family, type, proto, flags)
    954 addrlist = []
--> 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    956     af, socktype, proto, canonname, sa = res

gaierror: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

ConnectError                              Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:60, in map_httpcore_exceptions()
     59 try:
---> 60     yield
     61 except Exception as exc:  # noqa: PIE-786

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:218, in HTTPTransport.handle_request(self, request)
    217 with map_httpcore_exceptions():
--> 218     resp = self._pool.handle_request(req)
    220 assert isinstance(resp.stream, typing.Iterable)

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection_pool.py:262, in ConnectionPool.handle_request(self, request)
    261         self.response_closed(status)
--> 262     raise exc
    263 else:

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection_pool.py:245, in ConnectionPool.handle_request(self, request)
    244 try:
--> 245     response = connection.handle_request(request)
    246 except ConnectionNotAvailable:
    247     # The ConnectionNotAvailable exception is a special case, that
    248     # indicates we need to retry the request on a new connection.
   (...)
    252     # might end up as an HTTP/2 connection, but which actually ends
    253     # up as HTTP/1.1.

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:92, in HTTPConnection.handle_request(self, request)
     91         self._connect_failed = True
---> 92         raise exc
     93 elif not self._connection.is_available():

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:69, in HTTPConnection.handle_request(self, request)
     68 try:
---> 69     stream = self._connect(request)
     71     ssl_object = stream.get_extra_info("ssl_object")

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:117, in HTTPConnection._connect(self, request)
    116 with Trace("connect_tcp", logger, request, kwargs) as trace:
--> 117     stream = self._network_backend.connect_tcp(**kwargs)
    118     trace.return_value = stream

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_backends\sync.py:99, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
     94 exc_map: ExceptionMapping = {
     95     socket.timeout: ConnectTimeout,
     96     OSError: ConnectError,
     97 }
---> 99 with map_exceptions(exc_map):
    100     sock = socket.create_connection(
    101         address,
    102         timeout,
    103         source_address=source_address,
    104     )

File ~\AppData\Local\Programs\Python\Python310\lib\contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    152 try:
--> 153     self.gen.throw(typ, value, traceback)
    154 except StopIteration as exc:
    155     # Suppress StopIteration *unless* it's the same exception that
    156     # was passed to throw().  This prevents a StopIteration
    157     # raised inside the "with" statement from being suppressed.

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_exceptions.py:14, in map_exceptions(map)
     13     if isinstance(exc, from_exc):
---> 14         raise to_exc(exc) from exc
     15 raise

ConnectError: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

ConnectError                              Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:882, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    881 try:
--> 882     response = self._client.send(
    883         request,
    884         auth=self.custom_auth,
    885         stream=stream or self._should_stream_response_body(request=request),
    886     )
    887     log.debug(
    888         'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
    889     )

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:901, in Client.send(self, request, stream, auth, follow_redirects)
    899 auth = self._build_request_auth(request, auth)
--> 901 response = self._send_handling_auth(
    902     request,
    903     auth=auth,
    904     follow_redirects=follow_redirects,
    905     history=[],
    906 )
    907 try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:929, in Client._send_handling_auth(self, request, auth, follow_redirects, history)
    928 while True:
--> 929     response = self._send_handling_redirects(
    930         request,
    931         follow_redirects=follow_redirects,
    932         history=history,
    933     )
    934     try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:966, in Client._send_handling_redirects(self, request, follow_redirects, history)
    964     hook(request)
--> 966 response = self._send_single_request(request)
    967 try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:1002, in Client._send_single_request(self, request)
   1001 with request_context(request=request):
-> 1002     response = transport.handle_request(request)
   1004 assert isinstance(response.stream, SyncByteStream)

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:217, in HTTPTransport.handle_request(self, request)
    205 req = httpcore.Request(
    206     method=request.method,
    207     url=httpcore.URL(
   (...)
    215     extensions=request.extensions,
    216 )
--> 217 with map_httpcore_exceptions():
    218     resp = self._pool.handle_request(req)

File ~\AppData\Local\Programs\Python\Python310\lib\contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    152 try:
--> 153     self.gen.throw(typ, value, traceback)
    154 except StopIteration as exc:
    155     # Suppress StopIteration *unless* it's the same exception that
    156     # was passed to throw().  This prevents a StopIteration
    157     # raised inside the "with" statement from being suppressed.

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:77, in map_httpcore_exceptions()
     76 message = str(exc)
---> 77 raise mapped_exc(message) from exc

ConnectError: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

gaierror                                  Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\httpcore\_exceptions.py:10, in map_exceptions(map)
      9 try:
---> 10     yield
     11 except Exception as exc:  # noqa: PIE786

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_backends\sync.py:100, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
     99 with map_exceptions(exc_map):
--> 100     sock = socket.create_connection(
    101         address,
    102         timeout,
    103         source_address=source_address,
    104     )
    105     for option in socket_options:

File ~\AppData\Local\Programs\Python\Python310\lib\socket.py:824, in create_connection(address, timeout, source_address)
    823 err = None
--> 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    825     af, socktype, proto, canonname, sa = res

File ~\AppData\Local\Programs\Python\Python310\lib\socket.py:955, in getaddrinfo(host, port, family, type, proto, flags)
    954 addrlist = []
--> 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    956     af, socktype, proto, canonname, sa = res

gaierror: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

ConnectError                              Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:60, in map_httpcore_exceptions()
     59 try:
---> 60     yield
     61 except Exception as exc:  # noqa: PIE-786

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:218, in HTTPTransport.handle_request(self, request)
    217 with map_httpcore_exceptions():
--> 218     resp = self._pool.handle_request(req)
    220 assert isinstance(resp.stream, typing.Iterable)

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection_pool.py:262, in ConnectionPool.handle_request(self, request)
    261         self.response_closed(status)
--> 262     raise exc
    263 else:

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection_pool.py:245, in ConnectionPool.handle_request(self, request)
    244 try:
--> 245     response = connection.handle_request(request)
    246 except ConnectionNotAvailable:
    247     # The ConnectionNotAvailable exception is a special case, that
    248     # indicates we need to retry the request on a new connection.
   (...)
    252     # might end up as an HTTP/2 connection, but which actually ends
    253     # up as HTTP/1.1.

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:92, in HTTPConnection.handle_request(self, request)
     91         self._connect_failed = True
---> 92         raise exc
     93 elif not self._connection.is_available():

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:69, in HTTPConnection.handle_request(self, request)
     68 try:
---> 69     stream = self._connect(request)
     71     ssl_object = stream.get_extra_info("ssl_object")

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_sync\connection.py:117, in HTTPConnection._connect(self, request)
    116 with Trace("connect_tcp", logger, request, kwargs) as trace:
--> 117     stream = self._network_backend.connect_tcp(**kwargs)
    118     trace.return_value = stream

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_backends\sync.py:99, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options)
     94 exc_map: ExceptionMapping = {
     95     socket.timeout: ConnectTimeout,
     96     OSError: ConnectError,
     97 }
---> 99 with map_exceptions(exc_map):
    100     sock = socket.create_connection(
    101         address,
    102         timeout,
    103         source_address=source_address,
    104     )

File ~\AppData\Local\Programs\Python\Python310\lib\contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    152 try:
--> 153     self.gen.throw(typ, value, traceback)
    154 except StopIteration as exc:
    155     # Suppress StopIteration *unless* it's the same exception that
    156     # was passed to throw().  This prevents a StopIteration
    157     # raised inside the "with" statement from being suppressed.

File C:\GenerativeAI\venv\lib\site-packages\httpcore\_exceptions.py:14, in map_exceptions(map)
     13     if isinstance(exc, from_exc):
---> 14         raise to_exc(exc) from exc
     15 raise

ConnectError: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

ConnectError                              Traceback (most recent call last)
File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:882, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    881 try:
--> 882     response = self._client.send(
    883         request,
    884         auth=self.custom_auth,
    885         stream=stream or self._should_stream_response_body(request=request),
    886     )
    887     log.debug(
    888         'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
    889     )

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:901, in Client.send(self, request, stream, auth, follow_redirects)
    899 auth = self._build_request_auth(request, auth)
--> 901 response = self._send_handling_auth(
    902     request,
    903     auth=auth,
    904     follow_redirects=follow_redirects,
    905     history=[],
    906 )
    907 try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:929, in Client._send_handling_auth(self, request, auth, follow_redirects, history)
    928 while True:
--> 929     response = self._send_handling_redirects(
    930         request,
    931         follow_redirects=follow_redirects,
    932         history=history,
    933     )
    934     try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:966, in Client._send_handling_redirects(self, request, follow_redirects, history)
    964     hook(request)
--> 966 response = self._send_single_request(request)
    967 try:

File C:\GenerativeAI\venv\lib\site-packages\httpx\_client.py:1002, in Client._send_single_request(self, request)
   1001 with request_context(request=request):
-> 1002     response = transport.handle_request(request)
   1004 assert isinstance(response.stream, SyncByteStream)

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:217, in HTTPTransport.handle_request(self, request)
    205 req = httpcore.Request(
    206     method=request.method,
    207     url=httpcore.URL(
   (...)
    215     extensions=request.extensions,
    216 )
--> 217 with map_httpcore_exceptions():
    218     resp = self._pool.handle_request(req)

File ~\AppData\Local\Programs\Python\Python310\lib\contextlib.py:153, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    152 try:
--> 153     self.gen.throw(typ, value, traceback)
    154 except StopIteration as exc:
    155     # Suppress StopIteration *unless* it's the same exception that
    156     # was passed to throw().  This prevents a StopIteration
    157     # raised inside the "with" statement from being suppressed.

File C:\GenerativeAI\venv\lib\site-packages\httpx\_transports\default.py:77, in map_httpcore_exceptions()
     76 message = str(exc)
---> 77 raise mapped_exc(message) from exc

ConnectError: [Errno 11001] getaddrinfo failed

The above exception was the direct cause of the following exception:

APIConnectionError                        Traceback (most recent call last)
Cell In[6], line 1
----> 1 vectordb2 = Chroma.from_documents(
      2     documents=splits,
      3     embedding=embedding,
      4     persist_directory=persist_directory
      5 )
      6 vectordb = Chroma(persist_directory=persist_directory, embedding_function=embedding)

File C:\GenerativeAI\venv\lib\site-packages\langchain\vectorstores\chroma.py:771, in Chroma.from_documents(cls, documents, embedding, ids, collection_name, persist_directory, client_settings, client, collection_metadata, **kwargs)
    769 texts = [doc.page_content for doc in documents]
    770 metadatas = [doc.metadata for doc in documents]
--> 771 return cls.from_texts(
    772     texts=texts,
    773     embedding=embedding,
    774     metadatas=metadatas,
    775     ids=ids,
    776     collection_name=collection_name,
    777     persist_directory=persist_directory,
    778     client_settings=client_settings,
    779     client=client,
    780     collection_metadata=collection_metadata,
    781     **kwargs,
    782 )

File C:\GenerativeAI\venv\lib\site-packages\langchain\vectorstores\chroma.py:729, in Chroma.from_texts(cls, texts, embedding, metadatas, ids, collection_name, persist_directory, client_settings, client, collection_metadata, **kwargs)
    721     from chromadb.utils.batch_utils import create_batches
    723     for batch in create_batches(
    724         api=chroma_collection._client,
    725         ids=ids,
    726         metadatas=metadatas,
    727         documents=texts,
    728     ):
--> 729         chroma_collection.add_texts(
    730             texts=batch[3] if batch[3] else [],
    731             metadatas=batch[2] if batch[2] else None,
    732             ids=batch[0],
    733         )
    734 else:
    735     chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)

File C:\GenerativeAI\venv\lib\site-packages\langchain\vectorstores\chroma.py:275, in Chroma.add_texts(self, texts, metadatas, ids, **kwargs)
    273 texts = list(texts)
    274 if self._embedding_function is not None:
--> 275     embeddings = self._embedding_function.embed_documents(texts)
    276 if metadatas:
    277     # fill metadatas with empty dicts if somebody
    278     # did not specify metadata for all texts
    279     length_diff = len(texts) - len(metadatas)

File C:\GenerativeAI\venv\lib\site-packages\langchain\embeddings\openai.py:556, in OpenAIEmbeddings.embed_documents(self, texts, chunk_size)
    553 # NOTE: to keep things simple, we assume the list may contain texts longer
    554 #       than the maximum context and use length-safe embedding function.
    555 engine = cast(str, self.deployment)
--> 556 return self._get_len_safe_embeddings(texts, engine=engine)

File C:\GenerativeAI\venv\lib\site-packages\langchain\embeddings\openai.py:432, in OpenAIEmbeddings._get_len_safe_embeddings(self, texts, engine, chunk_size)
    429     _iter = range(0, len(tokens), _chunk_size)
    431 for i in _iter:
--> 432     response = embed_with_retry(
    433         self,
    434         input=tokens[i : i + _chunk_size],
    435         **self._invocation_params,
    436     )
    437     if not isinstance(response, dict):
    438         response = response.dict()

File C:\GenerativeAI\venv\lib\site-packages\langchain\embeddings\openai.py:107, in embed_with_retry(embeddings, **kwargs)
    105 """Use tenacity to retry the embedding call."""
    106 if _is_openai_v1():
--> 107     return embeddings.client.create(**kwargs)
    108 retry_decorator = _create_retry_decorator(embeddings)
    110 @retry_decorator
    111 def _embed_with_retry(**kwargs: Any) -> Any:

File C:\GenerativeAI\venv\lib\site-packages\openai\resources\embeddings.py:105, in Embeddings.create(self, input, model, encoding_format, user, extra_headers, extra_query, extra_body, timeout)
     99         embedding.embedding = np.frombuffer(  # type: ignore[no-untyped-call]
    100             base64.b64decode(data), dtype="float32"
    101         ).tolist()
    103     return obj
--> 105 return self._post(
    106     "/embeddings",
    107     body=maybe_transform(params, embedding_create_params.EmbeddingCreateParams),
    108     options=make_request_options(
    109         extra_headers=extra_headers,
    110         extra_query=extra_query,
    111         extra_body=extra_body,
    112         timeout=timeout,
    113         post_parser=parser,
    114     ),
    115     cast_to=CreateEmbeddingResponse,
    116 )

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:1096, in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls)
   1082 def post(
   1083     self,
   1084     path: str,
   (...)
   1091     stream_cls: type[_StreamT] | None = None,
   1092 ) -> ResponseT | _StreamT:
   1093     opts = FinalRequestOptions.construct(
   1094         method="post", url=path, json_data=body, files=to_httpx_files(files), **options
   1095     )
-> 1096     return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:856, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
    847 def request(
    848     self,
    849     cast_to: Type[ResponseT],
   (...)
    854     stream_cls: type[_StreamT] | None = None,
    855 ) -> ResponseT | _StreamT:
--> 856     return self._request(
    857         cast_to=cast_to,
    858         options=options,
    859         stream=stream,
    860         stream_cls=stream_cls,
    861         remaining_retries=remaining_retries,
    862     )

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:929, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    926         response.close()
    928     if retries > 0:
--> 929         return self._retry_request(
    930             options,
    931             cast_to,
    932             retries,
    933             stream=stream,
    934             stream_cls=stream_cls,
    935             response_headers=response.headers if response is not None else None,
    936         )
    938     raise APIConnectionError(request=request) from err
    940 return self._process_response(
    941     cast_to=cast_to,
    942     options=options,
   (...)
    945     stream_cls=stream_cls,
    946 )

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:966, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)
    962 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
    963 # different thread if necessary.
    964 time.sleep(timeout)
--> 966 return self._request(
    967     options=options,
    968     cast_to=cast_to,
    969     remaining_retries=remaining,
    970     stream=stream,
    971     stream_cls=stream_cls,
    972 )

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:929, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    926         response.close()
    928     if retries > 0:
--> 929         return self._retry_request(
    930             options,
    931             cast_to,
    932             retries,
    933             stream=stream,
    934             stream_cls=stream_cls,
    935             response_headers=response.headers if response is not None else None,
    936         )
    938     raise APIConnectionError(request=request) from err
    940 return self._process_response(
    941     cast_to=cast_to,
    942     options=options,
   (...)
    945     stream_cls=stream_cls,
    946 )

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:966, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)
    962 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
    963 # different thread if necessary.
    964 time.sleep(timeout)
--> 966 return self._request(
    967     options=options,
    968     cast_to=cast_to,
    969     remaining_retries=remaining,
    970     stream=stream,
    971     stream_cls=stream_cls,
    972 )

File C:\GenerativeAI\venv\lib\site-packages\openai\_base_client.py:938, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    928     if retries > 0:
    929         return self._retry_request(
    930             options,
    931             cast_to,
   (...)
    935             response_headers=response.headers if response is not None else None,
    936         )
--> 938     raise APIConnectionError(request=request) from err
    940 return self._process_response(
    941     cast_to=cast_to,
    942     options=options,
   (...)
    945     stream_cls=stream_cls,
    946 )

APIConnectionError: Connection error.

It was due to small chunk size. Increasing it fixed my problem.