Skip to content

Refresh vector search samples for March 2026 product behavior - #24

Open
amthomas46 wants to merge 5 commits into
mainfrom
vector-search-improvements
Open

Refresh vector search samples for March 2026 product behavior#24
amthomas46 wants to merge 5 commits into
mainfrom
vector-search-improvements

Conversation

@amthomas46

Copy link
Copy Markdown

Brings the samples in line with the current Azure SQL / SQL Server 2025 vector search behavior (March 2026 update) and swaps the RAG notebook to the first-party mssql-python driver.

Product-behavior updates

  • DiskANN/diskann-quickstart-azure-sql.sql and DiskANN/diskann-quickstart-sql-server-2025.sql

    • Add 90 filler rows so the CREATE VECTOR INDEX step meets the 100-row minimum.
    • Swap the deprecated TOP_N = hint inside VECTOR_SEARCH(...) for the outer TOP (N) WITH APPROXIMATE syntax.
    • Remove the obsolete ALLOW_STALE_VECTOR_INDEX = ON + rebuild-index-after-DML workflow. DML on an indexed table now works, and the graph is maintained asynchronously.
    • Add a sys.dm_db_vector_indexes observation step showing graph_catchup_pending_percent.
  • DiskANN/diskann-quickstart-azure-sql-improvements.sql

    • Rename approximate_staleness_percentgraph_catchup_pending_percent (actual DMV column name).
    • Add the neighbouring quantized_keys_used_percent, last_background_task_* counters.
    • Swap the plain DROP EXTERNAL MODEL IF EXISTS for a guarded IF EXISTS (SELECT 1 FROM sys.external_models …) DROP — avoids a syntax error on some builds.
    • Fix a couple of comment-line typos that were confusing -- for -.
  • DiskANN/Wikipedia/006-fulltext-setup.sql: clearer note on full-text population timing on Hyperscale.

  • DiskANN/Wikipedia/008-semantic-reranking.sql and Semantic-Reranking/02-rerank.sql

    • Cohere Foundry deployment names cannot contain a dot, so Cohere-rerank-v4.0-fastCohere-rerank-v4-0-fast.
    • Trim the rerank payload to top 5 documents with LEFT([text], 150) so we stay inside the Cohere GlobalStandard SKU's ~1000 tokens/min frontend cap.
  • DiskANN/Wikipedia/009-wikipedia-fp16.sql: idempotent DDL (skip if the fp16 column / indexes already exist), cleaner formatting, expanded prereq notes.

Driver + binding fix

  • Hybrid-Search/hybrid_search.py: CAST(? AS VECTOR(384)) alone fails because the ODBC driver binds Python strings as ntext, and SQL Server won't coerce ntext directly into VECTOR. Fix is the double cast: CAST(CAST(? AS NVARCHAR(MAX)) AS VECTOR(384)).

mssql-python driver migration in the RAG notebook

  • RAG-with-Documents/RAG-with-resumes.ipynb: replaces pyodbc + manual Entra token struct with the first-party mssql-python driver, using authentication='ActiveDirectoryDefault'. Same functionality; no ODBC driver install required; native Entra ID support with no token juggling. Also applies the double-CAST fix to the INSERT and VECTOR_DISTANCE queries so they work with the new driver.
  • RAG-with-Documents/requirements.txt: pyodbcmssql-python.
  • RAG-with-Documents/.env.sample: drop the ODBC-specific Driver={ODBC Driver 18…} and LongAsMax=yes bits from the sample connection strings.
  • RAG-with-Documents/Readme.md: one-word swap in the library-list sentence.

New sample

  • DiskANN/FineFoodReviews/ — end-to-end hybrid search over the Amazon Fine Food Reviews dataset (already shipped in Datasets/finefoodembeddings.csv).
    • 000-setup.sql — table + external model + optional external table for CSV load.
    • 001-load-and-embed.sql — load 500 rows and embed with AI_GENERATE_EMBEDDINGS.
    • 002-diskann-and-fulltext.sql — build the DiskANN vector index + full-text catalog/index on combined.
    • 003-hybrid-search.sql — vector-only, full-text-only, and hybrid-RRF queries side by side.
    • README.md + Python helpers for a client-side CSV load path.
    • Top-level README.md picks up one paragraph under #### DiskANN and Hybrid Search linking to it.

Housekeeping

  • .gitignore: add .DS_Store and a local session-prep folder (VSLive2026/).

Testing

Validated against Azure SQL Hyperscale on a throwaway pr_test_vector_search database (dropped after):

