Spaces:
Running
Running
| | |
| # CONTEXT BUILDER - ./core/context_builder.py | |
| from core.rag.rag_jung import retrieve | |
| from core.tools.web_search import web_search | |
| def should_use_web(query): | |
| trigger_words = ["what is", "who is", "define", "meaning", "latest"] | |
| return any(w in query.lower() for w in trigger_words) | |
| def build_context(agent, query): | |
| # ----------------------------- | |
| # RAG CONTEXT | |
| # ----------------------------- | |
| #rag_context = retrieve(query) | |
| rag_context = retrieve(query, k=3) | |
| #rag_context = retrieve(user_input, k=3) | |
| #print(f"{agent.upper()} RAG: \n{rag_context}") | |
| # ----------------------------- | |
| # WEB CONTEXT (only if needed) | |
| # ----------------------------- | |
| web_context = "" | |
| if should_use_web(query) or len(rag_context.strip()) < 50: | |
| print(f"🌐 Using web fallback...") | |
| #web_context = web_search(query) or "" | |
| web_context = web_search(query) | |
| #print(f"{agent.upper()} WEB: \n{web_context}") | |
| # ----------------------------- | |
| # COMBINED CONTEXT | |
| # ----------------------------- | |
| combined = f""" | |
| {agent.upper()} RAG: | |
| {rag_context} | |
| {agent.upper()} WEB: | |
| {web_context} | |
| """ | |
| print(f"{agent.upper()} RAG: \n{rag_context}") | |
| print(f"{agent.upper()} WEB: \n{web_context}") | |
| print(f"COMBINED - RAG+WEB - CONTEXT: \n{combined.strip()}") | |
| return combined.strip() |