Skip to content

Commit 91f8a8c

Browse files
committed
#3670 updating documentation
Adding examples, testing, making column names consistent. Working on #3670.
1 parent 92c3fed commit 91f8a8c

1 file changed

Lines changed: 39 additions & 36 deletions

File tree

Documentation/Using_AI.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,30 @@ CREATE TABLE dbo.Blitz_AI_Prompts
4747
(Id INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
4848
PromptNickname NVARCHAR(200),
4949
AI_System_Prompt NVARCHAR(4000),
50-
DefaultPrompt BIT DEFAULT 0);
50+
Default_Prompt BIT DEFAULT 0);
5151

52-
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, DefaultPrompt, AI_System_Prompt)
53-
VALUES ('sp_BlitzCache Default', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment.
52+
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, Default_Prompt, AI_System_Prompt)
53+
VALUES ('sp_BlitzCache Default', 1, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment.
5454
5555
You have a query that isn''t performing to end user expectations. You have been tasked with making serious improvements to it, quickly. You are not allowed to change server-level settings or make frivolous suggestions like updating statistics. Instead, you need to focus on query changes or index changes.
5656
5757
Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.');
5858

59-
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, DefaultPrompt, AI_System_Prompt)
59+
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, Default_Prompt, AI_System_Prompt)
6060
VALUES ('sp_BlitzCache Index Tuning', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment.
6161
6262
You have a query that isn''t performing to end user expectations. You have been tasked with making serious improvements to it, quickly, but you are only allowed to make index changes. You are not allowed to make changes to the query, server-level settings, database settings, etc.
6363
6464
Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.');
6565

66-
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, DefaultPrompt, AI_System_Prompt)
66+
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, Default_Prompt, AI_System_Prompt)
6767
VALUES ('sp_BlitzCache Deadlock Tuning', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment.
6868
6969
You have a query that is experiencing deadlocks and blocking. You have been tasked with making serious improvements to it, quickly. You are not allowed to change server-level or database-level settings nor make frivolous suggestions like updating statistics. Instead, you need to focus on query changes or index changes that will reduce blocking and deadlocks.
7070
7171
Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.');
7272

73-
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, DefaultPrompt, AI_System_Prompt)
73+
INSERT INTO dbo.Blitz_AI_Prompts (PromptNickname, Default_Prompt, AI_System_Prompt)
7474
VALUES ('sp_BlitzCache Modernize', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment.
7575
7676
You have been given a legacy query that needs to be modernized. Our goals are to make the query run faster, make it easier to understand, easier to maintain, and to take advantage of new features up to and including SQL Server 2025. You have been tasked with making serious improvements to it, quickly, without touching server-level settings, database-level settings, indexes, or statistics.
@@ -183,24 +183,35 @@ You can create configuration tables to store AI provider settings and prompt tem
183183

184184
```sql
185185
CREATE TABLE dbo.Blitz_AI_Providers
186-
(Id INT PRIMARY KEY CLUSTERED,
186+
(Id INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
187+
Model_Nickname NVARCHAR(200),
187188
AI_Model NVARCHAR(100),
188189
AI_URL NVARCHAR(500),
189190
AI_Database_Scoped_Credential_Name NVARCHAR(500),
190191
AI_Parameters NVARCHAR(4000),
191192
Payload_Template NVARCHAR(4000),
192193
Timeout_Seconds TINYINT,
193194
Context INT,
194-
DefaultModel BIT DEFAULT 0);
195-
196-
/* OpenAI example: */
197-
INSERT INTO dbo.Blitz_AI_Providers (Id, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, DefaultModel)
198-
VALUES (1, N'gpt-5-nano', N'https://api.openai.com/v1/chat/completions',
199-
N'https://api.openai.com/', 230, 1);
200-
201-
/* Gemini example: */
202-
INSERT INTO dbo.Blitz_AI_Providers (Id, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, DefaultModel)
203-
VALUES (2, N'gemini-2.5-flash', N'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent',
195+
Default_Model BIT DEFAULT 0);
196+
197+
/* OpenAI - fast, cheap model, default: */
198+
INSERT INTO dbo.Blitz_AI_Providers (Model_Nickname, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, DefaultModel)
199+
VALUES (N'ChatGPT Fast', N'gpt-5-nano', N'https://api.openai.com/v1/chat/completions',
200+
N'https://api.openai.com/', 30, 1);
201+
202+
/* OpenAI - highest quality, slowest, most expensive model: */
203+
INSERT INTO dbo.Blitz_AI_Providers (Model_Nickname, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, DefaultModel)
204+
VALUES (N'ChatGPT Slow', N'gpt-5.4', N'https://api.openai.com/v1/chat/completions',
205+
N'https://api.openai.com/', 230, 0);
206+
207+
/* Gemini - fast, cheap model: */
208+
INSERT INTO dbo.Blitz_AI_Providers (Model_Nickname, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, DefaultModel)
209+
VALUES (N'Gemini Fast', N'gemini-3-flash-preview', N'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent',
210+
N'https://generativelanguage.googleapis.com/', 30, 0);
211+
212+
/* Gemini - highest quality, slowest, most expensive model: */
213+
INSERT INTO dbo.Blitz_AI_Providers (Model_Nickname, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, DefaultModel)
214+
VALUES (N'Gemini Slow', N'gemini-3-1-pro-preview', N'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent',
204215
N'https://generativelanguage.googleapis.com/', 230, 0);
205216
```
206217

@@ -237,13 +248,14 @@ EXEC sp_BlitzCache @Top = 1, @AI = 1,
237248
/* Use a specific model from your config table */
238249
EXEC sp_BlitzCache @Top = 1, @AI = 1,
239250
@AIConfigTable = 'master.dbo.Blitz_AI_Providers',
240-
@AIModel = 'gemini-2.5-flash';
251+
@AIModel = 'ChatGPT Slow';
241252

242-
/* Use a custom prompt from your prompts table */
253+
/* Use a specific model AND prompt */
243254
EXEC sp_BlitzCache @Top = 1, @AI = 1,
244255
@AIConfigTable = 'master.dbo.Blitz_AI_Providers',
256+
@AIModel = 'ChatGPT Slow';
245257
@AIPromptConfigTable = 'master.dbo.Blitz_AI_Prompts',
246-
@AIPrompt = 'index_focused';
258+
@AIPrompt = 'sp_BlitzCache Deadlock Tuning';
247259
```
248260

249261
### sp_BlitzCache AI Parameters
@@ -273,7 +285,7 @@ With `@AI = 2`, only the **AI Prompt** column is included in the result set.
273285

274286
Once credentials are set up, sp_BlitzIndex can call the AI API directly and return index recommendations. This only works in single-table mode (when `@TableName` is specified).
275287

276-
### Quick Start with OpenAI
288+
To just run it with the default ChatGPT model:
277289

278290
```sql
279291
EXEC sp_BlitzIndex
@@ -283,27 +295,18 @@ EXEC sp_BlitzIndex
283295
@AI = 1;
284296
```
285297

286-
### Using Google Gemini
298+
Using the configuration tables works basically the same as the sp_BlitzCache examples above:
287299

288300
```sql
289301
EXEC sp_BlitzIndex
290302
@DatabaseName = 'YourDatabase',
291303
@SchemaName = 'dbo',
292304
@TableName = 'YourTable',
293-
@AI = 1,
294-
@AIModel = N'gemini-2.5-flash',
295-
@AIURL = N'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent';
296-
```
297-
298-
### Using Configuration Tables
299-
300-
```sql
301-
EXEC sp_BlitzIndex
302-
@DatabaseName = 'YourDatabase',
303-
@SchemaName = 'dbo',
304-
@TableName = 'YourTable',
305-
@AI = 1,
306-
@AIConfigTable = 'master.dbo.Blitz_AI_Providers';
305+
@AI = 1,
306+
@AIConfigTable = 'master.dbo.Blitz_AI_Providers',
307+
@AIModel = 'ChatGPT Slow'
308+
@AIPromptConfigTable = 'master.dbo.Blitz_AI_Prompts',
309+
@AIPrompt = 'sp_BlitzIndex OLTP'; /* Or whatever custom prompt you inserted */
307310
```
308311

309312
### sp_BlitzIndex AI Parameters

0 commit comments

Comments
 (0)