From 11d47c4067a04a59893514609a2bca07168feac3 Mon Sep 17 00:00:00 2001 From: Bob Roberts Date: Mon, 27 Oct 2025 20:12:57 -0500 Subject: [PATCH] Add fallback error handling for LLM synthesis with TextNode attribute issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/core/rag_engine.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/core/rag_engine.py b/app/core/rag_engine.py index eedd3a5..3e9de46 100644 --- a/app/core/rag_engine.py +++ b/app/core/rag_engine.py @@ -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."""