Find answers from the community

Updated 2 months ago

Consistent `Connection Error`s when using Chat Engine w/RAG

I'm hoping I could get some help on my problem.
I've managed to build a chat engine using RAG with a simple directory reader & a PG Vector Store.
When asking questions, in a back and forth way (chat engine style), there's a very strange but consistent behavior.
When I send a first message, I get an answer from OpenAI. But when I send a second message, I run into Connection errors :
Plain Text
INFO:     Loading index from storage...
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"
INFO:     Finished loading index from storage
INFO:llama_index.core.chat_engine.condense_plus_context:Condensed question: <condensed_question>
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"
/.venv/lib/python3.11/site-packages/vecs/collection.py:502: UserWarning: Query does not have a covering index for IndexMeasure.cosine_distance. See Collection.create_index
  warnings.warn(
INFO:     127.0.0.1:59430 - "POST /api/chat/ HTTP/1.1" 200 OK
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
INFO:     127.0.0.1:59442 - "POST /api/chat HTTP/1.1" 307 Temporary Redirect
INFO:     Loading index from storage...
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"
INFO:     Finished loading index from storage
INFO:openai._base_client:Retrying request to /chat/completions in 0.928694 seconds
INFO:openai._base_client:Retrying request to /chat/completions in 1.522838 seconds
INFO:openai._base_client:Retrying request to /chat/completions in 3.389680 seconds
ERROR:root:Error in chat generation: Connection error.
INFO:     127.0.0.1:59442 - "POST /api/chat/ HTTP/1.1" 500 Internal Server Error

It's been very consistent and I don't understand why it happens. A short term solution would be to reboot the server but it's definitely not sustainable...
Would anyone know why?
F
1 comment
I tried building a retry mechanism wrapper:
Plain Text
`
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
async def call_openai_api(
    chat_engine: BaseChatEngine, message: _Message, messages: List[_Message]
):
    try:
        response = await chat_engine.astream_chat(message, messages)
        return response
    except Exception as e:
        print(f"Error in API call: {e}")
        raise


Same errors and same logs came thru.
Add a reply
Sign up and join the conversation on Discord