damccorm commented on code in PR #41690:
URL: https://github.com/apache/beam/pull/41690#discussion_r4744097209


##########
sdks/python/apache_beam/ml/rag/enrichment/bigquery_vector_search.py:
##########
@@ -185,11 +186,19 @@ def _format_restrict(self, item: EmbeddableItem) -> str:
   def format_query(self, items: list[EmbeddableItem]) -> str:
     """Format the vector search query template."""
     base_columns_str = ", ".join(f"base.{col}" for col in self.columns)
-    columns_str = ", ".join(self.columns)
+    select_columns = list(self.columns)
+    if self.embedding_column not in select_columns:

Review Comment:
   Nit: BigQuery column identifiers are case-insensitive (and callers 
occasionally backtick-quote entries in `columns`), so `columns=['content', 
'Embedding']` or ``['content', '`embedding`']`` with 
`embedding_column='embedding'` would still emit a duplicate column in the 
subquery. Normalizing with `col.strip().strip('`').lower()` for the membership 
check would catch those too.



##########
sdks/python/apache_beam/ml/rag/enrichment/bigquery_vector_search.py:
##########
@@ -185,11 +186,19 @@ def _format_restrict(self, item: EmbeddableItem) -> str:
   def format_query(self, items: list[EmbeddableItem]) -> str:
     """Format the vector search query template."""
     base_columns_str = ", ".join(f"base.{col}" for col in self.columns)
-    columns_str = ", ".join(self.columns)
+    select_columns = list(self.columns)
+    if self.embedding_column not in select_columns:
+      select_columns.append(self.embedding_column)
+    select_columns_str = ", ".join(select_columns)
     distance_clause = (
         f", distance_type => '{self.distance_type}'"
         if self.distance_type else "")
-    options_clause = (f", options => {self.options}" if self.options else "")
+    if self.options:
+      escaped_options = (
+          json.dumps(self.options).replace("\\", "\\\\").replace("'", "\\'"))

Review Comment:
   Optional nit: passing `allow_nan=False` to `json.dumps(...)` fails fast in 
Python on `NaN`/`Infinity` floats instead of emitting non-standard JSON for 
BigQuery to reject.



-- 
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]

Reply via email to