Spaces:
Running
Running
File size: 1,430 Bytes
43e17ed 4d61f97 43e17ed 4d61f97 43e17ed 2cfae81 4d61f97 0678516 43e17ed 4d61f97 43e17ed 0678516 4d61f97 43e17ed 4d61f97 0678516 4d61f97 43e17ed 0678516 4d61f97 7fafb5b 0678516 43e17ed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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() |