Solution

Local RAG with Search API Fallback

RAG applications that only search a local document index cannot answer questions outside their corpus. Users ask about current events, competitor information, or topics not covered

The Problem

RAG applications that only search a local document index cannot answer questions outside their corpus. Users ask about current events, competitor information, or topics not covered in the indexed documents, and the system either hallucinates from the LLM's training data or returns 'I don't know.' Both responses are unsatisfying and push users back to manual search.

The Scavio Solution

Implement a hybrid retrieval strategy: search the local index first, and if the top result's relevance score is below a threshold, fall back to Scavio's search API for live web results. The local index handles known-domain queries with high accuracy and zero latency cost. The search API handles everything else with current web data. Merge both result sets into the LLM's context with clear source labels so the model can attribute its answer correctly.

Before

Before the hybrid approach, a company knowledge bot could only answer questions about internal docs. When a customer asked 'how does your pricing compare to Competitor X,' the bot either hallucinated a comparison or said it could not help. Users learned not to trust the bot for anything beyond basic FAQ lookups.

After

After adding search API fallback, the bot first checks internal docs. If the local search confidence is low, it queries Scavio for the competitor's current pricing page and generates an accurate comparison. Users now trust the bot for both internal and external questions, and usage increased 3x.

Who It Is For

Developers building RAG applications that need to answer questions beyond their local document corpus without hallucinating or refusing.

Key Benefits

  • Local-first search keeps most queries fast and free
  • Search API fallback covers questions outside the corpus
  • Relevance threshold prevents unnecessary API calls
  • Source labels in context enable accurate attribution
  • Graceful degradation instead of hallucination or refusal

Python Example

Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
CONFIDENCE_THRESHOLD = 0.7

def hybrid_retrieve(query: str, local_index) -> dict:
    # Search local index first
    local_results = local_index.search(query, top_k=3)
    if local_results and local_results[0].score >= CONFIDENCE_THRESHOLD:
        return {'source': 'local', 'results': [r.text for r in local_results]}
    # Fallback to Scavio
    resp = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'google', 'query': query}, timeout=10)
    web_results = resp.json().get('organic', [])[:3]
    return {'source': 'web', 'results': [f"{r['title']}: {r['snippet']}" for r in web_results]}

# Use in RAG pipeline:
# context = hybrid_retrieve(user_question, my_meilisearch_index)
# prompt = f"Source: {context['source']}\n{chr(10).join(context['results'])}\nQuestion: {user_question}"

JavaScript Example

JavaScript
const CONFIDENCE_THRESHOLD = 0.7;

async function hybridRetrieve(query, localIndex) {
  const localResults = await localIndex.search(query, { limit: 3 });
  if (localResults.hits?.length && localResults.hits[0]._rankingScore >= CONFIDENCE_THRESHOLD) {
    return { source: 'local', results: localResults.hits.map(h => h.content) };
  }
  const resp = 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 })
  });
  const data = await resp.json();
  return { source: 'web', results: (data.organic || []).slice(0, 3).map(r => `${r.title}: ${r.snippet}`) };
}

Platforms Used

Google

Web search with knowledge graph, PAA, and AI overviews

Reddit

Community, posts & threaded comments from any subreddit

YouTube

Video search with transcripts and metadata

Frequently Asked Questions

RAG applications that only search a local document index cannot answer questions outside their corpus. Users ask about current events, competitor information, or topics not covered in the indexed documents, and the system either hallucinates from the LLM's training data or returns 'I don't know.' Both responses are unsatisfying and push users back to manual search.

Implement a hybrid retrieval strategy: search the local index first, and if the top result's relevance score is below a threshold, fall back to Scavio's search API for live web results. The local index handles known-domain queries with high accuracy and zero latency cost. The search API handles everything else with current web data. Merge both result sets into the LLM's context with clear source labels so the model can attribute its answer correctly.

Developers building RAG applications that need to answer questions beyond their local document corpus without hallucinating or refusing.

Yes. Scavio's free tier includes 500 credits per month with no credit card required. That is enough to validate this solution in your workflow.

Local RAG with Search API Fallback

Implement a hybrid retrieval strategy: search the local index first, and if the top result's relevance score is below a threshold, fall back to Scavio's search API for live web res