Skip to content

Commit d2b5497

Browse files
committed
Vector quickstart uses API keys
1 parent 760144e commit d2b5497

File tree

3 files changed

+35
-101
lines changed

3 files changed

+35
-101
lines changed

articles/search/search-get-started-rbac.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ ms.author: heidist
77
ms.service: azure-ai-search
88

99
ms.topic: quickstart
10-
ms.date: 11/29/2024
10+
ms.date: 12/03/2024
1111
---
1212

1313
# Quickstart: Connect without keys
1414

15-
Configure Azure AI Search to use Microsoft Entra ID authentication and role-based access control (RBAC) so that you can connect from your local system with your personal identity, using Jupyter notebooks or a REST client to interact with your search service.
15+
Configure Azure AI Search to use Microsoft Entra ID authentication and role-based access control (RBAC) so that you can connect from your local system without API keys, using Jupyter notebooks or a REST client to interact with your search service.
1616

1717
If you stepped through other quickstarts that connect using API keys, this quickstart shows you how to switch to identity-based authentication so that you can avoid hard-coded keys in your example code.
1818

articles/search/search-get-started-vector.md

Lines changed: 32 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ ms.service: azure-ai-search
88
ms.custom:
99
- ignite-2023
1010
ms.topic: quickstart
11-
ms.date: 10/31/2024
11+
ms.date: 12/03/2024
1212
---
1313

1414
# Quickstart: Vector search by using REST
1515

1616
Learn how to use the [Search REST APIs](/rest/api/searchservice) to create, load, and query vectors in Azure AI Search.
1717

18-
In Azure AI Search, a [vector store](vector-store.md) has an index schema that defines vector and nonvector fields, a vector configuration for algorithms that create the embedding space, and settings on vector field definitions that are used in query requests. The [Create Index](/rest/api/searchservice/indexes/create-or-update) API creates the vector store.
18+
In Azure AI Search, a [vector store](vector-store.md) has an index schema that defines vector and nonvector fields, a vector search configuration for algorithms that create the embedding space, and settings on vector field definitions that are evaluated at query time. The [Create Index](/rest/api/searchservice/indexes/create-or-update) REST API creates the vector store.
1919

2020
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
2121

@@ -24,106 +24,51 @@ If you don't have an Azure subscription, create a [free account](https://azure.m
2424
2525
## Prerequisites
2626

27-
- [Visual Studio Code](https://code.visualstudio.com/download) with a [REST client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client). If you need help with getting started, see [Quickstart: Text search using REST](search-get-started-rest.md).
27+
- [Visual Studio Code](https://code.visualstudio.com/download) with a [REST client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client).
2828

2929
- [Azure AI Search](search-what-is-azure-search.md), in any region and on any tier. You can use the Free tier for this quickstart, but Basic or higher is recommended for larger data files. [Create](search-create-service-portal.md) or [find an existing Azure AI Search resource](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices) under your current subscription.
3030

3131
Most existing services support vector search. For a small subset of services created prior to January 2019, an index that contains vector fields fails on creation. In this situation, a new service must be created.
3232

3333
- Optionally, to run the query example that invokes [semantic reranking](semantic-search-overview.md), your search service must be the Basic tier or higher, with [semantic ranker enabled](semantic-how-to-enable-disable.md).
3434

35-
- Optionally, an [Azure OpenAI](https://aka.ms/oai/access) resource with a deployment of `text-embedding-ada-002`. The source `.rest` file includes an optional step for generating new text embeddings, but we provide pregenerated embeddings so that you can omit this dependency.
36-
3735
## Download files
3836

3937
[Download a REST sample](https://github.com/Azure-Samples/azure-search-rest-samples/tree/main/Quickstart-vectors) from GitHub to send the requests in this quickstart. For more information, see [Downloading files from GitHub](https://docs.github.com/get-started/start-your-journey/downloading-files-from-github).
4038

4139
You can also start a new file on your local system and create requests manually by using the instructions in this article.
4240

43-
## Get a search service endpoint
41+
## Get a search endpoint and an API key
42+
43+
You can find the search service endpoint and API keys in the Azure portal.
4444

45-
You can find the search service endpoint in the Azure portal.
45+
Requests to the search endpoint must be authenticated and authorized. You can use API keys or roles for this task. Keys are easier to start with, but roles are more secure. Although we use API keys for this quickstart, we recommend [switching to a keyless connection](search-get-started-rbac.md).
4646

4747
1. Sign in to the [Azure portal](https://portal.azure.com) and [find your search service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices).
4848

4949
1. On the **Overview** home page, find the URL. An example endpoint might look like `https://mydemo.search.windows.net`.
5050

5151
:::image type="content" source="media/search-get-started-rest/get-endpoint.png" lightbox="media/search-get-started-rest/get-endpoint.png" alt-text="Screenshot of the URL property on the overview page.":::
5252

53-
You're pasting this endpoint into the `.rest` or `.http` file in a later step.
54-
55-
## Configure access
56-
57-
Requests to the search endpoint must be authenticated and authorized. You can use API keys or roles for this task. Keys are easier to start with, but roles are more secure.
58-
59-
For a role-based connection, the following instructions have you connecting to Azure AI Search under your identity, not the identity of a client app.
60-
61-
### Option 1: Use keys
62-
63-
Select **Settings** > **Keys** and then copy an admin key. Admin keys are used to add, modify, and delete objects. There are two interchangeable admin keys. Copy either one. For more information, see [Connect to Azure AI Search using key authentication](search-security-api-keys.md).
64-
65-
:::image type="content" source="media/search-get-started-rest/get-api-key.png" lightbox="media/search-get-started-rest/get-api-key.png" alt-text="Screenshot that shows the API keys in the Azure portal.":::
66-
67-
You're pasting this key into the `.rest` or `.http` file in a later step.
68-
69-
### Option 2: Use roles
70-
71-
Make sure your search service is [configured for role-based access](search-security-enable-roles.md). You must have preconfigured [role-assignments for developer access](search-security-rbac.md#assign-roles-for-development). Your role assignments must grant permission to create, load, and query a search index.
72-
73-
In this section, obtain your personal identity token using either the Azure CLI, Azure PowerShell, or the Azure portal.
74-
75-
#### [Azure CLI](#tab/azure-cli)
76-
77-
1. Sign in to Azure CLI.
78-
79-
```azurecli
80-
az login
81-
```
82-
83-
1. Get your personal identity token.
84-
85-
```azurecli
86-
az account get-access-token --scope https://search.azure.com/.default
87-
```
88-
89-
#### [Azure PowerShell](#tab/azure-powershell)
90-
91-
1. Sign in with PowerShell.
92-
93-
```azurepowershell
94-
Connect-AzAccount
95-
```
96-
97-
1. Get your personal identity token.
98-
99-
```azurepowershell
100-
Get-AzAccessToken -ResourceUrl https://search.azure.com
101-
```
102-
103-
#### [Azure portal](#tab/portal)
104-
105-
Use the steps found here: [find the user object ID](/partner-center/find-ids-and-domain-names#find-the-user-object-id) in the Azure portal.
106-
107-
---
53+
1. Select **Settings** > **Keys** and then copy an admin key. [Admin API keys](search-security-api-keys.md) are used to add, modify, and delete objects. There are two interchangeable admin keys. Copy either one.
10854

109-
You're pasting your personal identity token into the `.rest` or `.http` file in a later step.
55+
:::image type="content" source="media/search-get-started-rest/get-api-key.png" lightbox="media/search-get-started-rest/get-api-key.png" alt-text="Screenshot that shows the API keys in the Azure portal.":::
11056

111-
> [!NOTE]
112-
> This section assumes you're using a local client that connects to Azure AI Search on your behalf. An alternative approach is [getting a token for the client app](/entra/identity-platform/v2-oauth2-client-creds-grant-flow), assuming your application is [registered](/entra/identity-platform/quickstart-register-app) with Microsoft Entra ID.
57+
You're pasting these values into a `.rest` or `.http` file in the next step.
11358

11459
## Create a vector index
11560

11661
[Create Index (REST)](/rest/api/searchservice/indexes/create) creates a vector index and sets up the physical data structures on your search service.
11762

11863
The index schema is organized around hotel content. Sample data consists of vector and nonvector names and descriptions of seven fictitious hotels. This schema includes configurations for vector indexing and queries, and for semantic ranking.
11964

120-
1. Open a new text file in Visual Studio Code.
65+
1. Create a new text file in Visual Studio Code.
12166

122-
1. Set variables to the values you collected earlier. This example uses a personal identity token.
67+
1. At the top of the file, add variables for the values you collected earlier.
12368

12469
```http
12570
@baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE
126-
@token = PUT-YOUR-PERSONAL-IDENTITY-TOKEN-HERE
71+
@apiKey = PUT-YOUR-ADMIN-KEY-HERE
12772
```
12873

12974
1. Save the file with a `.rest` or `.http` file extension.
@@ -134,7 +79,7 @@ The index schema is organized around hotel content. Sample data consists of vect
13479
### Create a new index
13580
POST {{baseUrl}}/indexes?api-version=2023-11-01 HTTP/1.1
13681
Content-Type: application/json
137-
Authorization: Bearer {{token}}
82+
api-key: {{apiKey}}
13883
13984
{
14085
"name": "hotels-vector-quickstart",
@@ -237,23 +182,6 @@ The index schema is organized around hotel content. Sample data consists of vect
237182
"efSearch": 500,
238183
"metric": "cosine"
239184
}
240-
},
241-
{
242-
"name": "my-hnsw-vector-config-2",
243-
"kind": "hnsw",
244-
"hnswParameters":
245-
{
246-
"m": 4,
247-
"metric": "euclidean"
248-
}
249-
},
250-
{
251-
"name": "my-eknn-vector-config",
252-
"kind": "exhaustiveKnn",
253-
"exhaustiveKnnParameters":
254-
{
255-
"metric": "cosine"
256-
}
257185
}
258186
],
259187
"profiles": [
@@ -284,9 +212,9 @@ The index schema is organized around hotel content. Sample data consists of vect
284212
}
285213
```
286214
287-
1. Select **Send request**. Recall that you need the REST client to send requests. You should have an `HTTP/1.1 201 Created` response. The response body should include the JSON representation of the index schema.
215+
1. Save the file, and then select **Send request**. You should have an `HTTP/1.1 201 Created` response. The response body should include the JSON representation of the index schema.
288216
289-
Key points:
217+
Key takeaways about this REST API:
290218
291219
- The `fields` collection includes a required key field and text and vector fields (such as `Description` and `DescriptionVector`) for text and vector search. Colocating vector and nonvector fields in the same index enables hybrid queries. For instance, you can combine filters, text search with semantic ranking, and vectors into a single query operation.
292220
- Vector fields must be `type: Collection(Edm.Single)` with `dimensions` and `vectorSearchProfile` properties.
@@ -302,11 +230,15 @@ The URI is extended to include the `docs` collection and the `index` operation.
302230
> [!IMPORTANT]
303231
> The following example isn't runnable code. For readability, we excluded vector values because each one contains 1,536 embeddings, which is too long for this article. If you want to try this step, copy runnable code from the [sample on GitHub](https://github.com/Azure-Samples/azure-search-rest-samples/tree/main/Quickstart-vectors).
304232
233+
1. Paste in a valid request that uploads documents, similar to the example below.
234+
235+
1. Save the file, and then select **Send request**. You should have an `HTTP/1.1 201 Created` response. The response body should include the JSON representation of the search documents.
236+
305237
```http
306238
### Upload documents
307239
POST {{baseUrl}}/indexes/hotels-quickstart-vectors/docs/index?api-version=2023-11-01 HTTP/1.1
308240
Content-Type: application/json
309-
Authorization: Bearer {{token}}
241+
api-key: {{apiKey}}
310242
311243
{
312244
"value": [
@@ -434,7 +366,7 @@ Authorization: Bearer {{token}}
434366
}
435367
```
436368

437-
Key points:
369+
Key takeaways about this REST API:
438370

439371
- Documents in the payload consist of fields defined in the index schema.
440372
- Vector fields contain floating point values. The dimensions attribute has a minimum of 2 and a maximum of 3,072 floating point values each. This quickstart sets the dimensions attribute to 1,536 because that's the size of embeddings generated by the Azure OpenAI **text-embedding-ada-002** model.
@@ -462,13 +394,13 @@ The vector query string is semantically similar to the search string, but it inc
462394
463395
### Single vector search
464396

465-
1. Paste in a POST request to query the search index. Then select **Send request**. The URI is extended to include the `/docs/search` operator.
397+
1. Paste in a POST request to query the search index. Save the file. Then select **Send request**. The URI is extended to include the `/docs/search` operator.
466398

467399
```http
468400
### Run a query
469401
POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1
470402
Content-Type: application/json
471-
Authorization: Bearer {{token}}
403+
api-key: {{apiKey}}
472404
473405
{
474406
"count": true,
@@ -547,7 +479,7 @@ You can add filters, but the filters are applied to the nonvector content in you
547479
### Run a vector query with a filter
548480
POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1
549481
Content-Type: application/json
550-
Authorization: Bearer {{token}}
482+
api-key: {{apiKey}}
551483
552484
{
553485
"count": true,
@@ -620,7 +552,7 @@ Hybrid search consists of keyword queries and vector queries in a single search
620552
### Run a hybrid query
621553
POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1
622554
Content-Type: application/json
623-
Authorization: Bearer {{token}}
555+
api-key: {{apiKey}}
624556
625557
{
626558
"count": true,
@@ -767,7 +699,7 @@ Here's the last query in the collection. This hybrid query with semantic ranking
767699
### Run a hybrid query
768700
POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1
769701
Content-Type: application/json
770-
Authorization: Bearer {{token}}
702+
api-key: {{apiKey}}
771703
772704
{
773705
"count": true,
@@ -854,7 +786,7 @@ Here's the last query in the collection. This hybrid query with semantic ranking
854786
}
855787
```
856788
857-
Key points:
789+
Key points about this REST API:
858790
859791
- Vector search is specified through the `vectors.value` property. Keyword search is specified through the `search` property.
860792
- In a hybrid search, you can integrate vector search with full-text search over keywords. Filters, spell check, and semantic ranking apply to textual content only, and not vectors. In this final query, there's no semantic `answer` because the system didn't produce one that was sufficiently strong.
@@ -872,9 +804,11 @@ You can also try this `DELETE` command:
872804
### Delete an index
873805
DELETE {{baseUrl}}/indexes/hotels-vector-quickstart?api-version=2023-11-01 HTTP/1.1
874806
Content-Type: application/json
875-
Authorization: Bearer {{token}}
807+
api-key: {{apiKey}}
876808
```
877809

878810
## Next steps
879811

880-
As a next step, we recommend that you review the demo code for [Python](https://github.com/Azure/azure-search-vector-samples/tree/main/demo-python), [C#](https://github.com/Azure/azure-search-vector-samples/tree/main/demo-dotnet), or [JavaScript](https://github.com/Azure/azure-search-vector-samples/tree/main/demo-javascript).
812+
As a next step, we recommend learning how to invoke REST API calls [without API keys](search-get-started-rbac.md).
813+
814+
You might also want to review the demo code for [Python](https://github.com/Azure/azure-search-vector-samples/tree/main/demo-python), [C#](https://github.com/Azure/azure-search-vector-samples/tree/main/demo-dotnet), or [JavaScript](https://github.com/Azure/azure-search-vector-samples/tree/main/demo-javascript).

articles/search/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ items:
2626
href: search-get-started-semantic.md
2727
- name: Chat with your data
2828
href: /azure/ai-services/openai/use-your-data-quickstart?context=/azure/search/context/context
29-
- name: Keyless authentication
29+
- name: Connect without keys
3030
href: search-get-started-rbac.md
3131
- name: Portal
3232
items:

0 commit comments

Comments
 (0)