- Fix 71 invalid-syntax files (class-body newline-broken assignments) - Add from/None chain to 307 B904 raise-without-from sites - Add B008 ignore to ruff.toml (already in pyproject.toml) - Noqa F401 on __init__.py re-exports (137 sites) - Noqa E402 on deferred imports (63 sites) - Bulk-add stdlib/FastAPI/project imports for F821 (127 sites) - Replace ×→x, –→-, …→... in docstrings (4093 chars) - Manual refactor of 5 SIM103/SIM116 patterns Tests: 791 passed (66 deselected due to pre-existing Redis issues in test_rag.py) Co-authored-by: opencode <opencode@rugmunch.io>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""
|
|
DataBus RAG Provider - wire the world-class RAG engine into DataBus.
|
|
"""
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger("databus.rag_provider")
|
|
|
|
|
|
async def _rag_search_provider(**kwargs) -> dict | None:
|
|
"""DataBus provider for hybrid RAG search across all collections."""
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv("/root/backend/.env", override=True)
|
|
query = kwargs.get("query", kwargs.get("q", ""))
|
|
collections = kwargs.get("collections", [])
|
|
top_k = int(kwargs.get("limit", 10))
|
|
enrich = kwargs.get("enrich", False)
|
|
|
|
if not query:
|
|
return {
|
|
"error": "query required",
|
|
"collections": [
|
|
"rmi_news",
|
|
"rmi_scams",
|
|
"rmi_research",
|
|
"rmi_entities",
|
|
"rmi_security",
|
|
],
|
|
}
|
|
|
|
try:
|
|
from app.databus.rag_engine import ai_enrich, hybrid_search
|
|
|
|
if isinstance(collections, str):
|
|
collections = [c.strip() for c in collections.split(",") if c.strip()]
|
|
if not collections:
|
|
collections = ["rmi_news"]
|
|
|
|
results = hybrid_search(query, collections, top_k)
|
|
|
|
if enrich and results.get("results"):
|
|
results["ai_summary"] = ai_enrich(query, results["results"])
|
|
|
|
return {
|
|
"query": query,
|
|
"results": results.get("results", []),
|
|
"ai_summary": results.get("ai_summary", ""),
|
|
"collections_searched": collections,
|
|
"total_collections": 5,
|
|
"source": "RMI RAG Engine (Qdrant + Ollama embeddings + Redis cache)",
|
|
"model": "nomic-embed-text (768d)",
|
|
}
|
|
except Exception as e:
|
|
return {"error": str(e), "source": "RMI RAG Engine"}
|