Skip to content

Bruno add scenario for vector search with SQL2025 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 20, 2025

Conversation

elbruno
Copy link
Contributor

@elbruno elbruno commented Jun 20, 2025

This pull request introduces a new scenario, "SQL 2025 Preview," showcasing the integration of vector search and vector indexes in SQL Server 2025 within a .NET Aspire application. The changes include updates to documentation, project setup, and implementation of the scenario's core functionality, along with unit tests to ensure robustness.

SQL 2025 Scenario Implementation:

  • Scenario Documentation: Added a new entry for "SQL 2025 Preview" in README.md and created a dedicated README.md for the scenario. This includes an overview, features, architecture diagram, deployment guidance, and cost/security considerations. [1] [2]

  • Project Setup:

    • Created DataEntities.csproj targeting .NET 9.0 with nullable reference types enabled.
    • Added .editorconfig settings to suppress specific warnings (CS8602 and IDE0058).
  • Core Functionality:

    • Implemented the Product class with support for SQL Server 2025's vector type and JSON serialization.
    • Developed ProductDataContext for database operations and initialized sample product data with vector embeddings.
    • Added an AISearch() function in ProductApiActions to perform semantic search using vector embeddings.

Unit Testing:

  • Test Project Setup: Created Products.Tests.csproj targeting .NET 9.0 with references to EntityFrameworkCore.InMemory and MSTest.
  • Test Coverage: Added unit tests for CRUD operations and semantic search in ProductApiActionsTests.

Tooling and Configuration:

  • EF Core Tooling: Added dotnet-ef to dotnet-tools.json for database migrations and management.

These changes collectively enable semantic search capabilities in a .NET Aspire application using SQL Server 2025's vector search features.

elbruno added 11 commits June 20, 2025 17:25
DETAILS

The Dockerfile has been modified to replace the previous SQL Server 2025 CTP 2.1 image with the official SQL Server 2025 Preview image for Ubuntu 22.04. The image line has been updated from `FROM mcr.microsoft.com/mssql/server:2025-CTP2.1-ubuntu-22.04` to `FROM mcr.microsoft.com/mssql/server:2025-latest`.
DETAILS

This commit removes the `MemoryContext` class and its associated dependencies from `ProductEndpoints.cs`, `MemoryContext.cs`, `Products.csproj`, and `Program.cs`. This change signifies a transition away from in-memory storage for product data, potentially indicating a new data management strategy. Additionally, related logging and initialization logic have been eliminated, simplifying the product management process. References to the `VectorEntities` project have also been removed from the solution file.
DETAILS

The `ProductVector.cs` file has been completely removed, which included the definition of the `ProductVector` class that inherited from `Product`. This class had properties for `Id`, `Name`, `Description`, `Price`, and a `Vector` of type `ReadOnlyMemory<float>`, all of which were overridden from the base class and included attributes for vector storage.

The `VectorEntities.csproj` file has also been removed entirely. This project file defined the project settings, including the target framework (`net9.0`), implicit usings, nullable reference types, and a package reference to `Microsoft.Extensions.VectorData.Abstractions`. It also included a project reference to another project located in the `DataEntities` directory.
DETAILS

Modified console output in `AISearch` to reflect "similar products" and added a filter to exclude products with IDs less than or equal to 0, ensuring only valid products are returned in the search results.
DETAILS

Modified the LINQ query to directly select the product entity instead of creating an anonymous object with product name and distance. This change simplifies the result set and allows easier access to all properties of the `Product` entity.
DETAILS

- Changed `Embedding` initialization in `Product` class to use an empty array `[]`.
- Updated `AISearch` method in `ProductAiActions.cs` to include a `dimensions` parameter, modifying embedding generation and reducing returned products from 3 to 2.
- Modified `DbInitializer` to pass the `dimensions` parameter for consistent embedding generation.
- Changed embedding model name from `"text-embedding-ada-002"` to `"text-embedding-3-small"` in `Program.cs`.
- Updated deployment configuration to align with the new embedding model name and version.
DETAILS

- Added new using directives for Entity Framework Core and OpenAI namespaces.
- Corrected the globalization environment variable from "fal" to "false".
- Commented out the old method of adding DbContext with `AddSqlServerDbContext`.
- Introduced a new approach to retrieve the connection string from configuration and initialize DbContext with vector search enabled.
- Added comments for clarity on DbContext handling and Azure OpenAI client configuration.
DETAILS

