Spaces:
Sleeping
Sleeping
Charan S commited on
Commit ·
e1a0142
1
Parent(s): 45994d6
fix: stabilize RAG pipeline and prevent hard failures in retrieval nodes
Browse filesFiles changed (4)
142 unmodified lines143144145146147148149150151152153154155142 unmodified lines "realtime_context": None, "news_chunks": [], "historical_chunks": [], "filings_chunks": [], "financials_chunks": [], "fundamental_data": None, "sector_context": None, "fused_context": "", "response": "", "followup_questions": [], "citations": [], "confidence_score": 0.0, "disclaimer_text": "",58 unmodified lines5960616263646566676263646566676869686970717273747576777879808158 unmodified lines
rewritten_query = _rewrite_query(query)
_empty = { "filings_chunks": [], "retrieval_scores": {**state.get("retrieval_scores", {}), "filings": {}}, }
try: loop = asyncio.get_running_loop() result = await loop.run_in_executor( None, run_rag_branch, rewritten_query, ticker, _BRANCH, ) loop = asyncio.get_running_loop() result = await loop.run_in_executor( None, run_rag_branch, rewritten_query, ticker, _BRANCH, ) except Exception as exc: log.warning("filings_rag_failed", ticker=ticker, error=str(exc)) return _empty
chunks = [ {26 unmodified lines27282930313233343536373839403435363738394041414243444546474849505152535426 unmodified lines """ Retrieve pre-ingested financial statement chunks from Qdrant finora_financials. Works for ALL stocks (US + Indian) — no ticker skip needed. Silently returns empty if the collection doesn't exist yet (not ingested). """ query = state["query"] ticker = state.get("ticker", "")
_empty = { "financials_chunks": [], "retrieval_scores": {**state.get("retrieval_scores", {}), "financials": {}}, }
try: loop = asyncio.get_running_loop() result = await loop.run_in_executor( None, run_rag_branch, query, ticker, _BRANCH, ) loop = asyncio.get_running_loop() result = await loop.run_in_executor( None, run_rag_branch, query, ticker, _BRANCH, ) except Exception as exc: log.warning("financials_rag_failed", ticker=ticker, error=str(exc)) return _empty
chunks = [ {38 unmodified lines3940414242434445464748495051525354555647575859607 unmodified lines686970617172737438 unmodified lines live_task = loop.run_in_executor(None, fetch_news, yf_ticker or ticker, _LIVE_COUNT) rag_task = loop.run_in_executor(None, run_rag_branch, query, ticker, _BRANCH)
live_news, result = await asyncio.gather(live_task, rag_task) # return_exceptions=True: Qdrant RAG failure must not cancel the live RSS task live_news_raw, rag_result = await asyncio.gather(live_task, rag_task, return_exceptions=True)
if isinstance(live_news_raw, Exception): log.warning("news_live_rss_failed", ticker=ticker, error=str(live_news_raw)) live_news_raw = [] live_news: list[dict] = live_news_raw # type: ignore[assignment]
if isinstance(rag_result, Exception): log.warning("news_qdrant_rag_failed", ticker=ticker, error=str(rag_result)) rag_result = None
# Qdrant chunks — supplementary historical/older context qdrant_chunks = [ {"text": ch.text, "score": ch.score, **ch.metadata} for ch in result.chunks for ch in (rag_result.chunks if rag_result else []) ]
# Deduplicate: drop Qdrant chunks whose title appears in live headlines7 unmodified lines # Qdrant supplementary second chunks = list(live_news) + qdrant_chunks
scores = result.retrieval_scores scores = rag_result.retrieval_scores if rag_result else {} log.info( "news_rag_done", ticker=ticker,backend/api/routes/chat.py+3
backend/graph/nodes/filings_rag_node.py+17-8
backend/graph/nodes/financials_rag_node.py+18-8
backend/graph/nodes/news_rag_node.py+13-3