-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Beef up MEVD docs: expanded conceptual article, new how-to guide, and working code snippets #51846
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
base: main
Are you sure you want to change the base?
Changes from all commits
ffd718c
424793f
fe8c80c
1ddb6a1
ab4c26a
21b049a
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,56 @@ | ||||||||||||||||||||||
| using Microsoft.Extensions.AI; | ||||||||||||||||||||||
| using Microsoft.Extensions.VectorData; | ||||||||||||||||||||||
| using Microsoft.SemanticKernel.Connectors.InMemory; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // <AutoEmbeddingDataModel> | ||||||||||||||||||||||
| // When the vector property type is string (not ReadOnlyMemory<float>), | ||||||||||||||||||||||
| // the vector store automatically generates embeddings using the configured IEmbeddingGenerator. | ||||||||||||||||||||||
| public class FinanceInfo | ||||||||||||||||||||||
|
Member
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. This looks like it could / should be a record?
Suggested change
|
||||||||||||||||||||||
| { | ||||||||||||||||||||||
| [VectorStoreKey] | ||||||||||||||||||||||
| public int Key { get; set; } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| [VectorStoreData] | ||||||||||||||||||||||
| public string Text { get; set; } = ""; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // The string value placed here before upsert is automatically converted to a vector. | ||||||||||||||||||||||
| [VectorStoreVector(1536)] | ||||||||||||||||||||||
| public string EmbeddingSource { get; set; } = ""; | ||||||||||||||||||||||
|
Comment on lines
+14
to
+18
Member
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. In both cases,
Suggested change
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| // </AutoEmbeddingDataModel> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public static class AutoEmbeddingExample | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| public static async Task RunAsync(IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| // <AutoEmbeddingVectorStore> | ||||||||||||||||||||||
| // Configure the embedding generator at the vector store level. | ||||||||||||||||||||||
| // All collections in this store will use it unless overridden. | ||||||||||||||||||||||
| var vectorStore = new InMemoryVectorStore(new InMemoryVectorStoreOptions | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| EmbeddingGenerator = embeddingGenerator | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var collection = vectorStore.GetCollection<int, FinanceInfo>("finance"); | ||||||||||||||||||||||
| await collection.EnsureCollectionExistsAsync(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Embeddings are generated automatically on upsert. | ||||||||||||||||||||||
| var records = new[] | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| new FinanceInfo { Key = 1, Text = "2024 Budget", EmbeddingSource = "The budget for 2024 is $100,000" }, | ||||||||||||||||||||||
| new FinanceInfo { Key = 2, Text = "2023 Budget", EmbeddingSource = "The budget for 2023 is $80,000" } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| await collection.UpsertAsync(records[0]); | ||||||||||||||||||||||
| await collection.UpsertAsync(records[1]); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Embeddings for search are also generated automatically. | ||||||||||||||||||||||
| var results = collection.SearchAsync("What is my 2024 budget?", top: 1); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| await foreach (var result in results) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| Console.WriteLine($"Found: Key={result.Record.Key}, Text={result.Record.Text}"); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| // </AutoEmbeddingVectorStore> | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||
| // <DataModel> | ||||||
| using Microsoft.Extensions.VectorData; | ||||||
|
|
||||||
| public class Hotel | ||||||
|
Member
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. same comment here on record:
Suggested change
|
||||||
| { | ||||||
| [VectorStoreKey] | ||||||
| public int HotelId { get; set; } | ||||||
|
|
||||||
| [VectorStoreData(IsIndexed = true)] | ||||||
| public string? HotelName { get; set; } | ||||||
|
|
||||||
| [VectorStoreData(IsFullTextIndexed = true)] | ||||||
| public string? Description { get; set; } | ||||||
|
|
||||||
| [VectorStoreVector(Dimensions: 1536, DistanceFunction = DistanceFunction.CosineSimilarity)] | ||||||
| public ReadOnlyMemory<float>? DescriptionEmbedding { get; set; } | ||||||
|
|
||||||
| [VectorStoreData(IsIndexed = true)] | ||||||
| public string[]? Tags { get; set; } | ||||||
| } | ||||||
| // </DataModel> | ||||||
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.
technical nit: