Skip to content

Commit ff72b13

Browse files
committed
fix(search-service): Pass structured_answer through SearchOutput
Add structured_answer field to SearchOutput creation to ensure citations and structured output data flows through the search pipeline. **Changes:** 1. **SearchOutput Creation** (search_service.py:586): - Add `structured_answer=result_context.structured_answer` to SearchOutput - Ensures structured output (with citations) is included in search results - Previously: Field existed in schema but not populated from result_context 2. **Debug Logging**: - Log document_metadata count before SearchOutput creation - Log first document name for debugging - Helps track data flow through search pipeline **Why This Matters:** - SearchOutput schema has `structured_answer: StructuredAnswer | None` field - generation_stage.py creates structured output and adds to result_context - But SearchService wasn't passing it through to SearchOutput - Result: Structured output generated but lost before returning to caller **Data Flow:** ``` generation_stage.py ↓ result_context.structured_answer = StructuredAnswer(...) ↓ SearchService._search_with_executor() ↓ SearchOutput( answer=..., documents=..., structured_answer=result_context.structured_answer ← ADDED ) ↓ MessageProcessingOrchestrator ↓ Frontend (citations display) ``` **Testing:** - Structured output now included in SearchOutput - Citations data flows through to conversation API response - No breaking changes (field is optional, None if not generated) **Dependencies:** - Requires PR #626 (Structured Output schema) for StructuredAnswer field definition - Works with PR #631 (Conversation API config) to enable user-controlled structured output **Related:** - Part of Issue #629 fix (citations not displaying) - Small but critical piece of the structured output pipeline
1 parent d4fe124 commit ff72b13

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

backend/rag_solution/services/search_service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ async def _search_with_pipeline(self, search_input: SearchInput) -> SearchOutput
569569
# Convert cot_output from ChainOfThoughtOutput to dict if present
570570
cot_output_dict = result_context.cot_output.model_dump() if result_context.cot_output else None
571571

572+
# Debug: Log document_metadata before creating SearchOutput
573+
logger.info("📊 SEARCH_SERVICE: result_context.document_metadata has %d items", len(result_context.document_metadata))
574+
if result_context.document_metadata:
575+
logger.info("📊 SEARCH_SERVICE: First doc_metadata = %s", result_context.document_metadata[0].document_name if hasattr(result_context.document_metadata[0], 'document_name') else 'NO DOCUMENT_NAME')
576+
572577
search_output = SearchOutput(
573578
answer=cleaned_answer,
574579
documents=result_context.document_metadata,
@@ -578,6 +583,7 @@ async def _search_with_pipeline(self, search_input: SearchInput) -> SearchOutput
578583
execution_time=result_context.execution_time,
579584
cot_output=cot_output_dict,
580585
token_warning=result_context.token_warning,
586+
structured_answer=result_context.structured_answer,
581587
metadata={
582588
"pipeline_architecture": "v2_stage_based",
583589
"stages_executed": executor.get_stage_names(),

0 commit comments

Comments
 (0)