Test Result
diskann-quickstart-azure-sql.sql end-to-end (10 batches) ✅ 10/10
diskann-quickstart-sql-server-2025.sql end-to-end (11 batches) ✅ 10/11 (USE <db>; skipped — Azure SQL limitation, works on SQL Server 2025)
diskann-quickstart-azure-sql-improvements.sql on a DB with the AI model set up (29 batches) ✅ 24/29 (5 cascade failures caused by the placeholder credential; users edit <yourendpoint> before running)
RAG-notebook INSERT via mssql-python + double-CAST
RAG-notebook vector_search_sql SELECT via mssql-python + double-CAST
hybrid_search.py VECTOR(384) INSERT + SELECT
Wikipedia + Semantic-Reranking + FineFoodReviews 002/003 (PARSEONLY) ✅ (no syntax errors from these edits; missing tables are expected in the fresh DB)

- Quickstart scripts (diskann-quickstart-*) updated to the current
  VECTOR_SEARCH ... WITH APPROXIMATE syntax; add filler rows to satisfy the
  100-row CREATE VECTOR INDEX minimum; remove the obsolete
  ALLOW_STALE_VECTOR_INDEX + rebuild-index-after-DML workflow.
- Improvements script: rename approximate_staleness_percent ->
  graph_catchup_pending_percent (actual DMV name in the current build);
  safer IF EXISTS external-model drop; fix two syntax typos.
- Wikipedia/006-fulltext-setup.sql: clearer full-text population timing note.
- Wikipedia/008-semantic-reranking.sql + Semantic-Reranking/02-rerank.sql:
  Cohere Foundry deployment naming (v4.0 -> v4-0, no dots), trim payload
  to top-5 with LEFT(text,150) to fit GlobalStandard 1000 tokens/min cap.
- Wikipedia/009-wikipedia-fp16.sql: idempotent DDL, cleaner rewrite.
- Hybrid-Search/hybrid_search.py: fix CAST(? AS VECTOR) binding bug -
  double CAST(CAST(? AS NVARCHAR(MAX)) AS VECTOR(...)) is required with
  the ODBC driver's ntext binding.
- RAG-with-Documents notebook: switch from pyodbc + manual Entra token
  struct to first-party mssql-python with authentication='ActiveDirectory
  Default'. Companion requirements.txt, .env.sample, Readme.md updates.
- New sample: DiskANN/FineFoodReviews/ - end-to-end hybrid search over
  the Amazon Fine Food Reviews dataset (dataset already shipped in
  Datasets/finefoodembeddings.csv).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the repository’s vector search + hybrid search samples to match March 2026 Azure SQL / SQL Server 2025 behavior (new VECTOR_SEARCH syntax and updated DMVs), migrates the RAG notebook to the first-party mssql-python driver, and adds a new end-to-end Fine Food Reviews hybrid-search sample.

Changes:

  • Refresh DiskANN scripts for current TOP (N) WITH APPROXIMATE syntax and updated sys.dm_db_vector_indexes counters.
  • Migrate RAG notebook/sample config from pyodbc to mssql-python, including the double-CAST(... AS NVARCHAR(MAX)) workaround for VECTOR binding.
  • Add a new DiskANN/FineFoodReviews hybrid-search sample (SQL scripts + helper Python loaders).

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Semantic-Reranking/02-rerank.sql Updates vector-search syntax and trims rerank payload to fit Cohere token budget.
README.md Adds pointer to the new FineFoodReviews hybrid-search sample.
RAG-with-Documents/requirements.txt Swaps pyodbc dependency to mssql-python.
RAG-with-Documents/Readme.md Updates library list to reference mssql-python.
RAG-with-Documents/RAG-with-resumes.ipynb Migrates notebook connection/auth approach to mssql-python and applies double-cast VECTOR workaround.
RAG-with-Documents/.env.sample Updates sample connection strings to remove ODBC-specific fields.
Hybrid-Search/hybrid_search.py Applies double-cast workaround for VECTOR parameter binding with pyodbc.
DiskANN/Wikipedia/009-wikipedia-fp16.sql Makes fp16 experiment script idempotent and updates vector-search syntax.
DiskANN/Wikipedia/008-semantic-reranking.sql Clarifies rerank prereqs, updates deployment name format, trims payload for token budget.
DiskANN/Wikipedia/006-fulltext-setup.sql Clarifies full-text population timing expectations (Hyperscale).
DiskANN/FineFoodReviews/README.md Documents the new Fine Food Reviews hybrid-search scenario and run order.
DiskANN/FineFoodReviews/003-hybrid-search.sql Adds side-by-side vector-only, full-text-only, and hybrid (RRF) queries.
DiskANN/FineFoodReviews/002-diskann-and-fulltext.sql Adds DiskANN index build + full-text catalog/index setup for the sample.
DiskANN/FineFoodReviews/001-load-and-embed.sql Adds sample load + AI_GENERATE_EMBEDDINGS step for 500 rows.
DiskANN/FineFoodReviews/000-setup.sql Creates the reviews table and documents external model + data source setup.
DiskANN/FineFoodReviews/_load-reviews.py Adds a Python helper to client-load CSV rows into dbo.reviews.
DiskANN/FineFoodReviews/_embed-reviews.py Adds a Python helper to batch-embed rows server-side.
DiskANN/diskann-quickstart-sql-server-2025.sql Adds filler rows for 100-row minimum and updates vector-search syntax.
DiskANN/diskann-quickstart-azure-sql.sql Adds filler rows, updates syntax, and replaces stale-index workflow with DMV observation step.
DiskANN/diskann-quickstart-azure-sql-improvements.sql Updates DMV column names and hardens external-model drop logic.
.gitignore Ignores macOS .DS_Store and local session-prep folder.
Comments suppressed due to low confidence (1)

DiskANN/FineFoodReviews/_embed-reviews.py:20

  • The comment says "Set a long command timeout", but SET LOCK_TIMEOUT 60000 only controls how long the session waits on locks (in ms); it does not increase query/command timeout. This is misleading for readers troubleshooting timeouts from AI_GENERATE_EMBEDDINGS.
# Set a long command timeout since AI_GENERATE_EMBEDDINGS is external
cur.execute("SET LOCK_TIMEOUT 60000;")

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DiskANN/FineFoodReviews/002-diskann-and-fulltext.sql
Comment thread DiskANN/FineFoodReviews/_load-reviews.py Outdated
Comment thread DiskANN/FineFoodReviews/_embed-reviews.py Outdated
Comment thread RAG-with-Documents/RAG-with-resumes.ipynb Outdated
Comment thread DiskANN/diskann-quickstart-azure-sql.sql
Comment thread DiskANN/diskann-quickstart-sql-server-2025.sql
- FineFoodReviews/000-setup.sql + 002-diskann-and-fulltext.sql: name the
  primary-key constraint explicitly (PK_reviews) so the fulltext KEY INDEX
  binding is deterministic. Avoids the auto-generated PK__reviews__<hex>
  name that would otherwise fail on any fresh database.
- FineFoodReviews/_load-reviews.py + _embed-reviews.py: replace hard-coded
  server/database/CSV path with MSSQL_SERVER / MSSQL_DATABASE / REVIEWS_CSV
  env vars (with safe placeholder + repo-relative defaults). No more
  developer-specific paths in the sample.
- FineFoodReviews/_embed-reviews.py: clarify SET LOCK_TIMEOUT comment — it
  is a lock-wait cap, not a query/command timeout.
- diskann-quickstart-azure-sql.sql + -sql-server-2025.sql: replace
  culture-sensitive FORMAT(..., 'N3') filler-vector formatting with
  CONVERT(varchar(5), CAST(x AS decimal(4,3))). Locale-invariant "."
  decimal separator, so the JSON-to-VECTOR cast is safe on any collation.
- RAG-with-Documents/RAG-with-resumes.ipynb: clear all executed cell
  outputs and execution counts to shrink the diff and avoid checking in
  local run content (1754 -> 841 lines).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

Comment thread RAG-with-Documents/RAG-with-resumes.ipynb Outdated
Comment thread DiskANN/FineFoodReviews/_load-reviews.py Outdated
- RAG-with-resumes.ipynb: generate_completion() was treating each row of
  search_results as a single scalar (filename = result, chunkid = result,
  etc.), so the LLM grounding payload had every field set to the whole
  row tuple. Fixed to unpack the (filename, chunkid, chunk,
  similarity_score, distance_score) shape that vector_search_sql
  returns.
- FineFoodReviews/_load-reviews.py: drop the misleading 'triggers
  AI_GENERATE_EMBEDDINGS server-side' line from the docstring — this
  script only loads rows; embedding happens in 001-load-and-embed.sql or
  _embed-reviews.py.
@amthomas46
amthomas46 requested a review from Copilot July 24, 2026 16:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@amthomas46
amthomas46 requested a review from Copilot July 24, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (8)

DiskANN/diskann-quickstart-azure-sql.sql:30

  • This INSERT targets unqualified Articles even though the table is created as dbo.Articles. If the executing user’s default schema isn’t dbo, this can insert into/expect the wrong object. Qualify with dbo.
INSERT INTO Articles (id, title, content, embedding)

DiskANN/diskann-quickstart-azure-sql.sql:78

  • This INSERT targets unqualified Articles but the table is dbo.Articles. Qualify the schema to avoid failures/accidental use of a different schema when the script is run under non-dbo default schemas.
INSERT INTO Articles (id, title, content, embedding)

DiskANN/diskann-quickstart-sql-server-2025.sql:43

  • This INSERT targets unqualified Articles even though the table is created as dbo.Articles. Qualify with dbo to avoid schema-resolution issues when run under non-dbo default schemas.
INSERT INTO Articles (id, title, content, embedding)

DiskANN/diskann-quickstart-azure-sql.sql:50

  • This CREATE VECTOR INDEX statement targets unqualified Articles even though the table is dbo.Articles. Qualifying the schema avoids failures when the executing user’s default schema isn’t dbo.
CREATE VECTOR INDEX vec_idx ON Articles(embedding)
WITH (METRIC = 'Cosine', TYPE = 'DiskANN')

DiskANN/diskann-quickstart-azure-sql.sql:64

  • VECTOR_SEARCH is pointed at unqualified Articles even though the table is dbo.Articles. Use dbo.Articles so the sample behaves consistently regardless of the caller’s default schema.
    VECTOR_SEARCH(
        TABLE = Articles AS t,
        COLUMN = embedding,

DiskANN/diskann-quickstart-azure-sql.sql:93

  • This VECTOR_SEARCH call uses unqualified Articles, which can resolve to a different schema than dbo in some environments. Qualify with dbo to ensure the query targets the table created by the script.
    VECTOR_SEARCH(
        TABLE = Articles AS t,
        COLUMN = embedding,

DiskANN/diskann-quickstart-sql-server-2025.sql:64

  • This CREATE VECTOR INDEX statement targets unqualified Articles even though the table is created as dbo.Articles. Qualifying the schema avoids resolution issues under non-dbo default schemas.
CREATE VECTOR INDEX vec_idx ON Articles(embedding)
WITH (METRIC = 'Cosine', TYPE = 'DiskANN')
ON [PRIMARY];

DiskANN/diskann-quickstart-sql-server-2025.sql:77

  • VECTOR_SEARCH is pointed at unqualified Articles even though the table is dbo.Articles. Use dbo.Articles to avoid schema-resolution issues when the script is run under users whose default schema isn’t dbo.
    VECTOR_SEARCH(
        TABLE = Articles AS t,
        COLUMN = embedding,

Comment thread DiskANN/diskann-quickstart-azure-sql.sql Outdated
Comment thread DiskANN/diskann-quickstart-azure-sql.sql Outdated
Comment thread DiskANN/diskann-quickstart-azure-sql-improvements.sql Outdated
Comment thread DiskANN/diskann-quickstart-sql-server-2025.sql Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

DiskANN/diskann-quickstart-sql-server-2025.sql:31

  • This script now mixes schema-qualified and unqualified references to the same table (e.g., dbo.Articles above vs Articles here). If the user's default schema is not dbo, this INSERT can fail or target an unexpected table. Use dbo.Articles consistently.
VALUES
(1, 'Intro to AI', 'This article introduces AI concepts.', '[0.1, 0.2, 0.3, 0.4, 0.5]'),
(2, 'Deep Learning', 'Deep learning is a subset of ML.', '[0.2, 0.1, 0.4, 0.3, 0.6]'),
(3, 'Neural Networks', 'Neural networks are powerful models.', '[0.3, 0.3, 0.3, 0.5, 0.1]'),

Comment thread RAG-with-Documents/RAG-with-resumes.ipynb Outdated
Comment thread RAG-with-Documents/RAG-with-resumes.ipynb Outdated
@amthomas46

Copy link
Copy Markdown
Author

@Pookam90 when you get a chance, can you clone and test to update? I tried to update all the things listed at the top. Thanks!

- Replace hard-coded Windows path with os.getenv("RESUME_FOLDER_PATH", ".")
- Remove separate loop that computed file_name only for the last file
- Compute file_name = os.path.basename(pdf_file) inside the enumerate loop
- Use pdf_file directly as pdf_path (already a full path from get_pdf_files)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants