|
1 | 1 | using Azure.AI.OpenAI;
|
2 | 2 | using Azure.Identity;
|
3 | 3 | using Microsoft.Extensions.AI;
|
4 |
| -using Microsoft.Extensions.VectorData; |
5 | 4 | using Microsoft.Extensions.Configuration;
|
| 5 | +using Microsoft.Extensions.VectorData; |
6 | 6 | using Microsoft.SemanticKernel.Connectors.InMemory;
|
7 | 7 | using VectorDataAI;
|
8 | 8 |
|
|
60 | 60 |
|
61 | 61 | // Create and populate the vector store
|
62 | 62 | var vectorStore = new InMemoryVectorStore();
|
63 |
| -var cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices"); |
| 63 | +Microsoft.Extensions.VectorData.IVectorStoreRecordCollection<int, CloudService> cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices"); |
64 | 64 | await cloudServicesStore.CreateCollectionIfNotExistsAsync();
|
65 | 65 |
|
66 |
| -foreach (var service in cloudServices) |
| 66 | +foreach (CloudService service in cloudServices) |
67 | 67 | {
|
68 | 68 | service.Vector = await generator.GenerateEmbeddingVectorAsync(service.Description);
|
69 | 69 | await cloudServicesStore.UpsertAsync(service);
|
70 | 70 | }
|
71 | 71 |
|
72 | 72 | // Convert a search query to a vector and search the vector store
|
73 |
| -var query = "Which Azure service should I use to store my Word documents?"; |
74 |
| -var queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query); |
| 73 | +string query = "Which Azure service should I use to store my Word documents?"; |
| 74 | +ReadOnlyMemory<float> queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query); |
75 | 75 |
|
76 |
| -var results = await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions() |
| 76 | +VectorSearchResults<CloudService> results = |
| 77 | + await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions<CloudService>() |
77 | 78 | {
|
78 |
| - Top = 1, |
79 |
| - VectorPropertyName = "Vector" |
| 79 | + Top = 1 |
80 | 80 | });
|
81 | 81 |
|
82 |
| -await foreach (var result in results.Results) |
| 82 | +await foreach (VectorSearchResult<CloudService> result in results.Results) |
83 | 83 | {
|
84 | 84 | Console.WriteLine($"Name: {result.Record.Name}");
|
85 | 85 | Console.WriteLine($"Description: {result.Record.Description}");
|
|
0 commit comments