Clarify SQL Server support, improve docs and UI text

Updated documentation and UI to clarify support for both Azure SQL Database and SQL Server 2025+ for native VECTOR type storage and search. Improved README with accurate prerequisites, setup instructions, and detailed ModelId usage guidance. Clarified streaming response availability in both Blazor and API. Fixed typos and improved wording in UI messages. Enhanced code comments for clarity and accuracy, including ModelId guidance in appsettings.json.
This commit is contained in:
Marco Minerva
2026-07-28 15:14:17 +02:00
parent dc26a3d2e9
commit f9f75cdf7c
6 changed files with 36 additions and 24 deletions
+21 -12
View File
@@ -4,7 +4,7 @@
[![Minimal API](https://img.shields.io/badge/Minimal%20API-Available-green)](https://dotnet.microsoft.com/apps/aspnet/apis) [![Minimal API](https://img.shields.io/badge/Minimal%20API-Available-green)](https://dotnet.microsoft.com/apps/aspnet/apis)
[![Blazor](https://img.shields.io/badge/Blazor-WebApp-purple)](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) [![Blazor](https://img.shields.io/badge/Blazor-WebApp-purple)](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor)
A Blazor Web App and Minimal API for performing RAG (Retrieval Augmented Generation) and vector search using the native VECTOR type in Azure SQL Database, Azure OpenAI, and [Microsoft Agent Framework](https://github.com/microsoft/agent-framework). A Blazor Web App and Minimal API for performing RAG (Retrieval Augmented Generation) and vector search using the native VECTOR type in Azure SQL Database or SQL Server 2025, Azure OpenAI, and [Microsoft Agent Framework](https://github.com/microsoft/agent-framework).
## Table of Contents ## Table of Contents
- [Overview](#overview) - [Overview](#overview)
@@ -23,10 +23,12 @@ A Blazor Web App and Minimal API for performing RAG (Retrieval Augmented Generat
## Overview ## Overview
This application allows you to: This application allows you to:
- Load documents (PDF, DOCX, TXT, MD) - Load documents (PDF, DOCX, TXT, MD)
- Generate embeddings and save them as vectors in Azure SQL Database - Generate embeddings and save them as vectors in Azure SQL Database or SQL Server 2025
- Perform semantic search and RAG using Azure OpenAI and Microsoft Agent Framework agents - Perform semantic search and RAG using Azure OpenAI and Microsoft Agent Framework agents
- Interact via a Blazor Web App or programmatically via Minimal API - Interact via a Blazor Web App or programmatically via Minimal API
The native `VECTOR` type is available in both Azure SQL Database and SQL Server 2025, so no external vector store is required.
Embeddings and chat completion are orchestrated with [Microsoft Agent Framework](https://github.com/microsoft/agent-framework). The application uses an embedding workflow to import documents, a reformulation agent to rewrite follow-up questions with conversation context, and a RAG agent connected to a SQL vector-search context provider. Embeddings and chat completion are orchestrated with [Microsoft Agent Framework](https://github.com/microsoft/agent-framework). The application uses an embedding workflow to import documents, a reformulation agent to rewrite follow-up questions with conversation context, and a RAG agent connected to a SQL vector-search context provider.
## Screenshots ## Screenshots
@@ -39,18 +41,24 @@ Embeddings and chat completion are orchestrated with [Microsoft Agent Framework]
## Prerequisites ## Prerequisites
- [.NET 10 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/10.0) - [.NET 10 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/10.0)
- One of the following, both of which support the native `VECTOR` type:
- [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/single-database-create-quickstart) - [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/single-database-create-quickstart)
- [SQL Server 2025](https://learn.microsoft.com/en-us/sql/relational-databases/vectors/vectors-sql-server) or later
- Azure OpenAI resource and API keys - Azure OpenAI resource and API keys
## Project Structure ## Project Structure
- `SqlDatabaseVectorSearch/` - Main Blazor Web App and API - `SqlDatabaseVectorSearch/` - Main Blazor Web App and API
- `Components/` - Blazor UI components - `Components/` - Blazor UI components
- `ContentDecoders/` - Decoders that extract text from PDF, DOCX, TXT and MD files
- `Data/` - EF Core context, migrations, and entities - `Data/` - EF Core context, migrations, and entities
- `Endpoints/` - Minimal API endpoints - `Endpoints/` - Minimal API endpoints
- `Extensions/` - Extension methods and helpers
- `Models/` - Request and response models
- `Services/` - Business logic and integration services - `Services/` - Business logic and integration services
- `TextChunkers/` - Text splitting utilities
- `Workflows/` - Microsoft Agent Framework workflow executors for document import and embedding generation
- `Settings/` - Configuration classes - `Settings/` - Configuration classes
- `TextChunkers/` - Text splitting utilities
- `Validations/` - Request validators
- `Workflows/` - Microsoft Agent Framework workflow executors for document import and embedding generation
## Setup ## Setup
@@ -61,8 +69,8 @@ Embeddings and chat completion are orchestrated with [Microsoft Agent Framework]
``` ```
2. Configure the database and OpenAI settings 2. Configure the database and OpenAI settings
- Edit `SqlDatabaseVectorSearch/appsettings.json` and set your Azure SQL connection string and OpenAI settings. - Edit `SqlDatabaseVectorSearch/appsettings.json` and set your connection string (Azure SQL Database or SQL Server 2025) and OpenAI settings.
- **Important**: The `ModelId` values for both `ChatCompletion` and `Embedding` are used for token counting via `Microsoft.ML.Tokenizers`. These values must be valid model identifiers supported by the tokenizer library (e.g., `gpt-4o`, `gpt-4`, `gpt-3.5-turbo`, `text-embedding-3-small`, `text-embedding-3-large`, `text-embedding-ada-002`). The `ModelId` may differ from the actual deployment name you're using in Azure OpenAI. For example, for gpt-4.1 and gpt-5 models set the `ModelId` to `gpt-4o` for proper token counting. - **Important**: The `ModelId` values for both `ChatCompletion` and `Embedding` are used only for token counting via `Microsoft.ML.Tokenizers`, while the actual calls to the service use the `Deployment` values. `ModelId` must therefore be a model name recognized by the tokenizer library (e.g., `gpt-5`, `gpt-4.1`, `gpt-4o`, `gpt-4`, `gpt-3.5-turbo`, `text-embedding-3-small`, `text-embedding-3-large`, `text-embedding-ada-002`), which is typically different from the deployment name you have chosen in Azure OpenAI. If a model is not recognized, `TiktokenTokenizer.CreateForModel` throws at startup: in that case, fall back to the closest supported model that shares the same encoding (for example `gpt-4o` for newer GPT models).
- If using embedding models with shortening (e.g., `text-embedding-3-small` or `text-embedding-3-large`), set the `Dimensions` property accordingly. For `text-embedding-3-large`, you must specify a value <= 1998. - If using embedding models with shortening (e.g., `text-embedding-3-small` or `text-embedding-3-large`), set the `Dimensions` property accordingly. For `text-embedding-3-large`, you must specify a value <= 1998.
- If you change the VECTOR size, update both the [ApplicationDbContext](SqlDatabaseVectorSearch/Data/ApplicationDbContext.cs) and the [Initial Migration](SqlDatabaseVectorSearch/Data/Migrations/00000000000000_Initial.cs). - If you change the VECTOR size, update both the [ApplicationDbContext](SqlDatabaseVectorSearch/Data/ApplicationDbContext.cs) and the [Initial Migration](SqlDatabaseVectorSearch/Data/Migrations/00000000000000_Initial.cs).
@@ -72,16 +80,16 @@ Embeddings and chat completion are orchestrated with [Microsoft Agent Framework]
dotnet run --project SqlDatabaseVectorSearch/SqlDatabaseVectorSearch.csproj dotnet run --project SqlDatabaseVectorSearch/SqlDatabaseVectorSearch.csproj
``` ```
5. Access the Web App 4. Access the Web App
- Navigate to `https://localhost:5001` (or the port shown in the console) - Navigate to `https://localhost:7025` (or the port shown in the console)
## Supported features ## Supported features
- **Microsoft Agent Framework orchestration**: Document import is implemented as a workflow, while question reformulation and RAG are implemented as agents. - **Microsoft Agent Framework orchestration**: Document import is implemented as a workflow, while question reformulation and RAG are implemented as agents.
- **Conversation history with question reformulation**: The reformulation agent rewrites each question using the conversation context before vector search is performed. - **Conversation history with question reformulation**: The reformulation agent rewrites each question using the conversation context before vector search is performed.
- **SQL vector-search context provider**: The RAG agent receives relevant chunks from Azure SQL Database through a `TextSearchProvider` backed by native VECTOR search. - **SQL vector-search context provider**: The RAG agent receives relevant chunks from Azure SQL Database or SQL Server 2025 through a `TextSearchProvider` backed by native VECTOR search.
- **Information about token usage**: The Blazor chat page and API responses expose token usage for reformulation and final answer generation. - **Information about token usage**: The Blazor chat page and API responses expose token usage for reformulation and final answer generation.
- **Response streaming**: The Blazor chat page uses streaming responses, appending answer tokens as they arrive. - **Response streaming**: The Blazor chat page and the `/api/ask-streaming` endpoint stream answers, appending tokens as they arrive.
- **Markdown source citations**: Citations are included directly in the generated Markdown answer as a localized sources section with source name, page number when available, and a short supporting excerpt. - **Markdown source citations**: Citations are included directly in the generated Markdown answer as a localized sources section with source name, page number when available, and a short supporting excerpt.
## How to Use ## How to Use
@@ -92,7 +100,7 @@ Embeddings and chat completion are orchestrated with [Microsoft Agent Framework]
### How it works ### How it works
1. Documents are uploaded through the API and processed by the `EmbeddingWorkflow`. 1. Documents are uploaded through the API and processed by the `EmbeddingWorkflow`.
2. The workflow converts the uploaded file into text, chunks it, generates embeddings, and stores documents, chunks, and VECTOR embeddings in Azure SQL Database. 2. The workflow converts the uploaded file into text, chunks it, generates embeddings, and stores documents, chunks, and VECTOR embeddings in Azure SQL Database or SQL Server 2025.
3. When a question is asked, the `ReformulationAgent` can rewrite it using the current conversation context. 3. When a question is asked, the `ReformulationAgent` can rewrite it using the current conversation context.
4. The `RagAgent` receives relevant SQL vector-search results through a `TextSearchProvider` and answers using only the provided context. 4. The `RagAgent` receives relevant SQL vector-search results through a `TextSearchProvider` and answers using only the provided context.
5. Sources are not returned as a separate JSON collection. They are formatted directly in the Markdown answer. 5. Sources are not returned as a separate JSON collection. They are formatted directly in the Markdown answer.
@@ -103,7 +111,7 @@ POST /api/ask
Content-Type: application/json Content-Type: application/json
{ {
"conversationId": "3d0bd178-499d-433a-b2bc-c35e488d9e2c" "conversationId": "3d0bd178-499d-433a-b2bc-c35e488d9e2c",
"text": "Why is Mars called the red planet?" "text": "Why is Mars called the red planet?"
} }
``` ```
@@ -167,6 +175,7 @@ data: {"conversationId":"3d0bd178-499d-433a-b2bc-c35e488d9e2c","originalQuestion
## Limitations & FAQ ## Limitations & FAQ
- **Database**: Azure SQL Database or SQL Server 2025 (or later). Both provide the native `VECTOR` type used by this sample.
- **VECTOR column size**: Maximum allowed is 1998. For `text-embedding-3-large`, set `Dimensions` <= 1998. - **VECTOR column size**: Maximum allowed is 1998. For `text-embedding-3-large`, set `Dimensions` <= 1998.
- **Supported file types**: PDF, DOCX, TXT, MD. - **Supported file types**: PDF, DOCX, TXT, MD.
- **Known Issues**: See [Issues](https://github.com/marcominerva/SqlDatabaseVectorSearch/issues) - **Known Issues**: See [Issues](https://github.com/marcominerva/SqlDatabaseVectorSearch/issues)
@@ -9,9 +9,9 @@
<PageTitle>Page Not Found</PageTitle> <PageTitle>Page Not Found</PageTitle>
<h1 class="display-1 fw-bold">404</h1> <h1 class="display-1 fw-bold">404</h1>
<p class="fs-3"><span class="text-danger">Ops!</span> Page Not Found.</p> <p class="fs-3"><span class="text-danger">Oops!</span> Page Not Found.</p>
<p class="lead"> <p class="lead">
The page you're looking for does not exists. The page you're looking for does not exist.
</p> </p>
} }
else if (Code > 0) else if (Code > 0)
@@ -19,9 +19,9 @@
<PageTitle>Unexpected Error</PageTitle> <PageTitle>Unexpected Error</PageTitle>
<h1 class="display-1 fw-bold">500</h1> <h1 class="display-1 fw-bold">500</h1>
<p class="fs-3"><span class="text-danger">Ops!</span> Unexpected error.</p> <p class="fs-3"><span class="text-danger">Oops!</span> Unexpected error.</p>
<p class="lead"> <p class="lead">
An unexpected error occurred while loading the page. Please, wait a minute and try again. An unexpected error occurred while loading the page. Please wait a moment and try again.
</p> </p>
} }
@@ -11,7 +11,8 @@
<p class="lead mb-4"> <p class="lead mb-4">
A Blazor Web App and Minimal API for Retrieval Augmented Generation (RAG) and vector search using the native A Blazor Web App and Minimal API for Retrieval Augmented Generation (RAG) and vector search using the native
<code>VECTOR</code> type in <code>VECTOR</code> type in
<img src="/images/sqldatabase.svg" class="inline-logo" alt="Azure SQL Database" /> Azure SQL Database, with <img src="/images/sqldatabase.svg" class="inline-logo" alt="Azure SQL Database" /> Azure SQL Database or
SQL Server 2025, with
<img src="/images/openai.svg" class="inline-logo" alt="Azure OpenAI" /> Azure OpenAI and <img src="/images/openai.svg" class="inline-logo" alt="Azure OpenAI" /> Azure OpenAI and
<a href="https://github.com/microsoft/agent-framework" target="_blank" rel="noopener">Microsoft Agent Framework</a>. <a href="https://github.com/microsoft/agent-framework" target="_blank" rel="noopener">Microsoft Agent Framework</a>.
</p> </p>
@@ -49,8 +50,8 @@
<Icon Name="IconName.DatabaseFillCheck" Color="IconColor.Success" Size="IconSize.x3" /> <Icon Name="IconName.DatabaseFillCheck" Color="IconColor.Success" Size="IconSize.x3" />
<h3 class="h6 mt-3 mb-2">2. Store</h3> <h3 class="h6 mt-3 mb-2">2. Store</h3>
<p class="text-body-secondary mb-0 small"> <p class="text-body-secondary mb-0 small">
Embeddings are persisted in Azure SQL Database using the native <code>VECTOR</code> type, so no Embeddings are persisted in Azure SQL Database or SQL Server 2025 using the native
external vector store is required. <code>VECTOR</code> type, so no external vector store is required.
</p> </p>
</div> </div>
</div> </div>
@@ -87,8 +88,8 @@
</li> </li>
<li class="list-group-item"> <li class="list-group-item">
<Icon Name="IconName.DatabaseFillCheck" Color="IconColor.Success" Class="me-2" /> <Icon Name="IconName.DatabaseFillCheck" Color="IconColor.Success" Class="me-2" />
<strong>SQL vector search</strong>: the most relevant chunks are retrieved from Azure SQL Database through <strong>SQL vector search</strong>: the most relevant chunks are retrieved from Azure SQL Database or
native <code>VECTOR</code> cosine-distance search. SQL Server 2025 through native <code>VECTOR</code> cosine-distance search.
</li> </li>
<li class="list-group-item"> <li class="list-group-item">
<Icon Name="IconName.CashCoin" Color="IconColor.Warning" Class="me-2" /> <Icon Name="IconName.CashCoin" Color="IconColor.Warning" Class="me-2" />
+2
View File
@@ -152,6 +152,8 @@ builder.Services.AddAIAgent("ReformulationAgent", (services, key) =>
}, },
ChatHistoryProvider = new InMemoryChatHistoryProvider(new() ChatHistoryProvider = new InMemoryChatHistoryProvider(new()
{ {
// The reformulation agent reads the conversation only to get the context it needs, but its own questions and answers
// must not pollute the session: the history is kept clean for the RAG agent, so nothing is stored back.
StorageInputRequestMessageFilter = _ => [], StorageInputRequestMessageFilter = _ => [],
StorageInputResponseMessageFilter = _ => [] StorageInputResponseMessageFilter = _ => []
}) })
@@ -19,7 +19,7 @@ public partial class GenerateEmbeddingExecutor(IServiceProvider serviceProvider,
var chunks = await decoder.DecodeAsync(request.Content, request.ContentType, cancellationToken); var chunks = await decoder.DecodeAsync(request.Content, request.ContentType, cancellationToken);
var chunkContents = chunks.Select(p => p.Content).ToList(); var chunkContents = chunks.Select(p => p.Content).ToList();
// We get the token count of the whole document because it is the total number of token used by embedding (it may be necessary, for example, for cost analysis). // We get the token count of the whole document because it is the total number of tokens used by the embedding (it may be necessary, for example, for cost analysis).
var tokenCount = tokenizerService.CountEmbeddingTokens(string.Join(" ", chunkContents)); var tokenCount = tokenizerService.CountEmbeddingTokens(string.Join(" ", chunkContents));
// Process paragraphs in batches. // Process paragraphs in batches.
+1 -1
View File
@@ -6,7 +6,7 @@
"ChatCompletion": { "ChatCompletion": {
"Endpoint": "", "Endpoint": "",
"Deployment": "", "Deployment": "",
"ModelId": "", // gpt-4o, gpt-4, gpt-3.5, etc. Note that for gpt-4.1 and gpt-5 models, the ModelId must be set to gpt-4o. "ModelId": "", // Used only for token counting: gpt-5, gpt-4.1, gpt-4o, gpt-4, gpt-3.5-turbo, etc. If the model isn't supported by Microsoft.ML.Tokenizers, use the closest one (for example gpt-4o).
"ApiKey": "" "ApiKey": ""
}, },
"Embedding": { "Embedding": {