Mongodb Vector search with llama_index.llms.openai_utils: APIConnectionError: Connection error

389 views Asked by At

I am trying to do a vector search followed the example in LlamaIndex and when running this following line of code:

# mongo_uri = os.environ["MONGO_URI"]
mongo_uri = (
    "mongodb+srv://<username>:<password>@ai-test.ugfvqq8.mongodb.net?retryWrites=true&w=majority"
)
mongodb_client = pymongo.MongoClient(mongo_uri)
store = MongoDBAtlasVectorSearch(mongodb_client)
storage_context = StorageContext.from_defaults(vector_store=store)
uber_docs = SimpleDirectoryReader(
    input_files=["./data/10k/uber_2021.pdf"]
).load_data()
index = VectorStoreIndex.from_documents(
    uber_docs, storage_context=storage_context
)

I got this error:

WARNING:llama_index.llms.openai_utils:Retrying llama_index.embeddings.openai.get_embeddings in 0.02318287802497976 seconds as it raised APIConnectionError: Connection error..
---------------------------------------------------------------------------
LocalProtocolError                        Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/httpcore/_exceptions.py in map_exceptions(map)
      9     try:
---> 10         yield
     11     except Exception as exc:  # noqa: PIE786

294 frames
/usr/local/lib/python3.10/dist-packages/httpcore/_sync/http11.py in _send_request_headers(self, request)
    141         with map_exceptions({h11.LocalProtocolError: LocalProtocolError}):
--> 142             event = h11.Request(
    143                 method=request.method,

/usr/local/lib/python3.10/dist-packages/h11/_events.py in __init__(self, method, headers, target, http_version, _parsed)
     95             object.__setattr__(
---> 96                 self, "headers",     normalize_and_validate(headers, _parsed=_parsed)
     97             )

/usr/local/lib/python3.10/dist-packages/h11/_headers.py in   normalize_and_validate(headers, _parsed)
    163             validate(_field_name_re, name, "Illegal header name {!r}", name)
--> 164             validate(_field_value_re, value, "Illegal header value {!r}", value)
    165         assert isinstance(name, bytes)

/usr/local/lib/python3.10/dist-packages/h11/_util.py in validate(regex, data, msg, *format_args)
     90             msg = msg.format(*format_args)
---> 91         raise LocalProtocolError(msg)
     92     return match.groupdict()

LocalProtocolError: Illegal header value b'Bearer '

I have also allowed my mongodb network access to be 0.0.0.0/0 but it seems like I am still facing this issue.

anyone have any solution to this? Thank you in advance

1

There are 1 answers

0
Ping Kee Ng On

I figured that it could be a lama-index issue. So I swapped over to use LangChain Vector store here. Working well.

Note: each vector search and generation of text with Llama2-7b-chat-hf model took me 2 mins on google Collab free tier.