@@ -407,7 +407,7 @@ def _get_token_value(original: str, header: str) -> str | None:
407407 return tools
408408
409409
410- def parse_referenced_documents (
410+ def parse_referenced_documents ( # pylint: disable=too-many-locals
411411 response : Optional [OpenAIResponseObject ],
412412 vector_store_ids : Optional [list [str ]] = None ,
413413 rag_id_mapping : Optional [dict [str , str ]] = None ,
@@ -430,16 +430,17 @@ def parse_referenced_documents(
430430 if response is None or not response .output :
431431 return documents
432432
433- resolved_source = _resolve_single_store_source (
434- vector_store_ids or [], rag_id_mapping or {}
435- )
433+ vs_ids = vector_store_ids or []
434+ id_mapping = rag_id_mapping or {}
436435
437436 for output_item in response .output :
438437 item_type = getattr (output_item , "type" , None )
439438
440439 if item_type == "file_search_call" :
441440 results = getattr (output_item , "results" , []) or []
442441 for result in results :
442+ resolved_source = _resolve_source_for_result (result , vs_ids , id_mapping )
443+
443444 # Handle both object and dict access
444445 if isinstance (result , dict ):
445446 attributes = result .get ("attributes" , {})
@@ -472,26 +473,6 @@ def parse_referenced_documents(
472473 return documents
473474
474475
475- def _resolve_single_store_source (
476- vector_store_ids : list [str ],
477- rag_id_mapping : dict [str , str ],
478- ) -> Optional [str ]:
479- """Resolve source name when there is exactly one vector store.
480-
481- Parameters:
482- vector_store_ids: The vector store IDs used in the query.
483- rag_id_mapping: Mapping from vector_db_id to user-facing rag_id.
484-
485- Returns:
486- The resolved rag_id (or raw store_id as fallback) if exactly one
487- store is used, None otherwise.
488- """
489- if len (vector_store_ids ) == 1 :
490- store_id = vector_store_ids [0 ]
491- return rag_id_mapping .get (store_id , store_id )
492- return None
493-
494-
495476def extract_token_usage (
496477 response : Optional [OpenAIResponseObject ], model_id : str
497478) -> TokenCounter :
0 commit comments