shunping commented on code in PR #41886:
URL: https://github.com/apache/beam/pull/41886#discussion_r4779393399


##########
sdks/python/apache_beam/ml/rag/enrichment/bigquery_vector_search.py:
##########
@@ -218,26 +301,28 @@ def format_query(self, items: list[EmbeddableItem]) -> 
str:
         ));
     """ if self.metadata_restriction_template else ""
 
-    # Group items by their metadata conditions
+    # Group items by their metadata conditions. Each item is identified in the
+    # query by its position in ``items`` so that results can be mapped back
+    # to the originating item, even when several items share the same id.
     condition_groups = defaultdict(list)
     if self.metadata_restriction_template:
-      for item in items:
+      for idx, item in enumerate(items):
         condition = self._format_restrict(item)
-        condition_groups[condition].append(item)
+        condition_groups[condition].append((idx, item))
     else:
       # No metadata filtering - all items in one group
-      condition_groups[""] = items
+      condition_groups[""] = list(enumerate(items))
 
     # Generate VECTOR_SEARCH subqueries for each condition group
     vector_searches = []
     for condition, group_items in condition_groups.items():
       # Create embeddings subquery for this group
       embedding_unions = []
-      for item in group_items:
+      for idx, item in group_items:
         if not item.dense_embedding:
           raise ValueError(f"Item {item.id} missing embedding")
         embedding_str = (
-            f"SELECT '{item.id}' as id, "
+            f"SELECT {idx} as idx, "
             f"{[float(x) for x in item.dense_embedding]} "

Review Comment:
   Embedding validation is outside the scope of this change; leaving as is.



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