Skip to content

Commit cae644c

Browse files
committed
Modified the code to include retrievers instead of rank
1 parent b250393 commit cae644c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

notebooks/search/02-hybrid-search.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,21 @@
196196
},
197197
{
198198
"cell_type": "code",
199-
"execution_count": 5,
199+
"execution_count": null,
200200
"metadata": {},
201201
"outputs": [],
202202
"source": [
203203
"def pretty_response(response):\n",
204204
" if len(response[\"hits\"][\"hits\"]) == 0:\n",
205205
" print(\"Your search returned no results.\")\n",
206206
" else:\n",
207-
" for hit in response[\"hits\"][\"hits\"]:\n",
207+
" for idx, hit in enumerate(response[\"hits\"][\"hits\"], start=1):\n",
208208
" id = hit[\"_id\"]\n",
209209
" publication_date = hit[\"_source\"][\"publish_date\"]\n",
210-
" rank = hit[\"_rank\"]\n",
210+
" score = hit[\"_score\"]\n",
211211
" title = hit[\"_source\"][\"title\"]\n",
212212
" summary = hit[\"_source\"][\"summary\"]\n",
213-
" pretty_output = f\"\\nID: {id}\\nPublication date: {publication_date}\\nTitle: {title}\\nSummary: {summary}\\nRank: {rank}\"\n",
213+
" pretty_output = f\"\\nID: {id}\\nPublication date: {publication_date}\\nTitle: {title}\\nSummary: {summary}\\nRank: {idx}\\nScore: {score}\"\n",
214214
" print(pretty_output)"
215215
]
216216
},
@@ -231,12 +231,12 @@
231231
"\n",
232232
"We then use [Reciprocal Rank Fusion (RRF)](https://www.elastic.co/guide/en/elasticsearch/reference/current/rrf.html) to balance the scores to provide a final list of documents, ranked in order of relevance. RRF is a ranking algorithm for combining results from different information retrieval strategies.\n",
233233
"\n",
234-
"Note that _score is null, and we instead use _rank to show our top-ranked documents."
234+
"Note: With the retriever API, _score contains the document’s relevance score, and the rank is simply the position in the results (first result is rank 1, etc.)."
235235
]
236236
},
237237
{
238238
"cell_type": "code",
239-
"execution_count": 6,
239+
"execution_count": null,
240240
"metadata": {},
241241
"outputs": [
242242
{
@@ -289,7 +289,7 @@
289289
" \"k\": 5,\n",
290290
" \"num_candidates\": 10,\n",
291291
" },\n",
292-
" rank={\"rrf\": {}},\n",
292+
" retriever={\"rrf\": {}},\n",
293293
")\n",
294294
"\n",
295295
"pretty_response(response)"

0 commit comments

Comments
 (0)