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
This repo has Python code examples for several articles each in a separate subfolder.
46
+
This repo has Python code examples for several articles each in a separate subfolder.
47
47
48
48
1. In Visual Studio Code, open the subfolder `Quickstart-Vector-Search`.
49
49
50
-
There are three files in this folder:
50
+
There are three files in this folder:
51
51
52
-
-`vector-search-quickstart.ipynb`
53
-
-`requirements.txt`
54
-
-`sample.env`
52
+
-`vector-search-quickstart.ipynb`
53
+
-`requirements.txt`
54
+
-`sample.env`
55
55
56
56
1. Rename the `sample.env` file to `.env` and modify the values in the `.env` file.
57
57
58
58
Use the search service URL as the `AZURE_SEARCH_ENDPOINT`. You can find the url in the [Azure portal](https://portal.azure.com). Go to your Azure AI Search service, on the **Overview** page, look for the URL field. An example endpoint might look like `https://mydemo.search.windows.net`.
59
59
60
60
Finally, choose a new `AZURE_SEARCH_INDEX_NAME` name, or use the one provided in the file.
61
61
62
-
1. In Visual Studio Code, work in an environment. On the **View** menu, select **Terminal...**, or select <kbd>Ctrl</kbd>+<kbd>`</kbd>.
62
+
1. In Visual Studio Code, work in an environment. On the **View** menu, select **Terminal...**, or select Ctrl+`.
63
63
64
64
1. Run the following commands in the terminal:
65
65
@@ -88,7 +88,7 @@ This quickstart uses `DefaultAzureCredential`, which simplifies authentication i
88
88
> If this is the first time you have used a Jupyter Notebook (.ipynb) in Visual Studio Code, you will be prompted to install the Jupyter Notebook kernel and possibly other tools. Choose to install the suggested tools to continue with this quickstart.
89
89
90
90
91
-
1. Find the cell below section titled "Install packages and set variables" and select the **Execute Cell (`Ctrl` + `Alt` + `Enter`)** button (which looks like a typical run button) to the left of the cell. Executing the cell loads the environment variables, creates the DefaultAzureCredential, and prints values to the output to confirm that the notebook's dependencies and `.env` are set up correctly.
91
+
1. Find the cell below section titled "Install packages and set variables" and select the **Execute Cell (Ctrl+Alt+Enter)** button (which looks like a typical run button) to the left of the cell. Executing the cell loads the environment variables, creates the DefaultAzureCredential, and prints values to the output to confirm that the notebook's dependencies and `.env` are set up correctly.
92
92
93
93
```python
94
94
# Load environment variables from .env file
@@ -226,7 +226,7 @@ The code in the `vector-search-quickstart.ipynb` uses several methods from the `
226
226
227
227
Key takeaways when creating vector index with the `azure.search.documents`:
228
228
229
-
- You define an index by creating a list of fields. Each field is created using a helper method that defines the field type and its settings.
229
+
- You define an index by creating a list of fields. Each field is created using a helper method that defines the field type and its settings.
230
230
231
231
- This particular index supports multiple search capabilities, such as:
@@ -246,50 +246,50 @@ In Azure AI Search, the index stores all searchable content, while the search en
246
246
247
247
1. Find the cell below section titled "Create documents payload" and execute the cell. This cell contains the following code (truncated for brevity):
248
248
249
-
```python
250
-
# Create a documents payload
251
-
documents = [
252
-
{
253
-
"@search.action": "mergeOrUpload",
254
-
"HotelId": "1",
255
-
"HotelName": "Stay-Kay City Hotel",
256
-
"Description": "This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
257
-
"DescriptionVector": [-0.048865054,-0.020307425,
258
-
# <truncated>
259
-
-0.018120624,-0.012772904],
260
-
"Category": "Boutique",
261
-
"Tags": [
262
-
"view",
263
-
"air conditioning",
264
-
"concierge"
265
-
],
266
-
"ParkingIncluded": "false",
267
-
"LastRenovationDate": "2022-01-18T00:00:00Z",
268
-
"Rating": 3.60,
269
-
"Address": {
270
-
"StreetAddress": "677 5th Ave",
271
-
"City": "New York",
272
-
"StateProvince": "NY",
273
-
"PostalCode": "10022",
274
-
"Country": "USA"
275
-
},
276
-
"Location": {
277
-
"type": "Point",
278
-
"coordinates": [
279
-
-73.975403,
280
-
40.760586
281
-
]
282
-
}
283
-
},
284
-
# <truncated>
285
-
]
249
+
```python
250
+
# Create a documents payload
251
+
documents = [
252
+
{
253
+
"@search.action": "mergeOrUpload",
254
+
"HotelId": "1",
255
+
"HotelName": "Stay-Kay City Hotel",
256
+
"Description": "This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
257
+
"DescriptionVector": [-0.048865054,-0.020307425,
258
+
# <truncated>
259
+
-0.018120624,-0.012772904],
260
+
"Category": "Boutique",
261
+
"Tags": [
262
+
"view",
263
+
"air conditioning",
264
+
"concierge"
265
+
],
266
+
"ParkingIncluded": "false",
267
+
"LastRenovationDate": "2022-01-18T00:00:00Z",
268
+
"Rating": 3.60,
269
+
"Address": {
270
+
"StreetAddress": "677 5th Ave",
271
+
"City": "New York",
272
+
"StateProvince": "NY",
273
+
"PostalCode": "10022",
274
+
"Country": "USA"
275
+
},
276
+
"Location": {
277
+
"type": "Point",
278
+
"coordinates": [
279
+
-73.975403,
280
+
40.760586
281
+
]
282
+
}
283
+
},
284
+
# <truncated>
285
+
]
286
286
```
287
-
287
+
288
288
This cell loads a variable named `documents` with a JSON object describing each document, along with the vectorized version of the article's description. This vector enables similarity search, where matching is based on meaning rather than exact keywords.
289
-
289
+
290
290
> [!IMPORTANT]
291
291
> The code in this example isn't runnable. Several characters or lines are removed for brevity. Instead, run the code in the Jupyter notebook.
292
-
292
+
293
293
1. Find the cell below section titled "Upload the documents" and execute the cell. This cell contains the following code (truncated for brevity):
294
294
295
295
```python
@@ -360,7 +360,7 @@ The first example demonstrates a basic scenario where you want to find document
360
360
361
361
1. Find the cell below section titled "Single vector search" and execute the cell. This block contains the request to query the search index.
362
362
363
-
```python
363
+
```python
364
364
# IMPORTANT: Before you run this code, make sure the documents were successfully
365
365
# created in the previous step. Sometimes it may take a few seconds for the index to be ready.
366
366
# Check the "Document count" for the index in the Azure portal.
@@ -390,9 +390,8 @@ The first example demonstrates a basic scenario where you want to find document
390
390
exceptExceptionas ex:
391
391
print("Vector search failed:", ex)
392
392
else:
393
-
print("No vector loaded, skipping search.")
394
-
395
-
```
393
+
print("No vector loaded, skipping search.")
394
+
```
396
395
397
396
This vector query is shortened for brevity. The `vectorQueries.vector` contains the vectorized text of the query input, `fields` determines which vector fields are searched, and `k` specifies the number of nearest neighbors to return.
398
397
@@ -498,9 +497,9 @@ You can add filters, but the filters are applied to the nonvector content in you
498
497
else:
499
498
print("No vector loaded, skipping search.")
500
499
```
501
-
502
-
The query was the same as the previous [single vector search example](#single-vector-search), but it includes a post-processing exclusion filter and returns only the two hotels within 300 kilometers.
503
-
500
+
501
+
The query was the same as the previous [single vector search example](#single-vector-search), but it includes a post-processing exclusion filter and returns only the two hotels within 300 kilometers.
502
+
504
503
```output
505
504
Total semantic hybrid results: 2
506
505
- HotelId: 48
@@ -614,10 +613,10 @@ Hybrid search consists of keyword queries and vector queries in a single search
614
613
"HotelName": "Luxury Lion Resort",
615
614
"Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort"
616
615
},
617
-
```
616
+
```
618
617
619
618
In the vector-only query, which uses HNSW for finding matches, the Sublime Palace Hotel drops to fourth position. Historic Lion, which was second in the full-text search and third in the vector search, doesn't experience the same range of fluctuation, so it appears as a top match in a homogenized result set.
0 commit comments