Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/ai/quickstarts/build-vector-search-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ Complete the following steps to create a .NET console app that can:

## Add the app code

1. Add a new class named **CloudService** to your project with the following properties:
1. Add a new class named `CloudService` to your project with the following properties:

:::code language="csharp" source="snippets/chat-with-data/azure-openai/CloudService.cs" :::

In the preceding code:

- The C# attributes provided by `Microsoft.Extensions.VectorData` influence how each property is handled when used in a vector store.
- The **Vector** property stores a generated embedding that represents the semantic meaning of the **Name** and **Description** for vector searches.
- The `Vector` property stores a generated embedding that represents the semantic meaning of the `Name` and `Description` for vector searches.

1. In the **Program.cs** file, add the following code to create a data set that describes a collection of cloud services:
1. In the `Program.cs` file, add the following code to create a data set that describes a collection of cloud services:

:::code language="csharp" source="snippets/chat-with-data/azure-openai/program.cs" id="DataSet":::

Expand Down Expand Up @@ -191,7 +191,7 @@ Complete the following steps to create a .NET console app that can:
dotnet run
```

The app prints out the top result of the vector search, which is the cloud service that is most relevant to the original query. You can modify the query to try different search scenarios.
The app prints out the top result of the vector search, which is the cloud service that's most relevant to the original query. You can modify the query to try different search scenarios.

:::zone target="docs" pivot="azure-openai"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ internal class CloudService
[VectorStoreRecordData]
public string Description { get; set; }

[VectorStoreRecordVector(384, DistanceFunction.CosineSimilarity)]
[VectorStoreRecordVector(Dimensions: 384, DistanceFunction = DistanceFunction.CosineSimilarity)]
public ReadOnlyMemory<float> Vector { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,23 @@

foreach (CloudService service in cloudServices)
{
service.Vector = await generator.GenerateEmbeddingVectorAsync(service.Description);
service.Vector = await generator.GenerateVectorAsync(service.Description);
await cloudServicesStore.UpsertAsync(service);
}
// </SnippetVectorStore>

// <SnippetSearch>
// Convert a search query to a vector and search the vector store
string query = "Which Azure service should I use to store my Word documents?";
ReadOnlyMemory<float> queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query);
ReadOnlyMemory<float> queryEmbedding = await generator.GenerateVectorAsync(query);

VectorSearchResults<CloudService> results =
await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions<CloudService>()
{
Top = 1
});
List<VectorSearchResult<CloudService>> results =
await cloudServicesStore.SearchEmbeddingAsync(queryEmbedding, top: 1).ToListAsync();

await foreach (VectorSearchResult<CloudService> result in results.Results)
foreach (VectorSearchResult<CloudService> result in results)
{
Console.WriteLine($"Name: {result.Record.Name}");
Console.WriteLine($"Description: {result.Record.Description}");
Console.WriteLine($"Vector match score: {result.Score}");
Console.WriteLine();
}
// </SnippetSearch>
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>5981f38c-e59c-46cc-80bb-463f8c3f1691</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.0-preview.1.25207.5" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.3-preview.1.25230.7" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25229.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.48.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.3.25171.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.3.25171.5" />
<PackageReference Include="System.Linq.AsyncEnumerable" Version="10.0.0-preview.3.25171.5" />
</ItemGroup>

</Project>