3.2 Create Search Index¶
1. Create Search Index Script¶
Let's copy over the create-search-index.py
script into our application source folder.
1 |
|
2. Understand Index Creation¶
Now, let's take a look at what this does.
Click to expand and view the Python Script to create the search index
src/api/create-search-index.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
First the script sets up a search index_client:
- Creates an Azure AI Project Client instance (configured with connection string)
- Retrieves an
embeddings
inference client from the AI project (maps to that model) - Retrieves a
search_connection
object from the AI project instance - Creates an
index_client
search index client using the search connection (key, endpoint)
First it defines the index based on a vector derived from product data fields.
- It maps product name to a title property
- It maps product description to a content property
- It uses HNSW algorithm (cosine distance) for similarity
- It prioritizes "content" for semantic ranking
It then creates the index from CSV and populates it using the index_client.
- It defines an index using the specified name and embeddings model
- It loads CSV and generates vector embeddings for each
description
- It uploads each vectorized document into the pre-defined search index
3. Run Index Creation Script¶
To get the index created in Azure AI Search, run the script described above.
1 |
|
4. Verify Search Index¶
Then verify that the index was created successfully:
- Visit the Azure Portal and look up your Resource Group
- Visit the Azure AI Search resource page from that RG
- Click on "Search Explorer" from the resource overview page
- Click "Search" - verify that you see indexed products