rag query routing api

RAG query routing API for SQL, vector search, and live APIs

Send every incoming RAG query to the exact backend that can answer it—SQL warehouse, dense vector store, live account API, or out-of-scope refusal—in one ~39 ms calibrated pass.

Interactive RAG retrieval source & refusal router
Input state evaluated

Compare total paid API credits consumed by Scale vs Studio accounts over the last 30 days grouped by week.

Primary choice confidence
sql_analytics (96%)
Est. model spend / 1k calls
$0.0036 (~190 tok)
AUTO-ESCALATE · sql_analytics + skip_vector_search P(skip_vector_search) = 0.93
retrieval_source → sql_analytics 96%
curl --fail-with-body https://clef-flash.com/api/v1/decisions \
  -H "authorization: Bearer $CLEF_API_KEY" \
  -H "content-type: application/json" \
  --data-binary @- <<'CLEF_DECISION'
{
  "model": "cloudflare/clef-flash",
  "threshold": 0.84,
  "state": "Compare total paid API credits consumed by Scale vs Studio accounts over the last 30 days grouped by week.",
  "questions": {
    "retrieval_source": {
      "type": "choice",
      "instructions": "Which retrieval backend should answer this user query?",
      "criteria": {
        "sql_analytics": "counts, revenue totals, date-range metrics or cohort filtering",
        "vector_docs": "product manuals, runbooks, policy docs or conceptual how-to guides",
        "live_api_state": "real-time order status, key quota balance or account settings",
        "out_of_scope": "unrelated trivia or request outside product knowledge base"
      }
    },
    "skip_vector_search": {
      "type": "noul",
      "instructions": "Can this query bypass expensive dense vector search and hit a deterministic backend directly?",
      "criteria": {
        "true": "exact SQL aggregation, live account API lookup or out-of-scope refusal",
        "false": "needs semantic document chunk retrieval from the vector store"
      }
    }
  }
}
CLEF_DECISION
Pro API key · $19 / 30 days · no auto-renewal

Ship this in production with a $19 Pro key

2,000 decisions/day, 8 concurrent requests in flight, text + JSON + image states, and an API key emailed in about a minute.

Why naive "embed everything" RAG pipelines answer metric questions wrong

Vector similarity search excels at policies, manuals, and runbooks, yet fails miserably on questions like "Compare Q3 paid credits by plan over the last 30 days" or "How many calls remain on my key today?" Stuffing irrelevant text chunks into a frontier LLM wastes tokens and invites hallucinated math.

Inserting Clef-Flash in front of retrieval routes structured metric questions directly to SQL, account-state questions to deterministic REST endpoints, and conceptual questions to your vector database—while refusing out-of-scope trivia before any expensive model runs.

  • Cuts unnecessary vector DB queries and wasted frontier context tokens by skipping retrieval when unneeded.
  • Zero JSON parsing bugs: always returns one valid retrieval_source plus skip_vector_search probability.
  • Sub-50 ms median model routing keeps end-to-end RAG time-to-first-token snappy.

RAG backend routing matrix

Use calibrated probabilities to trigger hybrid retrieval only when two sources genuinely overlap (low top-choice confidence).

Route LabelQuery PatternDownstream Execution
sql_analyticsCounts, sums, cohorts, date-range comparisonsText-to-SQL or parameterized warehouse query
vector_docsHow-to guides, architecture docs, security policiesDense + BM25 hybrid chunk retrieval
live_api_stateCurrent quota, order status, active API keysDeterministic internal REST / D1 lookup
out_of_scopeUnrelated trivia or unsupported topicsReturn instant polite refusal (0 LLM tokens)

Dynamic hybrid fallback when confidence sits below threshold

Some enterprise queries genuinely span two stores—for instance, "Summarize our SLA policy and tell me if we breached it last week." When you pass threshold: 0.84, Clef-Flash marks needsReview: true whenever probability splits across sql_analytics and vector_docs, giving your orchestrator an exact numeric signal to fan out to both backends in parallel.

Test your own query mixes in the interactive studio above and copy production-ready curl or TypeScript code directly into your retrieval router.

Built for multi-tenant SaaS knowledge bases

Because retrieval route descriptions travel inside every request, multi-tenant platforms can dynamically include only the connectors each workspace has enabled (such as Jira, Snowflake, Notion, or Zendesk) without maintaining separate classifiers per customer.

Frequently asked questions

How should my RAG pipeline handle queries that need both SQL and vector docs?

Read the full probabilities map returned for retrieval_source. Whenever the top choice sits below threshold (or a second source exceeds 0.25), fan out to both backends in parallel.

Does routing with Clef-Flash save money compared to an LLM router?

Yes. Clef-Flash bills upstream input tokens at $0.019/1M with zero prose output tokens, avoiding expensive frontier router calls while skipping unnecessary vector retrieval on out-of-scope or live-API queries.

Can I pass recent conversation history alongside the latest user question?

Yes. Pass the last several turns plus user metadata inside state (up to 24,576 tokens / 100,000 characters on /api/v1/decisions) so follow-up pronouns resolve accurately.

What plan fits a production RAG router?

Pro ($19/30 days) handles 2,000 routed queries/day with 8 concurrent calls; Scale ($79/30 days) scales to 20,000/day and 32 concurrent calls with zero auto-renewal.

Keep reading

Model notes

One short email when a new decision model lands or a benchmark changes. No spam, unsubscribe in one click.