-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R-306] Frequent openai.APIConnectionError when running testset generator #1512
Comments
@Twist333d Hello! I'm here to help you with your bug and questions. Let's squash those bugs together and get your code running smoothly. I found a similar closed issue that might be relevant to your problem: ragas evaluate asking for OPENAI_API_KEY when using locally hosted Langchain TGI LLM. The issue was resolved by using Regarding your specific issue with frequent To address the connection errors, you might want to ensure that the retry logic is correctly configured in your setup. You can customize the from ragas.run_config import RunConfig
custom_config = RunConfig(
timeout=120, # Adjust the timeout as needed
max_retries=15, # Increase the number of retries
max_wait=90, # Adjust the maximum wait time
log_tenacity=True # Enable logging for retry attempts
) You can then use this |
@dosu - I am not sure the suggestion is correct - I see that default number of re-tries is set to 10 and I am not changing the default run_config. |
The default configuration for the retry mechanism in the Ragas library indeed sets the number of retries ( from ragas.run_config import RunConfig
custom_config = RunConfig(
timeout=120, # Adjust the timeout as needed
max_retries=15, # Increase the number of retries
max_wait=90, # Adjust the maximum wait time
log_tenacity=True # Enable logging for retry attempts
) This configuration can help improve the handling of intermittent connection issues by allowing more retry attempts and adjusting the wait times between retries. |
@dosu - I think what needs to be done to address the root cause is to identify why these connection errors are happening? Ragas should be handling the timeout errors gracefully and inform users about what should be done in this cases |
I can not generate a single testset because of this error. Another error trace
|
To identify the root cause of frequent To improve Ragas to handle timeout errors gracefully and inform users about necessary actions, you can modify the @silent
def track(event_properties: BaseEvent):
if do_not_track():
return
payload = dict(event_properties)
if _usage_event_debugging():
# For internal debugging purpose
logger.info("Tracking Payload: %s", payload)
return
try:
requests.post(USAGE_TRACKING_URL, json=payload, timeout=USAGE_REQUESTS_TIMEOUT_SEC)
except requests.exceptions.Timeout:
logger.error("Request to %s timed out. Please check your network connection or try again later.", USAGE_TRACKING_URL) This modification will log an error message when a timeout occurs, informing the user to check their network connection or try again later, thus handling the timeout errors gracefully [1]. |
@Twist333d let me take a look at this. Like you said we should and do have retry mech but not sure why it's not working here |
I have experienced the exact same issue as @Twist333d. I am experiencing the same error and similar traceback which is why I am not posting any code. I am attempting connection to Azure OpenAI. Searched the entire documentation, and the source code and with no luck. I thought it was a problem with authenticating my user to the Azure service, but figured it was a Ragas issue, because the exact same code works inside a Jupyter Notebook in the exact same environment as the failing .py script. In the Jupyter Notebook, I was able to authenticate my user, and run the code, resulting in a successfully generated TestSet. For whatever reason, running the exact same script as a .py file in my terminal results in an API connection error. |
If that helps - the source code is here https://github.com/Twist333d/omni-claude/blob/setup-rag-eval-az-24/src/evaluation/evaluation.py. I double checked that I correctly call the main function (even though the trace mentions the event loop) |
See #1526 |
ohh got it - that was why I was not able to reproduce this with #1563 thanks a lot @hunter-walden2113 🙌🏽 @alexander-zuev do check it out - we'll merge this soon btw I also had a deep down guide into testset that also make setting these explicit https://docs.ragas.io/en/latest/getstarted/rag_testset_generation/#a-deeper-look |
Addresses the "no embeddings found" and "API Connection error" issues. Specifically issues: [1546](#1546), [1526](#1526), [1512](#1512), [1496](#1496) Users have reported that they cannot generate a Testset because they get API connection errors, or their knowledge graph does not have the embeddings. This is due to the use of the default LLMs and Embedding models via llm_factory and embedding_factory. The errors are occuring becuase the users do not have OpenAI credentials in their environment because they are using different models in their workflow. Issue to solve is to prevent the default_transforms function from using the llm_factory by forcing the user to add both an embedding model and llm model when instantiating TestsetGenerator. 1. Added `embedding_model` as an attribute to `TestsetGenerator`. 2. Added `embedding_model: LangchainEmbeddings` as a parameter to `TestsetGenerator.from_langchain` 3. Changed the return from `TestsetGenerator.from_langchain` to `return cls(LangchainLLMWrapper(llm), LangchainEmbeddingsWrapper(embedding_model), knowledge_graph)` 4. Added both an `llm` and `embedding_model` parameter to `TestsetGenerator.generate_with_langchain_docs`
closing this now |
[X] I have checked the documentation and related resources and couldn't resolve my bug. Yes, there are no recommendations on how to fix the api connection errors, especially since you are using wrappers (langchain / llamaindex)
Describe the bug
A clear and concise description of what the bug is.
In short - there are frequent, intermittent APIConnectionErrors when running testset generator. Error trace doesn't give out specific enough reasons or ways to troubleshoot.
I would expect in such cases the library to re-try the connection and not just fail the generation wasting all of the tokens/embeddings
Ragas version: 0.2.0
Python version: 3.12.6
Code to Reproduce
Sharing the evaluation module code
Error trace
R-306
The text was updated successfully, but these errors were encountered: