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 lines143144145146147148149150151152142 unmodified lines"realtime_context": None,"news_chunks": [],"historical_chunks": [],"fundamental_data": None,"sector_context": None,"fused_context": "","response": "","citations": [],"confidence_score": 0.0,"disclaimer_text": "",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 lines596061626364656667686970717258 unmodified linesrewritten_query = _rewrite_query(query)loop = asyncio.get_running_loop()result = await loop.run_in_executor(None,run_rag_branch,rewritten_query,ticker,_BRANCH,)chunks = [{58 unmodified lines596061626364656667686970717273747576777879808158 unmodified linesrewritten_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,)except Exception as exc:log.warning("filings_rag_failed", ticker=ticker, error=str(exc))return _emptychunks = [{
26 unmodified lines27282930313233343536373839404142434426 unmodified lines"""Retrieve pre-ingested financial statement chunks from Qdrant finora_financials.Works for ALL stocks (US + Indian) — no ticker skip needed."""query = state["query"]ticker = state.get("ticker", "")loop = asyncio.get_running_loop()result = await loop.run_in_executor(None,run_rag_branch,query,ticker,_BRANCH,)chunks = [{26 unmodified lines2728293031323334353637383940414243444546474849505152535426 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,)except Exception as exc:log.warning("financials_rag_failed", ticker=ticker, error=str(exc))return _emptychunks = [{
38 unmodified lines3940414243444546474849507 unmodified lines5859606162636438 unmodified lineslive_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)# Qdrant chunks — supplementary historical/older contextqdrant_chunks = [{"text": ch.text, "score": ch.score, **ch.metadata}for ch in result.chunks]# Deduplicate: drop Qdrant chunks whose title appears in live headlines7 unmodified lines# Qdrant supplementary secondchunks = list(live_news) + qdrant_chunksscores = result.retrieval_scoreslog.info("news_rag_done",ticker=ticker,38 unmodified lines394041424344454647484950515253545556575859607 unmodified lines6869707172737438 unmodified lineslive_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)# return_exceptions=True: Qdrant RAG failure must not cancel the live RSS tasklive_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 contextqdrant_chunks = [{"text": ch.text, "score": ch.score, **ch.metadata}for ch in (rag_result.chunks if rag_result else [])]# Deduplicate: drop Qdrant chunks whose title appears in live headlines7 unmodified lines# Qdrant supplementary secondchunks = list(live_news) + qdrant_chunksscores = 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