Removed the `ProductAiActions` class and integrated its `AISearch` method into `ProductApiActions`. Updated `using` directives to include necessary namespaces, refactored response construction for improved readability, and updated routing for the AISearch endpoint to ensure continued functionality.
DETAILS

The project file `Products.csproj` has been updated to remove several package references, including `Aspire.Microsoft.EntityFrameworkCore.SqlServer`, `Microsoft.SemanticKernel.Connectors.InMemory`, `Microsoft.VisualStudio.Web.CodeGeneration.Design`, and `OpenTelemetry.Instrumentation.AspNetCore`. Additionally, the project reference to `VectorEntities.csproj` has been removed. The remaining package references are `Aspire.Azure.AI.OpenAI` and `EFCore.SqlServer.VectorSearch`.
Copy link

👋 Thanks for contributing @elbruno! We will review the pull request and get back to you soon.

Copy link

Check Broken Paths

We have automatically detected the following broken relative paths in your files.
Review and fix the paths to resolve this issue.

Check the file paths and associated broken paths inside them.
For more details, check our Contributing Guide.

File Full Path Issues
scenarios/06-mcp/README.md
#LinkLine Number
1./src/eShopLite-Mcp.sln79
scenarios/05-deepseek/README.md
#LinkLine Number
1./images/90ytrunfromcodespaces.png227
scenarios/08-Sql2025/README.md
#LinkLine Number
1./src/eShopLite-Aspire.sln98

Copy link

Check Broken Paths

We have automatically detected the following broken relative paths in your files.
Review and fix the paths to resolve this issue.

Check the file paths and associated broken paths inside them.
For more details, check our Contributing Guide.

File Full Path Issues
scenarios/06-mcp/README.md
#LinkLine Number
1./src/eShopLite-Mcp.sln79
scenarios/05-deepseek/README.md
#LinkLine Number
1./images/90ytrunfromcodespaces.png227

Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
README.md
#LinkLine Number
1https://dcbadge.vercel.app/api/server/ByRwuEEgH411
scenarios/02-AzureAISearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/06-mcp/README.md
#LinkLine Number
1https://twitter.com/elbruno3
scenarios/05-deepseek/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/03-RealtimeAudio/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/08-Sql2025/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/01-SemanticSearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2

Copy link

Check Broken Paths

We have automatically detected the following broken relative paths in your files.
Review and fix the paths to resolve this issue.

Check the file paths and associated broken paths inside them.
For more details, check our Contributing Guide.

File Full Path Issues
scenarios/06-mcp/README.md
#LinkLine Number
1./src/eShopLite-Mcp.sln79

Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
README.md
#LinkLine Number
1https://dcbadge.vercel.app/api/server/ByRwuEEgH411
scenarios/02-AzureAISearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/06-mcp/README.md
#LinkLine Number
1https://twitter.com/elbruno3
scenarios/05-deepseek/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/03-RealtimeAudio/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/08-Sql2025/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/01-SemanticSearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2

Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
README.md
#LinkLine Number
1https://dcbadge.vercel.app/api/server/ByRwuEEgH411
scenarios/02-AzureAISearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/06-mcp/README.md
#LinkLine Number
1https://twitter.com/elbruno3
scenarios/05-deepseek/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/03-RealtimeAudio/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/08-Sql2025/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/01-SemanticSearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2

1 similar comment
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
README.md
#LinkLine Number
1https://dcbadge.vercel.app/api/server/ByRwuEEgH411
scenarios/02-AzureAISearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/06-mcp/README.md
#LinkLine Number
1https://twitter.com/elbruno3
scenarios/05-deepseek/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/03-RealtimeAudio/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/08-Sql2025/README.md
#LinkLine Number
1https://twitter.com/elbruno2
scenarios/01-SemanticSearch/README.md
#LinkLine Number
1https://twitter.com/elbruno2

@elbruno elbruno merged commit 702308c into main Jun 20, 2025
7 of 8 checks passed
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
README.md
#LinkLine Number
1https://dcbadge.vercel.app/api/server/ByRwuEEgH411

@elbruno elbruno deleted the bruno-add-scenario-sql2025 branch June 20, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant