Skip to content

Commit f6f7355

Browse files
diberryCopilot
andcommitted
fix: round 2 review - SQL safety, precomputed, em dashes, gitignore
- SQL: use N'' prefix for Unicode string in sys.tables lookup - SQL: add vector dimensions comment for text-embedding-3-small - SQL: add timeout/retry rationale comments on OpenAI client - sample.env: move inline comment to separate line - README: pre-computed -> precomputed (6 instances) - README: fix em dash spacing (7 instances) - .gitignore: expand parent gitignore with .env.*, dist/, build/, logs, OS files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fe28b52 commit f6f7355

4 files changed

Lines changed: 35 additions & 17 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1+
# Environment files
12
.env
3+
.env.*
4+
!.env.sample
5+
!.env.example
6+
7+
# Dependencies
28
node_modules/
9+
10+
# Build artifacts
11+
dist/
12+
build/
13+
14+
# Logs
15+
*.log
16+
npm-debug.log*
17+
18+
# OS files
19+
.DS_Store
20+
Thumbs.db

samples/features/vector-search/vector-search-query-typescript/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ This sample demonstrates how to perform **native vector search** in Azure SQL Da
44

55
It uses:
66

7-
- **[tedious](https://www.npmjs.com/package/tedious)**Microsoft's Node.js driver for SQL Server, with Azure AD authentication
8-
- **[openai](https://www.npmjs.com/package/openai)**Azure OpenAI SDK for generating embeddings (via the `AzureOpenAI` class)
9-
- **[@azure/identity](https://www.npmjs.com/package/@azure/identity)**`DefaultAzureCredential` for passwordless authentication to both Azure SQL and Azure OpenAI
7+
- **[tedious](https://www.npmjs.com/package/tedious)**Microsoft's Node.js driver for SQL Server, with Azure AD authentication
8+
- **[openai](https://www.npmjs.com/package/openai)**Azure OpenAI SDK for generating embeddings (via the `AzureOpenAI` class)
9+
- **[@azure/identity](https://www.npmjs.com/package/@azure/identity)**`DefaultAzureCredential` for passwordless authentication to both Azure SQL and Azure OpenAI
1010

1111
## What the sample does
1212

13-
1. Loads 50 hotels with pre-computed embeddings from `data/HotelsData_Vector.json`
13+
1. Loads 50 hotels with precomputed embeddings from `data/HotelsData_Vector.json`
1414
2. Connects to Azure SQL Database using `DefaultAzureCredential` (no passwords or API keys)
1515
3. Creates a table with `id`, `name`, `description`, `category`, `rating`, and a `VECTOR(1536)` column
16-
4. Inserts all 50 hotels with their pre-computed vector embeddings
16+
4. Inserts all 50 hotels with their precomputed vector embeddings
1717
5. Generates a fresh query embedding using Azure OpenAI `text-embedding-3-small`
1818
6. Performs a vector similarity search using either **exact kNN** (`VECTOR_DISTANCE`) or **approximate ANN** (`VECTOR_SEARCH` with DiskANN index), based on the `VECTOR_SEARCH_ALGORITHM` environment variable
1919
7. Displays the top matching results with category, rating, and similarity scores
@@ -109,7 +109,7 @@ This runs the TypeScript code directly using `tsx` with Node.js 20+ native env-f
109109
## Expected output
110110

111111
```
112-
=== Azure SQL Vector SearchTypeScript Quickstart ===
112+
=== Azure SQL Vector SearchTypeScript Quickstart ===
113113
114114
Server: <your-server>.database.windows.net
115115
Database: <your-database>
@@ -126,12 +126,12 @@ Connected.
126126
Creating hotels table (if not exists)...
127127
Table ready.
128128
129-
Inserting hotel data with pre-computed embeddings...
129+
Inserting hotel data with precomputed embeddings...
130130
Inserted 50 hotels.
131131
132132
Searching for: "luxury beachfront hotel with ocean views and spa"
133133
134-
--- Search ResultsExact (kNN) via VECTOR_DISTANCE (Top 3 by Cosine Distance) ---
134+
--- Search ResultsExact (kNN) via VECTOR_DISTANCE (Top 3 by Cosine Distance) ---
135135
136136
Hotel: Ocean Water Resort & Spa
137137
Category: Luxury
@@ -186,9 +186,9 @@ CREATE TABLE dbo.hotels_typescript (
186186
);
187187
```
188188

189-
### Loading pre-computed vectors
189+
### Loading precomputed vectors
190190

191-
Hotel data with pre-computed embeddings is loaded from `data/HotelsData_Vector.json`. This avoids calling Azure OpenAI for each hotel during the main run, making the demo faster and simpler:
191+
Hotel data with precomputed embeddings is loaded from `data/HotelsData_Vector.json`. This avoids calling Azure OpenAI for each hotel during the main run, making the demo faster and simpler:
192192

193193
```typescript
194194
const hotels = JSON.parse(readFileSync(dataPath, "utf-8"));
@@ -295,7 +295,7 @@ az sql server firewall-rule create \
295295

296296
### Vector dimension errors
297297

298-
**"Invalid or missing vector dimensions"**The pre-computed embeddings in `HotelsData_Vector.json` must use 1536 dimensions (matching `text-embedding-3-small`). Re-run `npm run embed` if you changed the embedding model.
298+
**"Invalid or missing vector dimensions"**The precomputed embeddings in `HotelsData_Vector.json` must use 1536 dimensions (matching `text-embedding-3-small`). Re-run `npm run embed` if you changed the embedding model.
299299

300300
## Explore your database
301301

samples/features/vector-search/vector-search-query-typescript/sample.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AZURE_SQL_DATABASE=<your-database>
44
AZURE_SQL_TABLE_NAME=hotels_typescript
55
AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com
66
AZURE_OPENAI_EMBEDDING_DEPLOYMENT=text-embedding-3-small
7-
# Vector search algorithm: "exact" (default, uses VECTOR_DISTANCE) or "diskann" (uses VECTOR_SEARCH with DiskANN index)
8-
VECTOR_SEARCH_ALGORITHM=exact # "exact" (default, uses VECTOR_DISTANCE) or "diskann" (uses VECTOR_SEARCH with DiskANN index)
7+
# Vector search algorithm: "exact" (default, uses VECTOR_DISTANCE) or "diskann" (uses VECTOR_SEARCH with DiskANN index, requires 1000+ rows)
8+
VECTOR_SEARCH_ALGORITHM=exact
99
# Drop table at end of run to clean up artifacts (default: false)
1010
SQL_DROP_TABLE=false

samples/features/vector-search/vector-search-query-typescript/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async function main(): Promise<void> {
186186
console.log(`Loaded ${hotels.length} hotels from data file.\n`);
187187

188188
// Validate vector dimensions for ALL hotels
189-
const VECTOR_DIMENSIONS = 1536;
189+
const VECTOR_DIMENSIONS = 1536; // text-embedding-3-small output dimensions
190190
const badVectors = hotels
191191
.map((h, i) => ({ index: i, id: h.HotelId, dim: h.DescriptionVector?.length }))
192192
.filter((v) => !v.dim || v.dim !== VECTOR_DIMENSIONS);
@@ -236,7 +236,7 @@ async function main(): Promise<void> {
236236
console.log(`Creating table dbo.${tableName} (if not exists)...`);
237237
await executeSql(
238238
conn,
239-
`IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = '${tableName}' AND schema_id = SCHEMA_ID('dbo'))
239+
`IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = N'${tableName}' AND schema_id = SCHEMA_ID('dbo'))
240240
BEGIN
241241
CREATE TABLE dbo.[${tableName}] (
242242
id NVARCHAR(50) PRIMARY KEY,
@@ -298,8 +298,8 @@ async function main(): Promise<void> {
298298
endpoint: config.azureOpenAiEndpoint,
299299
azureADTokenProvider,
300300
apiVersion: "2024-10-21",
301-
timeout: 30_000,
302-
maxRetries: 3,
301+
timeout: 30_000, // 30s timeout for embedding generation
302+
maxRetries: 3, // Retry transient failures
303303
});
304304

305305
let queryEmbeddings: number[][];

0 commit comments

Comments
 (0)