You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this quickstart, you create a .NET console app to perform semantic search on a vector store to find relevant results for the user's query. You learn how to generate embeddings for user prompts and use those embeddings to query the vector data store. Vector search functionality is also a key component for Retrieval Augmented Generation (RAG) scenarios. The app uses the <xref:Microsoft.Extensions.AI> and [Microsoft.Extensions.VectorData.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.VectorData.Abstractions) libraries so you can write code using AI abstractions rather than a specific SDK. AI abstractions help create loosely coupled code that allows you to change the underlying AI model with minimal app changes.
13
+
In this quickstart, you create a .NET console app to perform semantic search on a _vector store_ to find relevant results for the user's query. You learn how to generate embeddings for user prompts and use those embeddings to query the vector data store.
14
14
15
-
:::zone target="docs" pivot="openai"
15
+
Vector stores, or vector databases, are essential for tasks like semantic search, retrieval augmented generation (RAG), and other scenarios that require grounding generative AI responses. While relational databases and document databases are optimized for structured and semi-structured data, vector databases are built to efficiently store, index, and manage data represented as embedding vectors. As a result, the indexing and search algorithms used by vector databases are optimized to efficiently retrieve data that can be used downstream in your applications.
The app uses the <xref:Microsoft.Extensions.AI> and <xref:Microsoft.Extensions.VectorData> libraries so you can write code using AI abstractions rather than a specific SDK. AI abstractions help create loosely coupled code that allows you to change the underlying AI model with minimal app changes.
20
20
21
-
:::zone target="docs" pivot="azure-openai"
21
+
[📦 Microsoft.Extensions.VectorData.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.VectorData.Abstractions/) is a .NET library developed in collaboration with Semantic Kernel and the broader .NET ecosystem to provide a unified layer of abstractions for interacting with vector stores. The abstractions in `Microsoft.Extensions.VectorData.Abstractions` provide library authors and developers with the following functionality:
- Perform create-read-update-delete (CRUD) operations on vector stores.
24
+
- Use vector and text search on vector stores.
24
25
25
-
:::zone-end
26
+
> [!NOTE]
27
+
> The [Microsoft.Extensions.VectorData.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.VectorData.Abstractions/) library is currently in preview.
26
28
27
-
## Interact with your data using vector stores
29
+
<!--Prerequisites section-->
28
30
29
-
Vector stores or vector databases are essential for tasks like semantic search, Retrieval Augmented Generation (RAG), and other scenarios that require grounding generative AI responses. While relational databases and document databases are optimized for structured and semi-structured data, vector databases are built to efficiently store, index, and manage data represented as embedding vectors. As a result, the indexing and search algorithms used by vector databases are optimized to efficiently retrieve data that can be used downstream in your applications.
[Microsoft.Extensions.VectorData.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.VectorData.Abstractions/) is a .NET library developed in collaboration with Semantic Kernel and the broader .NET ecosystem to provide a unified layer of abstractions for interacting with vector stores.
35
+
:::zone-end
34
36
35
-
The abstractions in `Microsoft.Extensions.VectorData.Abstractions` provide library authors and developers with the following functionality:
37
+
:::zone target="docs" pivot="azure-openai"
36
38
37
-
- Perform Create-Read-Update-Delete (CRUD) operations on vector stores
> The [Microsoft.Extensions.VectorData.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.VectorData.Abstractions/) library is currently in preview.
41
+
:::zone-end
42
42
43
43
## Create the app
44
44
45
45
Complete the following steps to create a .NET console app that can:
46
46
47
-
- Create and populate a vector store by generating embeddings for a data set
48
-
- Generate an embedding for the user prompt
49
-
- Query the vector store using the user prompt embedding
50
-
- Display the relevant results from the vector search
47
+
- Create and populate a vector store by generating embeddings for a data set.
48
+
- Generate an embedding for the user prompt.
49
+
- Query the vector store using the user prompt embedding.
50
+
- Display the relevant results from the vector search.
51
51
52
52
1. In an empty directory on your computer, use the `dotnet new` command to create a new console app:
53
53
@@ -80,8 +80,8 @@ Complete the following steps to create a .NET console app that can:
80
80
81
81
- [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) provides [`Microsoft Entra ID`](/entra/fundamentals/whatis) token authentication support across the Azure SDK using classes such as `DefaultAzureCredential`.
82
82
- [`Azure.AI.OpenAI`](https://www.nuget.org/packages/Azure.AI.OpenAI) is the official package for using OpenAI's .NET library with the Azure OpenAI Service.
83
-
- [`Microsoft.SemanticKernel.Connectors.InMemory`](https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.InMemory) provides an in-memory vector store class to hold queryable vector data records.
84
83
- [`Microsoft.Extensions.VectorData.Abstractions`](https://www.nuget.org/packages/Microsoft.Extensions.AI) enables Create-Read-Update-Delete (CRUD) and search operations on vector stores.
84
+
- [`Microsoft.SemanticKernel.Connectors.InMemory`](https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.InMemory) provides an in-memory vector store class to hold queryable vector data records.
85
85
- [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration) provides an implementation of key-value pair—based configuration.
86
86
- [`Microsoft.Extensions.Configuration.UserSecrets`](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.UserSecrets) is a user secrets configuration provider implementation for `Microsoft.Extensions.Configuration`.
87
87
@@ -101,8 +101,8 @@ Complete the following steps to create a .NET console app that can:
101
101
The following list describes each package in the `VectorDataAI` app:
102
102
103
103
- [`Microsoft.Extensions.AI.OpenAI`](https://www.nuget.org/packages/Microsoft.Extensions.AI.OpenAI) provides AI abstractions for OpenAI-compatible models or endpoints. This library also includes the official [`OpenAI`](https://www.nuget.org/packages/OpenAI) library for the OpenAI service API as a dependency.
104
-
- [`Microsoft.SemanticKernel.Connectors.InMemory`](https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.InMemory) provides an in-memory vector store class to hold queryable vector data records.
105
104
- [`Microsoft.Extensions.VectorData.Abstractions`](https://www.nuget.org/packages/Microsoft.Extensions.AI) enables Create-Read-Update-Delete (CRUD) and search operations on vector stores.
105
+
- [`Microsoft.SemanticKernel.Connectors.InMemory`](https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.InMemory) provides an in-memory vector store class to hold queryable vector data records.
106
106
- [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration) provides an implementation of key-value pair—based configuration.
107
107
- [`Microsoft.Extensions.Configuration.UserSecrets`](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.UserSecrets) is a user secrets configuration provider implementation for `Microsoft.Extensions.Configuration`.
108
108
@@ -134,21 +134,18 @@ Complete the following steps to create a .NET console app that can:
134
134
dotnet user-secrets set ModelName <your-OpenAI-model-name>
135
135
```
136
136
137
-
> [!NOTE]
138
-
> For the `ModelName` value, you need to specify an OpenAI text embedding model such as `text-embedding-3-small` or `text-embedding-3-large` to generate embeddings for vector search in the sections that follow.
139
-
140
137
:::zone-end
141
138
139
+
> [!NOTE]
140
+
> For the model name, you need to specify a text embedding model such as `text-embedding-3-small` or `text-embedding-3-large` to generate embeddings for vector search in the sections that follow. For more information about embedding models, see [Embeddings](/azure/ai-services/openai/concepts/models#embeddings).
141
+
142
142
## Add the app code
143
143
144
144
1. Add a new class named `CloudService` to your project with the following properties:
- The C# attributes provided by `Microsoft.Extensions.VectorData` influence how each property is handled when used in a vector store.
151
-
- The `Vector` property stores a generated embedding that represents the semantic meaning of the `Name` and `Description` for vector searches.
148
+
The <xref:Microsoft.Extensions.VectorData> attributes, such as <xref:Microsoft.Extensions.VectorData.VectorStoreKeyAttribute>, 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 `Description` value for vector searches.
152
149
153
150
1. In the `Program.cs` file, add the following code to create a data set that describes a collection of cloud services:
154
151
@@ -158,10 +155,10 @@ Complete the following steps to create a .NET console app that can:
> <xref:Azure.Identity.DefaultAzureCredential> searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md).
161
+
> <xref:Azure.Identity.DefaultAzureCredential> searches for authentication credentials from your local tooling. You'll need to assign the `Azure AI Developer` role to the account you used to sign in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md).
165
162
166
163
:::zone-end
167
164
@@ -193,7 +190,7 @@ Complete the following steps to create a .NET console app that can:
193
190
194
191
## Clean up resources
195
192
196
-
If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.
193
+
If you no longer need them, delete the Azure OpenAI resource and model deployment.
197
194
198
195
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
199
196
1. Select the Azure OpenAI resource, and then select **Delete**.
0 commit comments