Add fallback error handling for LLM synthesis with TextNode attribute issues

Wrap synthesizer.synthesize() in try-catch to handle AttributeError gracefully
and fall back to returning raw documents when LLM synthesis fails.

This allows the chat feature to work even when there are Pydantic or llama-index
compatibility issues with TextNode attributes.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bob Roberts 2025-10-27 20:12:57 -05:00
parent 0d8d6d7bb8
commit 11d47c4067

View file

@ -314,13 +314,18 @@ class RAGEngine:
"sources": []
}
# Synthesize answer using LLM
synthesizer = get_response_synthesizer()
response = synthesizer.synthesize(question, nodes=filtered_nodes)
try:
# Synthesize answer using LLM
synthesizer = get_response_synthesizer()
response = synthesizer.synthesize(question, nodes=filtered_nodes)
logger.info(f"Generated answer: {str(response)[:200]}")
logger.info(f"Generated answer: {str(response)[:200]}")
return self._format_response(response, filtered_nodes)
return self._format_response(response, filtered_nodes)
except AttributeError as e:
logger.error(f"Attribute error during synthesis: {e}")
# Fallback: return documents without LLM synthesis
return self._format_response(f"Retrieved {len(filtered_nodes)} relevant documents", filtered_nodes)
def _format_response(self, response, source_nodes) -> Dict[str, any]:
"""Format query response for return."""