-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce CommunityToolkit.VectorData.SqlServer #16
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
Changes from all commits
2b2bf84
45859d5
5035285
c22f623
5c6a91c
9ec59aa
b5b9ba7
b7b1c5c
1d4f68c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # CommunityToolkit.VectorData.SqlServer | ||
|
|
||
| SQL Server and Azure SQL provider for [Microsoft.Extensions.VectorData](https://learn.microsoft.com/en-us/dotnet/ai/vector-stores/overview). | ||
|
|
||
| ## Usage | ||
|
|
||
| ```csharp | ||
| using Microsoft.Extensions.VectorData; | ||
| using CommunityToolkit.VectorData.SqlServer; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another change when compared to microsoft/DacFx#786, the namespace is |
||
|
|
||
| // Define your record model | ||
| public sealed class BlogPost | ||
| { | ||
| [VectorStoreKey] | ||
| public int Id { get; set; } | ||
|
|
||
| [VectorStoreData] | ||
| public string? Title { get; set; } | ||
|
|
||
| [VectorStoreData] | ||
| public string? Url { get; set; } | ||
|
|
||
| [VectorStoreData] | ||
| public string? Content { get; set; } | ||
|
|
||
| [VectorStoreVector(Dimensions: 1536)] | ||
| public ReadOnlyMemory<float> ContentEmbedding { get; set; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to modernize these examples to use auto embedding generation. See https://learn.microsoft.com/en-us/dotnet/ai/vector-stores/define-your-data-model?tabs=attributes%2Ckey-attribute%2Cdata-attribute%2Cvector-attribute#automatic-embedding-generation-recommended [VectorStoreVector(Dimensions: 1536)]
public string ContentEmbedding => Content;This also requires configuring the vector store with an Embedding Generator, so if too complex for a simple inline example like this, feel free to ignore. And certainly feel free to do this in a follow up PR if you agree with the suggestion. |
||
| } | ||
|
|
||
| // Create the vector store and get a collection | ||
| using SqlServerVectorStore vectorStore = new(connectionString); | ||
| var collection = vectorStore.GetCollection<int, BlogPost>("BlogPosts"); | ||
| await collection.EnsureCollectionExistsAsync(); | ||
|
|
||
| // Upsert records | ||
| await collection.UpsertAsync(new BlogPost | ||
| { | ||
| Id = 1, | ||
| Title = "Vector search in Azure SQL", | ||
| Content = "...", | ||
| ContentEmbedding = embedding // ReadOnlyMemory<float> from your embedding provider | ||
| }); | ||
|
|
||
| // Search | ||
| var results = await collection.SearchAsync(queryEmbedding, top: 5).ToListAsync(); | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [Vector stores in .NET](https://learn.microsoft.com/en-us/dotnet/ai/vector-stores/overview) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to other code reviewers: microsoft/DacFx#786 was our source of truth, what we needed was to change the license header from
// Copyright (c) Microsoft. All rights reserved.