imbajin commented on code in PR #383:
URL: https://github.com/apache/hugegraph-ai/pull/383#discussion_r4283363582


##########
hugegraph-llm/src/hugegraph_llm/nodes/hugegraph_node/graph_query_node.py:
##########
@@ -355,7 +356,7 @@ def _subgraph_query(self, context: Dict[str, Any]) -> 
Dict[str, Any]:
             if not matched_vids:
                 return context
 
-            gremlin_query = VERTEX_QUERY_TPL.format(keywords=matched_vids)
+            gremlin_query = 
VERTEX_QUERY_TPL.format(keywords=",".join(gremlin_str_literal(vid) for vid in 
matched_vids))

Review Comment:
   ⚠️ Important. Blocking: yes. Summary: This formats every matched ID through 
`gremlin_str_literal()`, which calls `str()` and turns numeric vertex IDs into 
string IDs. `FetchGraphData` obtains IDs from `g.V().id().toList()`, and the 
semantic index stores and returns those values unchanged, so a numeric ID such 
as `123` now generates `g.V('123')` instead of `g.V(123)` and can miss the 
vertex. Please preserve numeric IDs as numeric Gremlin literals and 
quote/escape only string IDs. Evidence: the exact-head `FetchGraphData`, 
`BuildSemanticIndex`, and `_fuzzy_match_vids` paths preserve index ID values; 
HugeGraph maps `Number` and `String` IDs to distinct ID types.



##########
hugegraph-llm/src/hugegraph_llm/utils/hugegraph_utils.py:
##########
@@ -34,6 +34,11 @@
 BACKUP_DIR = str(os.path.join(resource_path, "backup-graph-data-4020", 
huge_settings.graph_name))
 
 
+def gremlin_str_literal(value) -> str:
+    """Quote a value as a Groovy single-quoted string literal (no `$` 
interpolation), e.g. 1:O'Brien -> '1:O\\'Brien'."""
+    return "'" + str(value).replace("\\", "\\\\").replace("'", "\\'") + "'"

Review Comment:
   ⚠️ Important. Blocking: no. Summary: Raw newline and other control 
characters are left inside this single-quoted Groovy literal, so a valid string 
ID containing a line break makes the Gremlin script fail to parse. Please 
encode Groovy control characters (including newline and carriage return) before 
quoting and cover them in a regression test. Evidence: this helper only escapes 
backslashes and apostrophes; Groovy single-quoted literals require escape 
sequences such as `\n` and `\r` for those characters.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to