Skip to content

fix(llm): improve rag demo error handling#335

Merged
imbajin merged 8 commits into
apache:mainfrom
zxuexingzhijie:fix/hugegraph-ai-rag-runtime-errors
May 20, 2026
Merged

fix(llm): improve rag demo error handling#335
imbajin merged 8 commits into
apache:mainfrom
zxuexingzhijie:fix/hugegraph-ai-rag-runtime-errors

Conversation

@zxuexingzhijie
Copy link
Copy Markdown
Contributor

@zxuexingzhijie zxuexingzhijie commented May 18, 2026

Summary

  • Make RAG demo auto-reload opt-in through HG_DEV_RELOAD instead of enabling reload by default.
  • Improve LLM error handling so LiteLLM/OpenAI runtime failures surface consistently instead of being silently converted to ordinary result strings.
  • Update Ollama async embeddings to use the batch embed(input=...) API and validate malformed embedding responses.
  • Make graph summary fetching handle HugeGraph Gremlin response shapes more defensively while preserving real execution failures.
  • Clarify HugeGraph schema and HTTP error messages so callers receive more actionable failures.

Change-Id: I1658c1a7aefe353f48be4d48c7d4425aded13a3d

Change-Id: I1658c1a7aefe353f48be4d48c7d4425aded13a3d
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 18, 2026
@imbajin imbajin requested a review from Copilot May 19, 2026 05:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Change-Id: I275a618f6b6a43448c40d91fc6e4667084d26f4f
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这轮主要有几处错误处理会导致运行时结果被静默改写或解析错误

Comment thread hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/fetch_graph_data.py Outdated
Comment thread hugegraph-python-client/src/pyhugegraph/utils/util.py Outdated
Comment thread hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/fetch_graph_data.py Outdated
Change-Id: I65b37b72baea21e2cf2cf2c471ff14c56869520e
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Comment thread hugegraph-python-client/src/pyhugegraph/utils/util.py Outdated
Comment on lines +25 to +38
def test_response_validation_raises_http_error_with_numeric_status_body():
response = Mock(spec=requests.Response)
response.status_code = 400
response.text = '{"status":400,"message":"bad gremlin"}'
response.content = response.text.encode("utf-8")
response.json.return_value = {"status": 400, "message": "bad gremlin"}
response.request = Mock()
response.request.body = "g.V2()"
response.raise_for_status.side_effect = requests.exceptions.HTTPError("400 Client Error")

validator = ResponseValidation()

with pytest.raises(Exception, match="bad gremlin"):
validator(response, "POST", "/gremlin")
Comment on lines +63 to +66
except RequestException as e:
raise ValueError(f"Failed to connect HugeGraph to get schema '{self.graph_name}': {e}") from e
if not schema["vertexlabels"] and not schema["edgelabels"]:
raise Exception(f"Can not get {self.graph_name}'s schema from HugeGraph!")
raise ValueError(f"Can not get {self.graph_name}'s schema from HugeGraph!")
Comment on lines 74 to 108
log.info("Token usage: %s", response.usage)
return response.choices[0].message.content
except (RateLimitError, BudgetExceededError, APIError) as e:
log.error("Error in LiteLLM call: %s", e)
return f"Error: {str(e)}"
raise

@retry(
stop=stop_after_attempt(2),
wait=wait_exponential(multiplier=1, min=2, max=5),
retry=retry_if_exception_type((RateLimitError, BudgetExceededError, APIError)),
)
async def agenerate(
self,
messages: Optional[List[Dict[str, Any]]] = None,
prompt: Optional[str] = None,
) -> str:
"""Generate a response to the query messages/prompt asynchronously."""
if messages is None:
assert prompt is not None, "Messages or prompt must be provided."
messages = [{"role": "user", "content": prompt}]
try:
response = await acompletion(
model=self.model,
messages=messages,
temperature=self.temperature,
max_tokens=self.max_tokens,
api_key=self.api_key,
base_url=self.api_base,
)
log.info("Token usage: %s", response.usage)
return response.choices[0].message.content
except (RateLimitError, BudgetExceededError, APIError) as e:
log.error("Error in async LiteLLM call: %s", e)
return f"Error: {str(e)}"
raise

Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本轮整体方向正确,但 base_node 的 catch-all 与 schema_build 的 raise 相互抵消、ollama/litellm/openai 的契约改动缺少测试覆盖,建议先收敛错误处理边界并补齐回归测试再合入。

Comment thread hugegraph-llm/src/hugegraph_llm/nodes/base_node.py Outdated
Comment thread hugegraph-llm/src/hugegraph_llm/nodes/base_node.py Outdated
Comment thread hugegraph-llm/src/hugegraph_llm/models/embeddings/ollama.py
Comment thread hugegraph-llm/src/hugegraph_llm/models/llms/litellm.py
Comment thread hugegraph-llm/src/hugegraph_llm/models/llms/openai.py Outdated
Comment thread hugegraph-python-client/src/pyhugegraph/utils/util.py
Comment thread hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py Outdated
Comment thread hugegraph-python-client/src/tests/api/test_response_validation.py
zxuexingzhijie and others added 2 commits May 20, 2026 13:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Change-Id: I939ca3a2df3ecc55471f9b98155b5ab03fa43d03
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 20, 2026
Change-Id: Ib8bb730fb9c28e4b3e0a05e72d531544d0f623a9
Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI 已恢复,主要阻塞问题已解决。下面还剩两处非阻塞的测试/维护性建议

Comment thread hugegraph-llm/src/hugegraph_llm/models/embeddings/ollama.py
Comment thread hugegraph-llm/src/tests/models/llms/test_litellm_client.py Outdated
Change-Id: I815753ca0350e6b5f734937973eca956d9ef422a
@zxuexingzhijie
Copy link
Copy Markdown
Contributor Author

done

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 20, 2026
@imbajin imbajin merged commit 2df0b6e into apache:main May 20, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer llm python-client size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants