Skip to content

Commit 9c12120

Browse files
authored
chore: add cookbook section to AI documentation flow (#531)
1 parent f769356 commit 9c12120

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

e2e/questdb

Submodule questdb updated 297 files

src/components/AIStatusIndicator/AssistantModes.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@ export const AssistantModes: React.FC<AssistantModesProps> = ({
412412
{item.name}
413413
</CodeBadgeText>
414414
</CodeBadge>
415-
<ReasoningTextPart>
416-
documentation
417-
</ReasoningTextPart>
418415
</>
419416
) : (
420417
<>
@@ -426,9 +423,6 @@ export const AssistantModes: React.FC<AssistantModesProps> = ({
426423
{item.name}
427424
</CodeBadgeText>
428425
</CodeBadge>
429-
<ReasoningTextPart>
430-
documentation
431-
</ReasoningTextPart>
432426
</>
433427
)}
434428
</ReasoningText>

src/utils/aiAssistant.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,14 @@ const REFERENCE_TOOLS = [
294294
properties: {
295295
category: {
296296
type: "string" as const,
297-
enum: ["functions", "operators", "sql", "concepts", "schema"],
297+
enum: [
298+
"functions",
299+
"operators",
300+
"sql",
301+
"concepts",
302+
"schema",
303+
"cookbook",
304+
],
298305
description: "The category of documentation to retrieve",
299306
},
300307
items: {
@@ -434,9 +441,12 @@ export function createModelToolsClient(
434441
}
435442

436443
const DOCS_INSTRUCTION_ANTHROPIC = `
437-
CRITICAL: Always follow this two-phase documentation approach:
438-
1. Use get_questdb_toc to see available functions/keywords/operators
439-
2. Use get_questdb_documentation to get details for specific items you'll use`
444+
CRITICAL: Always follow this documentation approach:
445+
1. Use get_questdb_toc to see available functions, operators, SQL syntax, AND cookbook recipes
446+
2. If user's request matches a cookbook recipe description, fetch it FIRST - recipes provide complete, tested SQL patterns
447+
3. Use get_questdb_documentation for specific function/syntax details
448+
449+
When a cookbook recipe matches the user's intent, ALWAYS use it as the foundation and adapt column/table names and use case to their schema.`
440450

441451
const getUnifiedPrompt = (grantSchemaAccess?: boolean) => {
442452
const base = `You are a SQL expert assistant specializing in QuestDB, a high-performance time-series database. You help users with:

src/utils/questdbDocsRetrieval.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type DocCategory =
44
| "sql"
55
| "concepts"
66
| "schema"
7+
| "cookbook"
78

89
export type ParsedDocItem = {
910
name: string
@@ -19,15 +20,17 @@ export function parseDocItem(item: string): ParsedDocItem | null {
1920
return null
2021
}
2122

22-
const parts = item.split(/\s+-\s+/)
23+
const itemWithoutDesc = item.split(" :: ")[0].trim()
24+
25+
const parts = itemWithoutDesc.split(/\s+-\s+/)
2326
if (parts.length >= 2) {
2427
return {
2528
name: parts[0].trim(),
2629
section: parts.slice(1).join(" - ").trim(),
2730
}
2831
}
2932

30-
return { name: item.trim() }
33+
return { name: itemWithoutDesc }
3134
}
3235

3336
/**
@@ -104,7 +107,14 @@ export async function getQuestDBTableOfContents(): Promise<string> {
104107
// Schema
105108
if (toc.schema) {
106109
result += "## Schema\n"
107-
result += toc.schema.join(", ") + "\n"
110+
result += toc.schema.join(", ") + "\n\n"
111+
}
112+
113+
if (toc.cookbook) {
114+
result += "## Cookbook SQL Recipes (Complete Working Examples)\n"
115+
result +=
116+
"These pages provide tested, production-ready SQL. When user's request matches a recipe, use it as the foundation and adapt column/table names and use case to their schema.\n\n"
117+
result += toc.cookbook.join("\n") + "\n"
108118
}
109119

110120
return result

0 commit comments

Comments
 (0)