Open jermkim-x opened 1 month ago
The APIConnectionError
you're encountering in the MultiModalVectorStoreIndex
module can be caused by several factors:
api_endpoint
provided is correct and reachable.token
used for authentication is valid and not expired.Additionally, the MultiModalVectorStoreIndex
module interacts with external APIs like the OpenAI API during the embedding process, which can also lead to connection errors if there are issues with the API or network [1][2].
To diagnose and resolve these issues, you can enable more detailed logging by setting the logging level to DEBUG
:
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
Additionally, you can set a global handler for LlamaIndex to get more insights:
import llama_index.core
llama_index.core.set_global_handler("simple")
These steps should help you gather more information about the connection issues and assist in troubleshooting them effectively [3][4].
To continue talking to Dosu, mention @dosu.
Question Validation
Question
I’m using MultiModalVectorStoreIndex module to build an index of the mistakes. I am now confused as to whether it is simply because my API is faulty or because the build itself is faulty.
The following is the content of the error:
ConnectError Traceback (most recent call last) File ~/miniconda3/lib/python3.12/site-packages/httpx/_transports/default.py:69, in map_httpcore_exceptions() 68 try: ---> 69 yield 70 except Exception as exc:
File ~/miniconda3/lib/python3.12/site-packages/httpx/_transports/default.py:233, in HTTPTransport.handle_request(self, request) 232 with map_httpcore_exceptions(): --> 233 resp = self._pool.handle_request(req) 235 assert isinstance(resp.stream, typing.Iterable)
File ~/miniconda3/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py:216, in ConnectionPool.handle_request(self, request) 215 self._close_connections(closing) --> 216 raise exc from None 218 # Return the response. Note that in this case we still have to manage 219 # the point at which the response is closed.
File ~/miniconda3/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py:196, in ConnectionPool.handle_request(self, request) 194 try: 195 # Send the request on the assigned connection. --> 196 response = connection.handle_request( 197 pool_request.request 198 ) 199 except ConnectionNotAvailable: 200 # In some cases a connection may initially be available to 201 # handle a request, but then become unavailable. 202 # 203 # In this case we clear the connection and try again.
File ~/miniconda3/lib/python3.12/site-packages/httpcore/_sync/connection.py:99, in HTTPConnection.handle_request(self, request) 98 self._connect_failed = True ---> 99 raise exc 101 return self._connection.handle_request(request)
File ~/miniconda3/lib/python3.12/site-packages/httpcore/_sync/connection.py:76, in HTTPConnection.handle_request(self, request) 75 if self._connection is None: ---> 76 stream = self._connect(request) 78 ssl_object = stream.get_extra_info("ssl_object")
File ~/miniconda3/lib/python3.12/site-packages/httpcore/_sync/connection.py:122, in HTTPConnection._connect(self, request) 121 with Trace("connect_tcp", logger, request, kwargs) as trace: --> 122 stream = self._network_backend.connect_tcp(**kwargs) 123 trace.return_value = stream
File ~/miniconda3/lib/python3.12/site-packages/httpcore/_backends/sync.py:205, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options) 200 exc_map: ExceptionMapping = { 201 socket.timeout: ConnectTimeout, 202 OSError: ConnectError, 203 } --> 205 with map_exceptions(exc_map): 206 sock = socket.create_connection( 207 address, 208 timeout, 209 source_address=source_address, 210 )
File ~/miniconda3/lib/python3.12/contextlib.py:158, in _GeneratorContextManager.exit(self, typ, value, traceback) 157 try: --> 158 self.gen.throw(value) 159 except StopIteration as exc: 160 # Suppress StopIteration unless it's the same exception that 161 # was passed to throw(). This prevents a StopIteration 162 # raised inside the "with" statement from being suppressed.
File ~/miniconda3/lib/python3.12/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 99] Cannot assign requested address
The above exception was the direct cause of the following exception:
ConnectError Traceback (most recent call last) File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:978, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 977 try: --> 978 response = self._client.send( 979 request, 980 stream=stream or self._should_stream_response_body(request=request), 981 **kwargs, 982 ) 983 except httpx.TimeoutException as err:
File ~/miniconda3/lib/python3.12/site-packages/httpx/_client.py:914, in Client.send(self, request, stream, auth, follow_redirects) 912 auth = self._build_request_auth(request, auth) --> 914 response = self._send_handling_auth( 915 request, 916 auth=auth, 917 follow_redirects=follow_redirects, 918 history=[], 919 ) 920 try:
File ~/miniconda3/lib/python3.12/site-packages/httpx/_client.py:942, in Client._send_handling_auth(self, request, auth, follow_redirects, history) 941 while True: --> 942 response = self._send_handling_redirects( 943 request, 944 follow_redirects=follow_redirects, 945 history=history, 946 ) 947 try:
File ~/miniconda3/lib/python3.12/site-packages/httpx/_client.py:979, in Client._send_handling_redirects(self, request, follow_redirects, history) 977 hook(request) --> 979 response = self._send_single_request(request) 980 try:
File ~/miniconda3/lib/python3.12/site-packages/httpx/_client.py:1015, in Client._send_single_request(self, request) 1014 with request_context(request=request): -> 1015 response = transport.handle_request(request) 1017 assert isinstance(response.stream, SyncByteStream)
File ~/miniconda3/lib/python3.12/site-packages/httpx/_transports/default.py:232, in HTTPTransport.handle_request(self, request) 220 req = httpcore.Request( 221 method=request.method, 222 url=httpcore.URL( (...) 230 extensions=request.extensions, 231 ) --> 232 with map_httpcore_exceptions(): 233 resp = self._pool.handle_request(req)
File ~/miniconda3/lib/python3.12/contextlib.py:158, in _GeneratorContextManager.exit(self, typ, value, traceback) 157 try: --> 158 self.gen.throw(value) 159 except StopIteration as exc: 160 # Suppress StopIteration unless it's the same exception that 161 # was passed to throw(). This prevents a StopIteration 162 # raised inside the "with" statement from being suppressed.
File ~/miniconda3/lib/python3.12/site-packages/httpx/_transports/default.py:86, in map_httpcore_exceptions() 85 message = str(exc) ---> 86 raise mapped_exc(message) from exc
ConnectError: [Errno 99] Cannot assign requested address
The above exception was the direct cause of the following exception:
APIConnectionError Traceback (most recent call last) Cell In[8], line 2 1 # Takes 10 min without GPU / 1 min with GPU on Google collab ----> 2 index = MultiModalVectorStoreIndex.from_documents( 3 text_docs + all_images, storage_context=storage_context, image_vector_store=image_store 4 )
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/base.py:106, in BaseIndex.from_documents(cls, documents, storage_context, service_context, show_progress, kwargs) 97 docstore.set_document_hash(doc.get_doc_id(), doc.hash) 99 nodes = run_transformations( 100 documents, # type: ignore 101 service_context.transformations, 102 show_progress=show_progress, 103 kwargs, 104 ) --> 106 return cls( 107 nodes=nodes, 108 storage_context=storage_context, 109 service_context=service_context, 110 show_progress=show_progress, 111 **kwargs, 112 )
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/multi_modal/base.py:80, in MultiModalVectorStoreIndex.init(self, nodes, index_struct, service_context, storage_context, use_async, store_nodes_override, show_progress, image_vector_store, image_embed_model, is_image_to_text, kwargs) 76 storage_context.add_vector_store(SimpleVectorStore(), self.image_namespace) 78 self._image_vector_store = storage_context.vector_stores[self.image_namespace] ---> 80 super().init( 81 nodes=nodes, 82 index_struct=index_struct, 83 service_context=service_context, 84 storage_context=storage_context, 85 show_progress=show_progress, 86 use_async=use_async, 87 store_nodes_override=store_nodes_override, 88 kwargs, 89 )
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/vector_store/base.py:49, in VectorStoreIndex.init(self, nodes, index_struct, service_context, storage_context, use_async, store_nodes_override, show_progress, kwargs) 47 self._use_async = use_async 48 self._store_nodes_override = store_nodes_override ---> 49 super().init( 50 nodes=nodes, 51 index_struct=index_struct, 52 service_context=service_context, 53 storage_context=storage_context, 54 show_progress=show_progress, 55 kwargs, 56 )
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/base.py:71, in BaseIndex.init(self, nodes, index_struct, storage_context, service_context, show_progress, **kwargs) 69 if index_struct is None: 70 assert nodes is not None ---> 71 index_struct = self.build_index_from_nodes(nodes) 72 self._index_struct = index_struct 73 self._storage_context.index_store.add_index_struct(self._index_struct)
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/vector_store/base.py:255, in VectorStoreIndex.build_index_from_nodes(self, nodes, insert_kwargs) 244 def build_index_from_nodes( 245 self, 246 nodes: Sequence[BaseNode], 247 insert_kwargs: Any, 248 ) -> IndexDict: 249 """Build the index from nodes. 250 251 NOTE: Overrides BaseIndex.build_index_from_nodes. 252 VectorStoreIndex only stores nodes in document store 253 if vector store does not store text 254 """ --> 255 return self._build_index_from_nodes(nodes, **insert_kwargs)
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/vector_store/base.py:236, in VectorStoreIndex._build_index_from_nodes(self, nodes, insert_kwargs) 234 run_async_tasks(tasks) 235 else: --> 236 self._add_nodes_to_index( 237 index_struct, 238 nodes, 239 show_progress=self._show_progress, 240 insert_kwargs, 241 ) 242 return index_struct
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/multi_modal/base.py:327, in MultiModalVectorStoreIndex._add_nodes_to_index(self, index_struct, nodes, show_progress, insert_kwargs) 324 text_nodes.append(node) 326 # embed all nodes as text - incclude image nodes that have text attached --> 327 text_nodes = self._get_node_with_embedding( 328 text_nodes, show_progress, is_image=False 329 ) 330 new_text_ids = self.storage_context.vector_stores[DEFAULT_VECTOR_STORE].add( 331 text_nodes, insert_kwargs 332 ) 334 # embed image nodes as images directly 335 # check if we should use text embedding for images instead of default
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/multi_modal/base.py:182, in MultiModalVectorStoreIndex._get_node_with_embedding(self, nodes, show_progress, is_image) 179 self._image_embed_model = self._service_context.embed_model 181 else: --> 182 id_to_embed_map = embed_nodes( 183 nodes, 184 embed_model=self._service_context.embed_model, 185 show_progress=show_progress, 186 ) 188 results = [] 189 for node in nodes:
File ~/miniconda3/lib/python3.12/site-packages/llama_index/indices/utils.py:137, in embed_nodes(nodes, embed_model, show_progress) 134 else: 135 id_to_embed_map[node.node_id] = node.embedding --> 137 new_embeddings = embed_model.get_text_embedding_batch( 138 texts_to_embed, show_progress=show_progress 139 ) 141 for new_id, text_embedding in zip(ids_to_embed, new_embeddings): 142 id_to_embed_map[new_id] = text_embedding
File ~/miniconda3/lib/python3.12/site-packages/llama_index/embeddings/base.py:256, in BaseEmbedding.get_text_embedding_batch(self, texts, show_progress, **kwargs) 250 if idx == len(texts) - 1 or len(cur_batch) == self.embed_batch_size: 251 # flush 252 with self.callback_manager.event( 253 CBEventType.EMBEDDING, 254 payload={EventPayload.SERIALIZED: self.to_dict()}, 255 ) as event: --> 256 embeddings = self._get_text_embeddings(cur_batch) 257 result_embeddings.extend(embeddings) 258 event.on_end( 259 payload={ 260 EventPayload.CHUNKS: cur_batch, 261 EventPayload.EMBEDDINGS: embeddings, 262 }, 263 )
File ~/miniconda3/lib/python3.12/site-packages/llama_index/embeddings/openai.py:385, in OpenAIEmbedding._get_text_embeddings(self, texts) 378 """Get text embeddings. 379 380 By default, this is a wrapper around _get_text_embedding. 381 Can be overridden for batch queries. 382 383 """ 384 client = self._get_client() --> 385 return get_embeddings( 386 client, 387 texts, 388 engine=self._text_engine, 389 **self.additional_kwargs, 390 )
File ~/miniconda3/lib/python3.12/site-packages/tenacity/init.py:336, in BaseRetrying.wraps..wrapped_f(*args, *kw)
334 copy = self.copy()
335 wrapped_f.statistics = copy.statistics # type: ignore[attr-defined]
--> 336 return copy(f, args, **kw)
File ~/miniconda3/lib/python3.12/site-packages/tenacity/init.py:475, in Retrying.call(self, fn, *args, **kwargs) 473 retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs) 474 while True: --> 475 do = self.iter(retry_state=retry_state) 476 if isinstance(do, DoAttempt): 477 try:
File ~/miniconda3/lib/python3.12/site-packages/tenacity/init.py:376, in BaseRetrying.iter(self, retry_state) 374 result = None 375 for action in self.iter_state.actions: --> 376 result = action(retry_state) 377 return result
File ~/miniconda3/lib/python3.12/site-packages/tenacity/init.py:418, in BaseRetrying._post_stop_check_actions..exc_check(rs)
416 retry_exc = self.retry_error_cls(fut)
417 if self.reraise:
--> 418 raise retry_exc.reraise()
419 raise retry_exc from fut.exception()
File ~/miniconda3/lib/python3.12/site-packages/tenacity/init.py:185, in RetryError.reraise(self) 183 def reraise(self) -> t.NoReturn: 184 if self.last_attempt.failed: --> 185 raise self.last_attempt.result() 186 raise self
File ~/miniconda3/lib/python3.12/concurrent/futures/_base.py:449, in Future.result(self, timeout) 447 raise CancelledError() 448 elif self._state == FINISHED: --> 449 return self.__get_result() 451 self._condition.wait(timeout) 453 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
File ~/miniconda3/lib/python3.12/concurrent/futures/_base.py:401, in Future.__get_result(self) 399 if self._exception: 400 try: --> 401 raise self._exception 402 finally: 403 # Break a reference cycle with the exception in self._exception 404 self = None
File ~/miniconda3/lib/python3.12/site-packages/tenacity/init.py:478, in Retrying.call(self, fn, *args, *kwargs) 476 if isinstance(do, DoAttempt): 477 try: --> 478 result = fn(args, **kwargs) 479 except BaseException: # noqa: B902 480 retry_state.set_exception(sys.exc_info()) # type: ignore[arg-type]
File ~/miniconda3/lib/python3.12/site-packages/llama_index/embeddings/openai.py:162, in get_embeddings(client, list_of_text, engine, kwargs) 158 assert len(list_of_text) <= 2048, "The batch size should not be larger than 2048." 160 list_of_text = [text.replace("\n", " ") for text in list_of_text] --> 162 data = client.embeddings.create(input=list_of_text, model=engine, kwargs).data 163 return [d.embedding for d in data]
File ~/miniconda3/lib/python3.12/site-packages/openai/resources/embeddings.py:114, in Embeddings.create(self, input, model, dimensions, encoding_format, user, extra_headers, extra_query, extra_body, timeout) 108 embedding.embedding = np.frombuffer( # type: ignore[no-untyped-call] 109 base64.b64decode(data), dtype="float32" 110 ).tolist() 112 return obj --> 114 return self._post( 115 "/embeddings", 116 body=maybe_transform(params, embedding_create_params.EmbeddingCreateParams), 117 options=make_request_options( 118 extra_headers=extra_headers, 119 extra_query=extra_query, 120 extra_body=extra_body, 121 timeout=timeout, 122 post_parser=parser, 123 ), 124 cast_to=CreateEmbeddingResponse, 125 )
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1266, in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls) 1252 def post( 1253 self, 1254 path: str, (...) 1261 stream_cls: type[_StreamT] | None = None, 1262 ) -> ResponseT | _StreamT: 1263 opts = FinalRequestOptions.construct( 1264 method="post", url=path, json_data=body, files=to_httpx_files(files), **options 1265 ) -> 1266 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:942, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls) 933 def request( 934 self, 935 cast_to: Type[ResponseT], (...) 940 stream_cls: type[_StreamT] | None = None, 941 ) -> ResponseT | _StreamT: --> 942 return self._request( 943 cast_to=cast_to, 944 options=options, 945 stream=stream, 946 stream_cls=stream_cls, 947 remaining_retries=remaining_retries, 948 )
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1002, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 999 log.debug("Encountered Exception", exc_info=True) 1001 if retries > 0: -> 1002 return self._retry_request( 1003 input_options, 1004 cast_to, 1005 retries, 1006 stream=stream, 1007 stream_cls=stream_cls, 1008 response_headers=None, 1009 ) 1011 log.debug("Raising connection error") 1012 raise APIConnectionError(request=request) from err
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1079, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls) 1075 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a 1076 # different thread if necessary. 1077 time.sleep(timeout) -> 1079 return self._request( 1080 options=options, 1081 cast_to=cast_to, 1082 remaining_retries=remaining, 1083 stream=stream, 1084 stream_cls=stream_cls, 1085 )
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1002, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 999 log.debug("Encountered Exception", exc_info=True) 1001 if retries > 0: -> 1002 return self._retry_request( 1003 input_options, 1004 cast_to, 1005 retries, 1006 stream=stream, 1007 stream_cls=stream_cls, 1008 response_headers=None, 1009 ) 1011 log.debug("Raising connection error") 1012 raise APIConnectionError(request=request) from err
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1079, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls) 1075 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a 1076 # different thread if necessary. 1077 time.sleep(timeout) -> 1079 return self._request( 1080 options=options, 1081 cast_to=cast_to, 1082 remaining_retries=remaining, 1083 stream=stream, 1084 stream_cls=stream_cls, 1085 )
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1002, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 999 log.debug("Encountered Exception", exc_info=True) 1001 if retries > 0: -> 1002 return self._retry_request( 1003 input_options, 1004 cast_to, 1005 retries, 1006 stream=stream, 1007 stream_cls=stream_cls, 1008 response_headers=None, 1009 ) 1011 log.debug("Raising connection error") 1012 raise APIConnectionError(request=request) from err
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1079, in SyncAPIClient._retry_request(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls) 1075 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a 1076 # different thread if necessary. 1077 time.sleep(timeout) -> 1079 return self._request( 1080 options=options, 1081 cast_to=cast_to, 1082 remaining_retries=remaining, 1083 stream=stream, 1084 stream_cls=stream_cls, 1085 )
File ~/miniconda3/lib/python3.12/site-packages/openai/_base_client.py:1012, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 1002 return self._retry_request( 1003 input_options, 1004 cast_to, (...) 1008 response_headers=None, 1009 ) 1011 log.debug("Raising connection error") -> 1012 raise APIConnectionError(request=request) from err 1014 log.debug( 1015 'HTTP Response: %s %s "%i %s" %s', 1016 request.method, (...) 1020 response.headers, 1021 ) 1022 log.debug("request_id: %s", response.headers.get("x-request-id"))
APIConnectionError: Connection error.