Skip to content

Commit 69aeb89

Browse files
committed
Fix readme and revert relevance
1 parent 099a2d2 commit 69aeb89

File tree

3 files changed

+56
-63
lines changed

3 files changed

+56
-63
lines changed

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AZURE_OPENAI_SERVICE="SERVICE-NAME"
22
AZURE_OPENAI_DEPLOYMENT_NAME=DEPLOYMENT-NAME
3-
AZURE_OPENAI_ADA_DEPLOYMENT=ADA-DEPLOYMENT
3+
AZURE_OPENAI_EMBEDDING_DEPLOYMENT=EMBEDDING-DEPLOYMENT
44
AZURE_SEARCH_SERVICE=SEARCH-SERVICE-NAME
55
AZURE_VISION_ENDPOINT=https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com
66
AZURE_TENANT_ID=TENANT-ID

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ This repository contains many notebooks that explain how Azure AI Search works,
2525

2626
4. Create a Python virtual environment or open the project in a container.
2727

28-
```shell
29-
AZURE_TENANT_ID=YOUR-TENANT-ID
30-
```
31-
32-
5. Create a Python virtual environment or open the project in a container.
33-
34-
6. Install the requirements:
28+
5. Install the requirements:
3529

3630
```shell
3731
pip install -r requirements.txt

search_relevance.ipynb

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": 5,
19+
"execution_count": null,
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
@@ -30,7 +30,7 @@
3030
"\n",
3131
"dotenv.load_dotenv()\n",
3232
"\n",
33-
"azure_credential = azure.identity.AzureDeveloperCliCredential(tenant_id=os.getenv(\"AZURE_TENANT_ID\"))\n",
33+
"azure_credential = azure.identity.DefaultAzureCredential()\n",
3434
"\n",
3535
"# Initialize Azure OpenAI client\n",
3636
"AZURE_OPENAI_SERVICE = os.getenv(\"AZURE_OPENAI_SERVICE\")\n",
@@ -72,9 +72,9 @@
7272
"name": "stdout",
7373
"output_type": "stream",
7474
"text": [
75-
"Score: 0.81581\tMatching text: Not found\n",
76-
"Score: 0.80998\tMatching text: Not found\n",
77-
"Score: 0.80965\tMatching text: Not found\n"
75+
"Score: 0.81510\tMatching text: Not found\n",
76+
"Score: 0.80934\tMatching text: Not found\n",
77+
"Score: 0.80891\tMatching text: Not found\n"
7878
]
7979
}
8080
],
@@ -94,141 +94,140 @@
9494
"cell_type": "markdown",
9595
"metadata": {},
9696
"source": [
97-
"## Keyword search"
97+
"Compare to a text search for same query:"
9898
]
9999
},
100100
{
101101
"cell_type": "code",
102-
"execution_count": 17,
102+
"execution_count": 3,
103103
"metadata": {},
104104
"outputs": [
105105
{
106106
"name": "stdout",
107107
"output_type": "stream",
108108
"text": [
109-
"Score: 15.90960\tContent:Soaker Hose 25-foot SKU: GOHOS002 Price: $25.00 Category: GARDEN & OUTDOOR > HOSES <figure><figcaption>1.1 <br>The image shows a coiled black hose o\n",
110-
"Score: 10.33728\tContent:Garden Hose 50-foot SKU: GOHOS001 Price: $32.00 Category: GARDEN & OUTDOOR > HOSES <figure><figcaption>1.1 <br>The image shows a coiled metal hose \n",
111-
"Score: 7.63983\tContent: Heavy-duty garden hose with brass fittings and kink-resistant construction.\n",
112-
"Score: 7.04795\tContent: Porous soaker hose for efficient water delivery directly to plant roots.\n",
113-
"Score: 4.35788\tContent:# Liquid-Tight Conduit SKU: ELCO000010 Price: $20.00 Category: ELECTRICAL > CONDUIT <figure><figcaption>1.1 <br>The image shows a coiled, metallic,\n"
109+
"Score: 4.14542\tMatching text: $45.00</td><td>$55.00</td></tr><tr><td>Employee +1</td><td>$65.00</td><td>$71.00</td></tr><tr><td>Employee +2 or more</td><td>$78.00</td><td>$89.00</td></tr></table> Next Steps We hope that this information has been helpful in understanding the differences between Northwind Health Plus and Northwind Standard. We are confident that you will find the right plan for you and your family. Thank you for choosing Contoso Electronics!\n",
110+
"Score: 3.37283\tMatching text: Not found\n"
114111
]
115112
}
116113
],
117114
"source": [
118-
"search_query = \"25 foot hose\"\n",
119-
"r = search_client.search(search_text=search_query, top=5)\n",
115+
"r = search_client.search(search_query, top=3)\n",
120116
"for doc in r:\n",
121-
" content = doc[\"content\"].replace(\"\\n\", \" \")[:150]\n",
122-
" print(f\"Score: {doc['@search.score']:.5f}\\tContent:{content}\")"
117+
" found_content = \"Not found\"\n",
118+
" if search_query.lower() in doc['content'].lower():\n",
119+
" found_content = doc['content'][doc['content'].lower().find(search_query.lower()):].replace(\"\\n\", \" \")\n",
120+
" print(f\"Score: {doc['@search.score']:.5f}\\tMatching text: {found_content}\")"
123121
]
124122
},
125123
{
126124
"cell_type": "markdown",
127125
"metadata": {},
128126
"source": [
129-
"## Vector search\n"
127+
"#### Hybrid retrieval\n",
128+
"\n",
129+
"Uses RRF to combine vector and text results."
130130
]
131131
},
132132
{
133133
"cell_type": "code",
134-
"execution_count": 18,
134+
"execution_count": 4,
135135
"metadata": {},
136136
"outputs": [
137137
{
138138
"name": "stdout",
139139
"output_type": "stream",
140140
"text": [
141-
"Score: 0.70706\tContent:Misting Sprinkler Kit SKU: GOSPR004 Price: $28.00 Category: GARDEN & OUTDOOR > SPRINKLERS <figure><figcaption>1.1 <br>The image shows an arrangement\n",
142-
"Score: 0.66958\tContent:In-Ground Sprinkler Head SKU: GOSPR005 Price: $12.00 Category: GARDEN & OUTDOOR > SPRINKLERS <figure><figcaption>1.1 <br>The image shows a black cyl\n",
143-
"Score: 0.66597\tContent:Soaker Hose 25-foot SKU: GOHOS002 Price: $25.00 Category: GARDEN & OUTDOOR > HOSES <figure><figcaption>1.1 <br>The image shows a coiled black hose o\n"
141+
"Score: 0.03254\tMatching text: $45.00</td><td>$55.00</td></tr><tr><td>Employee +1</td><td>$65.00</td><td>$71.00</td></tr><tr><td>Employee +2 or more</td><td>$78.00</td><td>$89.00</td></tr></table> Next Steps We hope that this information has been helpful in understanding the differences between Northwind Health Plus and Northwind Standard. We are confident that you will find the right plan for you and your family. Thank you for choosing Contoso Electronics!\n",
142+
"Score: 0.03110\tMatching text: Not found\n",
143+
"Score: 0.01667\tMatching text: Not found\n",
144+
"Score: 0.01639\tMatching text: Not found\n",
145+
"Score: 0.01613\tMatching text: Not found\n",
146+
"Score: 0.01562\tMatching text: Not found\n",
147+
"Score: 0.01538\tMatching text: Not found\n",
148+
"Score: 0.01515\tMatching text: Not found\n",
149+
"Score: 0.01493\tMatching text: Not found\n",
150+
"Score: 0.01449\tMatching text: Not found\n"
144151
]
145152
}
146153
],
147154
"source": [
148-
"search_query = \"garden watering supplies\"\n",
149155
"search_vector = get_embedding(search_query)\n",
150-
"r = search_client.search(None, top=3, vector_queries=[\n",
151-
" VectorizedQuery(vector=search_vector, k_nearest_neighbors=50, fields=\"embedding3\")])\n",
156+
"r = search_client.search(search_query, top=15, vector_queries=[\n",
157+
" VectorizedQuery(vector=search_vector, k_nearest_neighbors=10, fields=\"embedding\")])\n",
152158
"for doc in r:\n",
153-
" content = doc[\"content\"].replace(\"\\n\", \" \")[:150]\n",
154-
" print(f\"Score: {doc['@search.score']:.5f}\\tContent:{content}\")"
159+
" found_content = \"Not found\"\n",
160+
" if search_query in doc['content']:\n",
161+
" found_content = doc['content'][doc['content'].find(search_query):].replace(\"\\n\", \" \")\n",
162+
" print(f\"Score: {doc['@search.score']:.5f}\\tMatching text: {found_content}\")"
155163
]
156164
},
157165
{
158166
"cell_type": "markdown",
159167
"metadata": {},
160168
"source": [
161-
"## Hybrid search with RRF"
169+
"#### Hybrid ranking is not always optimal"
162170
]
163171
},
164172
{
165173
"cell_type": "code",
166-
"execution_count": 19,
174+
"execution_count": 5,
167175
"metadata": {},
168176
"outputs": [
169177
{
170178
"name": "stdout",
171179
"output_type": "stream",
172180
"text": [
173-
"Score: 0.03150\tContent: Complete misting system for cooling and plant watering with multiple nozzles.\n",
174-
"Score: 0.03137\tContent:Misting Sprinkler Kit SKU: GOSPR004 Price: $28.00 Category: GARDEN & OUTDOOR > SPRINKLERS <figure><figcaption>1.1 <br>The image shows an arrangement\n",
175-
"Score: 0.03089\tContent:Landscape Spotlight Kit SKU: GOOTD004 Price: $52.00 Category: GARDEN & OUTDOOR > OUTDOOR LIGHTING <figure><figcaption>1.1 <br>The image shows a nea\n",
176-
"Score: 0.03078\tContent: Heavy-duty garden hose with brass fittings and kink-resistant construction.\n",
177-
"Score: 0.03062\tContent:Soaker Hose 25-foot SKU: GOHOS002 Price: $25.00 Category: GARDEN & OUTDOOR > HOSES <figure><figcaption>1.1 <br>The image shows a coiled black hose o\n",
178-
"Score: 0.03054\tContent:Garden Hose 50-foot SKU: GOHOS001 Price: $32.00 Category: GARDEN & OUTDOOR > HOSES <figure><figcaption>1.1 <br>The image shows a coiled metal hose \n",
179-
"Score: 0.03048\tContent:In-Ground Sprinkler Head SKU: GOSPR005 Price: $12.00 Category: GARDEN & OUTDOOR > SPRINKLERS <figure><figcaption>1.1 <br>The image shows a black cyl\n",
180-
"Score: 0.02899\tContent: Low-voltage landscape lighting kit for highlighting plants and features.\n",
181-
"Score: 0.01667\tContent: Specialized drawer unit with adjustable dividers for craft and hobby supplies.\n",
182-
"Score: 0.01613\tContent:Craft Storage Drawers SKU: SOPLS005 Price: $42.00 Category: STORAGE & ORGANIZATION > PLASTIC DRAWERS <figure><figcaption>1.1 <br>The image shows a w\n",
183-
"Score: 0.01587\tContent: Porous soaker hose for efficient water delivery directly to plant roots.\n",
184-
"Score: 0.01538\tContent: Space-saving wall-mounted cabinet for tools and supplies with key lock.\n",
185-
"Score: 0.01493\tContent:String Lights 48-foot SKU: GOOTD003 Price: $28.00 Category: GARDEN & OUTDOOR > OUTDOOR LIGHTING <figure><figcaption>1.1 <br>The image shows three h\n",
186-
"Score: 0.01493\tContent: Pop-up sprinkler head for permanent irrigation systems with adjustable arc.\n",
187-
"Score: 0.01389\tContent:Solar Path Light Set SKU: GOOTD001 Price: $35.00 Category: GARDEN & OUTDOOR > OUTDOOR LIGHTING <figure><figcaption>1.1 <br>The image shows a metalli\n"
181+
"Score: 0.03252\t\tContent: PerksPlus is not only designed to support employees' physical health, but also their mental health. Regular exercise has been shown to reduce stress,\n",
182+
"Score: 0.03105\t\tContent: Under the Northwind Health Plus plan, habilitation services are covered up to a certain dollar amount and number of visits. This amount and the numbe\n",
183+
"Score: 0.02797\t\tContent: Occupational Therapy Occupational therapy helps individuals develop, maintain, or restore skills for daily living and work. It can help individuals w\n",
184+
"Score: 0.02766\t\tContent: Some of the lessons covered under PerksPlus include: · Skiing and snowboarding lessons · Scuba diving lessons · Surfing lessons · Horseback riding le\n",
185+
"Score: 0.02290\t\tContent: Talk to your doctor or health care provider about the trial and ask any questions you may have. · Ask about the potential risks and benefits of parti\n"
188186
]
189187
}
190188
],
191189
"source": [
190+
"search_query = \"learning about underwater activities\"\n",
192191
"search_vector = get_embedding(search_query)\n",
193-
"r = search_client.search(search_query, top=15, vector_queries=[\n",
194-
" VectorizedQuery(vector=search_vector, k_nearest_neighbors=10, fields=\"embedding3\")])\n",
192+
"r = search_client.search(search_query, top=5, vector_queries=[\n",
193+
" VectorizedQuery(vector=search_vector, k_nearest_neighbors=10, fields=\"embedding\")])\n",
195194
"for doc in r:\n",
196195
" content = doc[\"content\"].replace(\"\\n\", \" \")[:150]\n",
197-
" print(f\"Score: {doc['@search.score']:.5f}\\tContent:{content}\")"
196+
" print(f\"Score: {doc['@search.score']:.5f}\\t\\tContent: {content}\")"
198197
]
199198
},
200199
{
201200
"cell_type": "markdown",
202201
"metadata": {},
203202
"source": [
204-
"## Hybrid with re-ranker"
203+
"#### Hybrid + semantic reranking 🎉"
205204
]
206205
},
207206
{
208207
"cell_type": "code",
209-
"execution_count": 15,
208+
"execution_count": 6,
210209
"metadata": {},
211210
"outputs": [
212211
{
213212
"name": "stdout",
214213
"output_type": "stream",
215214
"text": [
216-
"Score: 0.03125\tReranker: 2.49573\tContent: Heavy-duty garden hose with brass fittings and kink-resistant construction.\n",
217-
"Score: 0.03102\tReranker: 2.46081\tContent: Garden Hose 50-foot SKU: GOHOS001 Price: $32.00 Category: GARDEN & OUTDOOR > HOSES <figure><figcaption>1.1 <br>The image shows a coiled metal hose \n",
218-
"Score: 0.03159\tReranker: 2.43777\tContent: Misting Sprinkler Kit SKU: GOSPR004 Price: $28.00 Category: GARDEN & OUTDOOR > SPRINKLERS <figure><figcaption>1.1 <br>The image shows an arrangement\n",
219-
"Score: 0.03200\tReranker: 2.28960\tContent: Complete misting system for cooling and plant watering with multiple nozzles.\n",
220-
"Score: 0.01538\tReranker: 2.22509\tContent: Pop-up sprinkler head for permanent irrigation systems with adjustable arc.\n"
215+
"Score: 0.02766\tReranker: 1.94936\tContent: Some of the lessons covered under PerksPlus include: · Skiing and snowboarding lessons · Scuba diving lessons · Surfing lessons · Horseback riding le\n",
216+
"Score: 0.03252\tReranker: 1.77669\tContent: PerksPlus is not only designed to support employees' physical health, but also their mental health. Regular exercise has been shown to reduce stress,\n",
217+
"Score: 0.02455\tReranker: 0.59237\tContent: By taking the time to research providers in-network with Northwind Health Plus and keeping track of your medical records and tests, you can make sure\n",
218+
"Score: 0.03105\tReranker: 0.58931\tContent: Under the Northwind Health Plus plan, habilitation services are covered up to a certain dollar amount and number of visits. This amount and the numbe\n",
219+
"Score: 0.02153\tReranker: 0.49740\tContent: This position will be responsible for designing and implementing innovative solutions to maximize product performance and optimize customer satisfact\n"
221220
]
222221
}
223222
],
224223
"source": [
225-
"search_query = \"garden watering supplies\"\n",
224+
"search_query = \"learning about underwater activities\"\n",
226225
"search_vector = get_embedding(search_query)\n",
227226
"r = search_client.search(\n",
228227
" search_query,\n",
229228
" top=5, \n",
230229
" vector_queries=[\n",
231-
" VectorizedQuery(vector=search_vector, k_nearest_neighbors=50, fields=\"embedding3\")],\n",
230+
" VectorizedQuery(vector=search_vector, k_nearest_neighbors=50, fields=\"embedding\")],\n",
232231
" query_type=\"semantic\",\n",
233232
" semantic_configuration_name=\"default\")\n",
234233
"\n",

0 commit comments

Comments
 (0)