Learn how to create and use Reference Queries to teach camelAI your business metrics and SQL patterns
Reference Queries are pre-defined SQL queries that teach camelAI how to calculate your business metrics correctly. They serve as building blocks that camelAI can reference, adapt, and combine to answer complex questions about your data.
Reference Queries are SQL queries stored in a vectorized database that camelAI searches when processing user questions. Unlike the Knowledge Base which stores textual context, Reference Queries provide actual SQL implementations of your business logic.
Comments in your SQL queries are included when we vectorize them, improving search accuracy:
Copy
Ask AI
-- Title: "Monthly Recurring Revenue (MRR)"SELECT DATE_TRUNC('month', subscription_date) as month, -- Convert all subscription types to monthly equivalent SUM(CASE WHEN billing_period = 'monthly' THEN amount WHEN billing_period = 'yearly' THEN amount / 12 END) as mrrFROM subscriptionsWHERE status = 'active' -- Only active subscriptions count toward MRRGROUP BY 1;
The comments help camelAI understand not just what the query does, but why certain logic is applied.
Show camelAI how your tables relate through example queries:
Copy
Ask AI
-- Title: "Customer Order Summary"SELECT c.email, COUNT(o.order_id) as order_count, SUM(o.total) as lifetime_valueFROM customers cJOIN orders o ON c.customer_id = o.customer_idWHERE o.status = 'completed'GROUP BY c.email;
Capture complex business rules in your reference queries:
Copy
Ask AI
-- Title: "Active Users"-- Active = logged in within 30 days AND has valid subscriptionSELECT COUNT(DISTINCT user_id) as active_usersFROM usersWHERE last_login >= CURRENT_DATE - 30 AND subscription_status = 'active';
Titles of queries are optional fields, but we strongly recommend creating a descriptive, to the point title. It strongly improves RAG performance.
Use language your users will use to ask questions.
Example: If your dashboard shows “Customer Acquisition Cost”, title your reference query exactly that way, not “CAC Calculation” or “Marketing Efficiency Query”.Good Titles: