Chapter 23 · SQL Server 2025 Features: Vector Data, AI-Oriented Workloads, and Modern Development

Embedding Pipelines, Vector Search Architecture, Filtering, and Hybrid Relational/Vector Queries

Design a reproducible embedding pipeline with chunking, provenance, hybrid filters, optional external models, and a separately governed preview approximate-search path.

Advanced180–260 minutesEmbedding pipeline + hybrid search labSQL Server 2025 CU7 · 17.0.4065.4Compatibility 170 · Developer labSSMS 22.8.2 · Last reviewed August 2026

Learning outcomes

A useful vector column is the last stage of a pipeline, not the first. ServiceHub must decide which text is embedded, how it is chunked, which model produced the vector, how changes trigger re-embedding, and how a query combines relational predicates with semantic ranking. SQL Server 2025 can generate chunks and embeddings and can define external model objects, but no database feature removes the need to govern the external model, network, credentials, latency or model-version contract.

01

Design a repeatable chunk/embed/load pipeline with model, dimension, source-hash and timestamp provenance.

02

Use AI_GENERATE_CHUNKS locally while keeping paid/external embedding calls optional.

03

Explain CREATE EXTERNAL MODEL and AI_GENERATE_EMBEDDINGS as GA features with explicit credential/network boundaries.

04

Distinguish exact hybrid search from preview approximate VECTOR_SEARCH/CREATE VECTOR INDEX.

05

Build re-embedding and filtering rules that prevent stale, cross-tenant or mixed-model search results.

Lab baseline. SQL Server 2025 (17.x), CU7 build 17.0.4065.4; compatibility level 170. SSMS 22.8.2 is the checked Windows administration tool; current VS Code + MSSQL extension and current sqlcmd are valid free alternatives. Azure Data Studio is retired. Mandatory labs use a free non-production SQL Server 2025 Developer edition and a disposable database named ServiceHubAILab. They use deterministic mock vectors, so no paid model API, API key, cloud account, or outbound network access is required. AI_GENERATE_CHUNKS requires compatibility level 170. External model calls are optional because they require a reachable inference endpoint and credentials. The lab keeps embeddings mocked and deterministic.

1. Make the embedding contract explicit before generating vectors

The embedding pipeline should be idempotent: the same source content and model contract should not create uncontrolled duplicate rows. A content hash is a practical change detector. The model identifier and dimension become part of the row's data contract. If either changes, the row is stale until re-embedded.

sql · add pipeline state and a chunk table
USE ServiceHubAILab;GOIF OBJECT_ID(N'lab23.DocumentChunk', N'U') IS NULLBEGIN    CREATE TABLE lab23.DocumentChunk    (        item_id          int NOT NULL,        chunk_ordinal    int NOT NULL,        chunk_text       nvarchar(1000) NOT NULL,        content_hash     varbinary(32) NOT NULL,        embedding_model  nvarchar(100) NOT NULL,        embedding        vector(4) NULL,        embedded_at      datetime2(0) NULL,        CONSTRAINT PK_lab23_DocumentChunk PRIMARY KEY(item_id, chunk_ordinal),        CONSTRAINT FK_lab23_DocumentChunk_Item FOREIGN KEY(item_id)            REFERENCES lab23.KnowledgeItem(item_id)    );END;

In a real pipeline, the source-of-truth text can be much longer than a model's recommended input size. Chunking changes retrieval quality: chunks that are too small lose context; chunks that are too large dilute the relevant concept and can exceed model limits.

sql · use SQL Server 2025 AI_GENERATE_CHUNKS without any external model call
USE ServiceHubAILab;GODECLARE @doc nvarchar(max) =N'VPN troubleshooting starts by confirming the user identity and password change. '+ N'Next verify MFA and device time. Then validate network reachability and the VPN client profile.';SELECT chunk, chunk_orderFROM AI_GENERATE_CHUNKS(    SOURCE = @doc,    CHUNK_TYPE = FIXED,    CHUNK_SIZE = 70,    OVERLAP = 10)ORDER BY chunk_order;

The exact chunk boundaries are deterministic for the chosen arguments but are not a semantic guarantee. Record chunking strategy/version when it matters to reproducibility.

2. External models are database objects around a network dependency

CREATE EXTERNAL MODEL stores endpoint/model metadata. AI_GENERATE_EMBEDDINGS can call that model and return the embedding. These features are GA in SQL Server 2025, but the inference endpoint is still external: it can throttle, fail, change price, change model behavior, or be unavailable. SQL Server's external rest endpoint enabled configuration is disabled by default and must be deliberately enabled before remote inference calls.

sql · inspect model and external-endpoint readiness without exposing secrets
SELECT    name,    value_in_useFROM sys.configurationsWHERE name IN (N'external rest endpoint enabled', N'allow server scoped db credentials');GOUSE ServiceHubAILab;GOSELECT    name,    location,    api_format,    model_type_desc,    model,    create_time,    modify_timeFROM sys.external_models;GOSELECT name, credential_identityFROM sys.database_scoped_credentials;
No API key belongs in a lesson, source repository, query history, or incident screenshot. Production credentials require an approved secret/identity design. Grant EXECUTE on a specific external model to the caller rather than broad model/credential administration when possible.

For an offline course lab, deterministic mock vectors are better evidence than pretending an external model is available. The goal is to learn SQL Server's integration boundary, not to force learners to buy an AI endpoint.

3. Exact hybrid search: filter first, rank second

Hybrid search combines relational predicates with semantic distance. For ServiceHub, “similar ticket” is still constrained by active status, tenant/region, data classification and sometimes document type. The exact query below is production-safe from a feature-status perspective because it does not require preview vector indexing.

sql · rank only the authorized relational candidate set
DECLARE @query vector(4) = '[0.78,0.18,0.04,0.08]';SELECT TOP (5)    item_id,    category,    source_text,    VECTOR_DISTANCE('cosine', @query, embedding) AS distanceFROM lab23.KnowledgeItemWHERE is_active = 1  AND region_code = 'N01'  AND embedding_model = N'lab-mock-v1'  AND embedding_dimensions = 4ORDER BY distance, item_id;

A wrong pattern is calculating top-k globally and then applying tenant/security filtering in application code. That can leak unauthorized candidates into telemetry and it can return fewer than k legal rows. Keep mandatory access predicates in the database query/authorization boundary.

4. Approximate vector search is a separate preview path

CREATE VECTOR INDEX and VECTOR_SEARCH are still preview in boxed SQL Server 2025 and require PREVIEW_FEATURES. They trade exactness for search efficiency and have current limitations. The latest vector-index generation is not identical across SQL Server, Azure SQL Database and Fabric, so copy/pasting cloud examples into boxed SQL Server is unsafe.

sql · optional preview gate — inspect before you change it
USE ServiceHubAILab;GOSELECT name, value, value_for_secondaryFROM sys.database_scoped_configurationsWHERE name = N'PREVIEW_FEATURES';GO-- Development/test only after reviewing current limitations:-- ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON;-- CREATE VECTOR INDEX IX_lab23_KnowledgeItem_embedding--   ON lab23.KnowledgeItem(embedding)--   WITH (METRIC='cosine', TYPE='DiskANN');-- VECTOR_SEARCH is then used for approximate nearest-neighbor retrieval.

Do not report an approximate-search latency number without also reporting recall/quality against an exact baseline. Faster wrong neighbors can be worse than a slower exact search. Current Microsoft documentation also notes that the newest vector-index generation is presently available only in Azure SQL Database and SQL database in Fabric, so boxed SQL Server 2025 preview behavior must be tested against its own current limitations. Some current index examples require a sufficiently sized synthetic corpus (for example at least 100 rows for the latest index generation); the eight-row mandatory lab intentionally does not pretend to be such a benchmark.

5. Re-embedding is a data migration

When the source text or model changes, decide whether to update in place, dual-write old/new embeddings during validation, or build a new table/index and cut over. A dual-version period makes A/B quality comparison possible and gives rollback. Treat model-version changes like schema/data migrations: inventory rows, backfill in batches, verify dimension and row counts, measure quality, then retire old vectors under a retention rule.

Check your understanding

  1. Why is an embedding model name part of the data contract?
  2. Does AI_GENERATE_CHUNKS require an external AI endpoint?
  3. Why keep mock vectors in the mandatory lab?
  4. What does PREVIEW_FEATURES gate here?
  5. What should a benchmark compare before adopting approximate search?
Review the answers

1. Because vectors from different semantic spaces can have identical dimensions yet be incomparable.

2. No. It chunks text inside SQL Server; AI_GENERATE_EMBEDDINGS requires an external model/inference path.

3. They make the lab free, deterministic and reproducible without secrets, cloud accounts, endpoint drift or throttling.

4. The preview approximate vector index/search path and other explicitly preview SQL Server 2025 features.

5. Latency/throughput and resource use together with recall/quality against an exact-search reference set.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.