-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
689 additions
and
1,025 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Populate Azure AI Search Index" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import dotenv\n", | ||
"import sys\n", | ||
"\n", | ||
"dotenv.load_dotenv(\".env\")\n", | ||
"sys.path.append(os.path.join(os.getcwd(), \"..\", \"src\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Approach 1: Pull-based\n", | ||
"\n", | ||
"The pull model uses indexers connecting to a supported data source, automatically uploading the data into your index. This is the recommended approach for data sources that are frequently updated." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from search.utilities import SearchClient\n", | ||
"\n", | ||
"# Create search client\n", | ||
"search_client = SearchClient(\n", | ||
" search_endpoint=os.environ[\"AZURE_AI_SEARCH_ENDPOINT\"],\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Generate list of variables to be used in templates\n", | ||
"template_variables = {\n", | ||
" key: value for key, value in os.environ.items() if key.startswith((\"AZURE\"))\n", | ||
"}\n", | ||
"\n", | ||
"# Define template paths\n", | ||
"base_path = os.path.join(os.getcwd(), \"..\", \"src\", \"search\", \"templates\")\n", | ||
"datasource_template_path = os.path.join(base_path, \"product-info\", \"datasource.json\")\n", | ||
"index_template_path = os.path.join(base_path, \"product-info\", \"index.json\")\n", | ||
"skillset_template_path = os.path.join(base_path, \"product-info\", \"skillset.json\")\n", | ||
"indexer_template_path = os.path.join(base_path, \"product-info\", \"indexer.json\")\n", | ||
"\n", | ||
"# List of search assets\n", | ||
"assets = [\n", | ||
" {\n", | ||
" \"type\": \"indexes\",\n", | ||
" \"name\": os.environ[\"AZURE_AI_SEARCH_INDEX_NAME\"],\n", | ||
" \"template_path\": index_template_path,\n", | ||
" \"template_variables\": template_variables,\n", | ||
" },\n", | ||
" {\n", | ||
" \"type\": \"datasources\",\n", | ||
" \"name\": os.environ[\"AZURE_AI_SEARCH_DATASOURCE_NAME\"],\n", | ||
" \"template_path\": datasource_template_path,\n", | ||
" \"template_variables\": template_variables,\n", | ||
" },\n", | ||
" {\n", | ||
" \"type\": \"skillsets\",\n", | ||
" \"name\": os.environ[\"AZURE_AI_SEARCH_SKILLSET_NAME\"],\n", | ||
" \"template_path\": skillset_template_path,\n", | ||
" \"template_variables\": template_variables,\n", | ||
" },\n", | ||
" {\n", | ||
" \"type\": \"indexers\",\n", | ||
" \"name\": os.environ[\"AZURE_AI_SEARCH_INDEXER_NAME\"],\n", | ||
" \"template_path\": indexer_template_path,\n", | ||
" \"template_variables\": template_variables,\n", | ||
" },\n", | ||
"]\n", | ||
"\n", | ||
"# Load search asset templates\n", | ||
"search_client.load_search_management_asset_templates(assets)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create the index\n", | ||
"index_response = search_client.create_search_management_asset(asset_type=\"indexes\")\n", | ||
"\n", | ||
"# Create the data source\n", | ||
"datasource_response = search_client.create_search_management_asset(asset_type=\"datasources\")\n", | ||
"\n", | ||
"# Create skillset to enhance the indexer\n", | ||
"skillset_response = search_client.create_search_management_asset(asset_type=\"skillsets\")\n", | ||
"\n", | ||
"# Create the indexer\n", | ||
"indexer_response = search_client.create_search_management_asset(asset_type=\"indexers\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Run the indexer\n", | ||
"indexer_run_response = search_client.run_indexer()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Run the indexer with reset\n", | ||
"indexer_run_reset_response = search_client.run_indexer(reset_flag=True)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.