Overview
Query your local RAG index first. If the result is stale (older than threshold) or confidence is low, fall back to a live search API for fresh data. Combines local speed with API freshness.
Trigger
On user query
Schedule
On-demand (per query)
Workflow Steps
Query local vector store
Search local embeddings for the user query.
Check freshness and confidence
If top result is older than 7 days or similarity score is below 0.7, mark as stale.
Fall back to search API
If stale, query live search API for fresh results.
Merge and rank
Combine local and API results, deduplicate, rank by relevance.
Python Implementation
import requests, os
from datetime import datetime, timedelta
H = {"x-api-key": os.environ["SCAVIO_API_KEY"]}
FRESHNESS_DAYS = 7
def hybrid_search(query, local_results):
# Check if local results are fresh enough
now = datetime.now()
fresh_local = [r for r in local_results
if (now - r.get("indexed_at", now)).days < FRESHNESS_DAYS
and r.get("score", 0) > 0.7]
if fresh_local:
return {"source": "local", "results": fresh_local}
# Fallback to live API
data = requests.post("https://api.scavio.dev/api/v1/search",
headers=H, json={"platform": "google", "query": query}).json()
api_results = [{"title": r["title"], "url": r["link"], "snippet": r.get("snippet", "")}
for r in data.get("organic_results", [])[:5]]
return {"source": "api_fallback", "results": api_results}JavaScript Implementation
const search = async (query, localResults) => {
const fresh = localResults.filter(r => r.score > 0.7 && r.daysOld < 7);
if (fresh.length > 0) return {source: "local", results: fresh};
const r = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST", headers: {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"},
body: JSON.stringify({platform: "google", query})
});
return {source: "api", results: (await r.json()).organic_results?.slice(0, 5)};
};Platforms Used
Web search with knowledge graph, PAA, and AI overviews