ama2aifusion commited on
Commit
97d7241
·
verified ·
1 Parent(s): 1e90877

Upload final_agent.ipynb

Browse files
Files changed (1) hide show
  1. notebooks/final_agent.ipynb +501 -0
notebooks/final_agent.ipynb ADDED
@@ -0,0 +1,501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "e5270bcc",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Final project of Agents course: An Agent that response the GAIA benchmark\n",
9
+ "\n",
10
+ "In this notebook, **we're going to read the GAIA questions from metadata and we'll store in a chroma database to use as retriever**.\n",
11
+ "\n",
12
+ "This notebook is part of the <a href=\"https://www.hf.co/learn/agents-course\">Hugging Face Agents Course</a>, a free course from beginner to expert, where you learn to build Agents.\n",
13
+ "\n",
14
+ "## What we'll do\n",
15
+ "\n",
16
+ "In this notebook, we'll do:\n",
17
+ "\n",
18
+ "1. Reading json metadata with GAIA questions\n",
19
+ "2. Creating chroma vector store\n",
20
+ "3. Querying the database and converting to a retriever to search using\n"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "id": "1e1d8e79",
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "data": {
31
+ "text/plain": [
32
+ "True"
33
+ ]
34
+ },
35
+ "execution_count": 9,
36
+ "metadata": {},
37
+ "output_type": "execute_result"
38
+ }
39
+ ],
40
+ "source": [
41
+ "import os\n",
42
+ "import json\n",
43
+ "from dotenv import load_dotenv\n",
44
+ "from langchain_huggingface import HuggingFaceEmbeddings\n",
45
+ "from langchain_chroma import Chroma\n",
46
+ "import random\n",
47
+ "\n",
48
+ "# from langchain.schema import Document\n",
49
+ "from langchain_core.documents import Document\n",
50
+ "from uuid import uuid4\n",
51
+ "\n",
52
+ "load_dotenv()\n"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 2,
58
+ "id": "bf2a78a5",
59
+ "metadata": {},
60
+ "outputs": [],
61
+ "source": [
62
+ "os.chdir(os.path.abspath(\"..\"))"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "markdown",
67
+ "id": "c0513724",
68
+ "metadata": {},
69
+ "source": [
70
+ "<div style=\"background-color:lightblue; color:black; font-weight:bold\">\n",
71
+ "\n",
72
+ "## 1. Reading json metadata\n",
73
+ "\n",
74
+ "</div>\n"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": 3,
80
+ "id": "c8f343d6",
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": [
84
+ "# Load the metadata.jsonl file\n",
85
+ "with open(\"data/metadata.jsonl\", \"r\") as jsonl_file:\n",
86
+ " json_list = list(jsonl_file)\n",
87
+ "\n",
88
+ "json_QA = []\n",
89
+ "for json_str in json_list:\n",
90
+ " json_data = json.loads(json_str)\n",
91
+ " json_QA.append(json_data)\n"
92
+ ]
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "execution_count": null,
97
+ "id": "e7191ac5",
98
+ "metadata": {},
99
+ "outputs": [
100
+ {
101
+ "name": "stdout",
102
+ "output_type": "stream",
103
+ "text": [
104
+ "==================================================\n",
105
+ "Task ID: 0bdb7c40-671d-4ad1-9ce3-986b159c0ddc\n",
106
+ "Question: In NASA's Astronomy Picture of the Day on 2006 January 21, two astronauts are visible, with one appearing much smaller than the other. As of August 2023, out of the astronauts in the NASA Astronaut Group that the smaller astronaut was a member of, which one spent the least time in space, and how many minutes did he spend in space, rounded to the nearest minute? Exclude any astronauts who did not spend any time in space. Give the last name of the astronaut, separated from the number of minutes by a semicolon.\n",
107
+ "Level: 3\n",
108
+ "Final Answer: White; 5876\n",
109
+ "Annotator Metadata: \n",
110
+ " ├── Steps: \n",
111
+ " │ ├── 1. Use search engine to search for \"NASA's Astronomy Picture of the Day 2006 January 21\".\n",
112
+ " │ ├── 2. Open the link to the image.\n",
113
+ " │ ├── 3. Read the explanation to find that the image is of astronaut Charles \"Pete\" Conrad reflected in the helmet of astronaut Alan Bean.\n",
114
+ " │ ├── 4. Observe that the smaller astronaut in the image is the one reflected in the other's helmet, so the smaller astronaut must be Charles \"Pete\" Conrad.\n",
115
+ " │ ├── 5. Go to the Wikipedia page for Charles \"Pete\" Conrad.\n",
116
+ " │ ├── 6. Search for \"Astronaut Group\" to find that Conrad was a member of NASA Astronaut Group 2.\n",
117
+ " │ ├── 7. Open the Wikipedia pages for each member of NASA Astronaut Group 2.\n",
118
+ " │ ├── 8. For those who are not deceased, go to View history and select the latest version of their Wikipedia page as of August 2023.\n",
119
+ " │ ├── 9. Compare the times listed in the infobox of each astronaut's Wikipedia page under \"Time in space\", observing that Ed White has the least time in space with 4d 01h 56m, but also that Elliott See does not have a listed \"Time in space\".\n",
120
+ " │ ├── 10. Read through Elliot See's Wikipedia article to find that he died in an accident before his first space flight, so he should be excluded, making Ed White's 4d 01h 56m the least amount of time in space.\n",
121
+ " │ ├── 11. Convert 4d 01h 56m to minutes: 4d * 24h/d * 60m/h + 1h * 60m/h + 56m = 5,876m\n",
122
+ " │ ├── 12. Format the final answer as specified: White; 5,876\n",
123
+ " ├── Number of steps: 12\n",
124
+ " ├── How long did this take?: 10\n",
125
+ " ├── Tools:\n",
126
+ " │ ├── 1. Web browser\n",
127
+ " │ ├── 2. Search engine\n",
128
+ " │ ├── 3. Image processing tools\n",
129
+ " │ ├── 4. Calculator\n",
130
+ " └── Number of tools: 4\n",
131
+ "==================================================\n"
132
+ ]
133
+ }
134
+ ],
135
+ "source": [
136
+ "# randomly select 3 samples\n",
137
+ "# {\"task_id\": \"c61d22de-5f6c-4958-a7f6-5e9707bd3466\", \"Question\": \"A paper about AI regulation that was originally submitted to arXiv.org in June 2022 shows a figure with three axes, where each axis has a label word at both ends. Which of these words is used to describe a type of society in a Physics and Society article submitted to arXiv.org on August 11, 2016?\", \"Level\": 2, \"Final answer\": \"egalitarian\", \"file_name\": \"\", \"Annotator Metadata\": {\"Steps\": \"1. Go to arxiv.org and navigate to the Advanced Search page.\\n2. Enter \\\"AI regulation\\\" in the search box and select \\\"All fields\\\" from the dropdown.\\n3. Enter 2022-06-01 and 2022-07-01 into the date inputs, select \\\"Submission date (original)\\\", and submit the search.\\n4. Go through the search results to find the article that has a figure with three axes and labels on each end of the axes, titled \\\"Fairness in Agreement With European Values: An Interdisciplinary Perspective on AI Regulation\\\".\\n5. Note the six words used as labels: deontological, egalitarian, localized, standardized, utilitarian, and consequential.\\n6. Go back to arxiv.org\\n7. Find \\\"Physics and Society\\\" and go to the page for the \\\"Physics and Society\\\" category.\\n8. Note that the tag for this category is \\\"physics.soc-ph\\\".\\n9. Go to the Advanced Search page.\\n10. Enter \\\"physics.soc-ph\\\" in the search box and select \\\"All fields\\\" from the dropdown.\\n11. Enter 2016-08-11 and 2016-08-12 into the date inputs, select \\\"Submission date (original)\\\", and submit the search.\\n12. Search for instances of the six words in the results to find the paper titled \\\"Phase transition from egalitarian to hierarchical societies driven by competition between cognitive and social constraints\\\", indicating that \\\"egalitarian\\\" is the correct answer.\", \"Number of steps\": \"12\", \"How long did this take?\": \"8 minutes\", \"Tools\": \"1. Web browser\\n2. Image recognition tools (to identify and parse a figure with three axes)\", \"Number of tools\": \"2\"}}\n",
138
+ "# random.seed(42)\n",
139
+ "random_samples = random.sample(json_QA, 1)\n",
140
+ "for sample in random_samples:\n",
141
+ " print(\"=\" * 50)\n",
142
+ " print(f\"Task ID: {sample['task_id']}\")\n",
143
+ " print(f\"Question: {sample['Question']}\")\n",
144
+ " print(f\"Level: {sample['Level']}\")\n",
145
+ " print(f\"Final Answer: {sample['Final answer']}\")\n",
146
+ " print(\"Annotator Metadata: \")\n",
147
+ " print(\" ├── Steps: \")\n",
148
+ " for step in sample[\"Annotator Metadata\"][\"Steps\"].split(\"\\n\"):\n",
149
+ " print(f\" │ ├── {step}\")\n",
150
+ " print(f\" ├── Number of steps: {sample['Annotator Metadata']['Number of steps']}\")\n",
151
+ " print(\n",
152
+ " f\" ├── How long did this take?: {sample['Annotator Metadata']['How long did this take?']}\"\n",
153
+ " )\n",
154
+ " print(\" ├── Tools:\")\n",
155
+ " for tool in sample[\"Annotator Metadata\"][\"Tools\"].split(\"\\n\"):\n",
156
+ " print(f\" │ ├── {tool}\")\n",
157
+ " print(f\" └── Number of tools: {sample['Annotator Metadata']['Number of tools']}\")\n",
158
+ "print(\"=\" * 50)\n"
159
+ ]
160
+ },
161
+ {
162
+ "cell_type": "markdown",
163
+ "id": "81c30287",
164
+ "metadata": {},
165
+ "source": [
166
+ "<div style=\"background-color:lightblue; color:black; font-weight:bold\">\n",
167
+ "\n",
168
+ "## 2. Creating chroma vector store\n",
169
+ "\n",
170
+ "</div>\n"
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "execution_count": null,
176
+ "id": "046462f4",
177
+ "metadata": {},
178
+ "outputs": [
179
+ {
180
+ "data": {
181
+ "application/vnd.jupyter.widget-view+json": {
182
+ "model_id": "87ec1aea91cf4cf799c882f649ef7e8c",
183
+ "version_major": 2,
184
+ "version_minor": 0
185
+ },
186
+ "text/plain": [
187
+ "modules.json: 0%| | 0.00/349 [00:00<?, ?B/s]"
188
+ ]
189
+ },
190
+ "metadata": {},
191
+ "output_type": "display_data"
192
+ },
193
+ {
194
+ "name": "stderr",
195
+ "output_type": "stream",
196
+ "text": [
197
+ "c:\\Users\\ee5011\\Anaconda3\\envs\\llm-huggingface-agents-course-env\\Lib\\site-packages\\huggingface_hub\\file_download.py:143: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\ee5011\\.cache\\huggingface\\hub\\models--sentence-transformers--all-mpnet-base-v2. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n",
198
+ "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n",
199
+ " warnings.warn(message)\n"
200
+ ]
201
+ },
202
+ {
203
+ "data": {
204
+ "application/vnd.jupyter.widget-view+json": {
205
+ "model_id": "e0df64b800c14d0eaca2214438eaf4e0",
206
+ "version_major": 2,
207
+ "version_minor": 0
208
+ },
209
+ "text/plain": [
210
+ "config_sentence_transformers.json: 0%| | 0.00/116 [00:00<?, ?B/s]"
211
+ ]
212
+ },
213
+ "metadata": {},
214
+ "output_type": "display_data"
215
+ },
216
+ {
217
+ "data": {
218
+ "application/vnd.jupyter.widget-view+json": {
219
+ "model_id": "fe6e89ddbb5540b4869935bda0ededc0",
220
+ "version_major": 2,
221
+ "version_minor": 0
222
+ },
223
+ "text/plain": [
224
+ "README.md: 0%| | 0.00/10.4k [00:00<?, ?B/s]"
225
+ ]
226
+ },
227
+ "metadata": {},
228
+ "output_type": "display_data"
229
+ },
230
+ {
231
+ "data": {
232
+ "application/vnd.jupyter.widget-view+json": {
233
+ "model_id": "6ac82a744f0b4d33a64b21346af272d2",
234
+ "version_major": 2,
235
+ "version_minor": 0
236
+ },
237
+ "text/plain": [
238
+ "sentence_bert_config.json: 0%| | 0.00/53.0 [00:00<?, ?B/s]"
239
+ ]
240
+ },
241
+ "metadata": {},
242
+ "output_type": "display_data"
243
+ },
244
+ {
245
+ "data": {
246
+ "application/vnd.jupyter.widget-view+json": {
247
+ "model_id": "877342a7a662471cb133598c298f6304",
248
+ "version_major": 2,
249
+ "version_minor": 0
250
+ },
251
+ "text/plain": [
252
+ "config.json: 0%| | 0.00/571 [00:00<?, ?B/s]"
253
+ ]
254
+ },
255
+ "metadata": {},
256
+ "output_type": "display_data"
257
+ },
258
+ {
259
+ "name": "stderr",
260
+ "output_type": "stream",
261
+ "text": [
262
+ "Xet Storage is enabled for this repo, but the 'hf_xet' package is not installed. Falling back to regular HTTP download. For better performance, install the package with: `pip install huggingface_hub[hf_xet]` or `pip install hf_xet`\n"
263
+ ]
264
+ },
265
+ {
266
+ "data": {
267
+ "application/vnd.jupyter.widget-view+json": {
268
+ "model_id": "29fdd3411b504b2ca875d7e0007db775",
269
+ "version_major": 2,
270
+ "version_minor": 0
271
+ },
272
+ "text/plain": [
273
+ "model.safetensors: 0%| | 0.00/438M [00:00<?, ?B/s]"
274
+ ]
275
+ },
276
+ "metadata": {},
277
+ "output_type": "display_data"
278
+ },
279
+ {
280
+ "data": {
281
+ "application/vnd.jupyter.widget-view+json": {
282
+ "model_id": "102778342b534cddb8b84d3698371c89",
283
+ "version_major": 2,
284
+ "version_minor": 0
285
+ },
286
+ "text/plain": [
287
+ "tokenizer_config.json: 0%| | 0.00/363 [00:00<?, ?B/s]"
288
+ ]
289
+ },
290
+ "metadata": {},
291
+ "output_type": "display_data"
292
+ },
293
+ {
294
+ "data": {
295
+ "application/vnd.jupyter.widget-view+json": {
296
+ "model_id": "209ab2f278b949e5846abd5b60e42130",
297
+ "version_major": 2,
298
+ "version_minor": 0
299
+ },
300
+ "text/plain": [
301
+ "vocab.txt: 0%| | 0.00/232k [00:00<?, ?B/s]"
302
+ ]
303
+ },
304
+ "metadata": {},
305
+ "output_type": "display_data"
306
+ },
307
+ {
308
+ "data": {
309
+ "application/vnd.jupyter.widget-view+json": {
310
+ "model_id": "aced6d0bf212458a89c05dde7a22411b",
311
+ "version_major": 2,
312
+ "version_minor": 0
313
+ },
314
+ "text/plain": [
315
+ "tokenizer.json: 0%| | 0.00/466k [00:00<?, ?B/s]"
316
+ ]
317
+ },
318
+ "metadata": {},
319
+ "output_type": "display_data"
320
+ },
321
+ {
322
+ "data": {
323
+ "application/vnd.jupyter.widget-view+json": {
324
+ "model_id": "105ea3c52b7444f281aa22bddf40d582",
325
+ "version_major": 2,
326
+ "version_minor": 0
327
+ },
328
+ "text/plain": [
329
+ "special_tokens_map.json: 0%| | 0.00/239 [00:00<?, ?B/s]"
330
+ ]
331
+ },
332
+ "metadata": {},
333
+ "output_type": "display_data"
334
+ },
335
+ {
336
+ "data": {
337
+ "application/vnd.jupyter.widget-view+json": {
338
+ "model_id": "abbfcff9883645de86ea66f61931d31a",
339
+ "version_major": 2,
340
+ "version_minor": 0
341
+ },
342
+ "text/plain": [
343
+ "config.json: 0%| | 0.00/190 [00:00<?, ?B/s]"
344
+ ]
345
+ },
346
+ "metadata": {},
347
+ "output_type": "display_data"
348
+ }
349
+ ],
350
+ "source": [
351
+ "# Necessary packages:\n",
352
+ "# - langchain-chroma>=0.1.2\n",
353
+ "# - langchain-huggingface\n",
354
+ "# Source:\n",
355
+ "# http://python.langchain.com/docs/integrations/vectorstores/chroma/\n",
356
+ "\n",
357
+ "embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\")\n",
358
+ "vector_store = Chroma(\n",
359
+ " collection_name=\"gaia_dataset\",\n",
360
+ " embedding_function=embeddings,\n",
361
+ " persist_directory=\"./data/chroma_langchain_db\", # Where to save data locally, remove if not necessary\n",
362
+ ")\n"
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "code",
367
+ "execution_count": null,
368
+ "id": "69e1f1b3",
369
+ "metadata": {},
370
+ "outputs": [],
371
+ "source": [
372
+ "# wrap the metadata.jsonl's questions and answers into a list of document\n",
373
+ "docs = []\n",
374
+ "for i, sample in enumerate(json_QA):\n",
375
+ " content = (\n",
376
+ " f\"Question : {sample['Question']}\\n\\nFinal answer : {sample['Final answer']}\"\n",
377
+ " )\n",
378
+ " doc = Document(\n",
379
+ " page_content=content,\n",
380
+ " metadata={\"source\": sample[\"task_id\"]},\n",
381
+ " id=i,\n",
382
+ " )\n",
383
+ " docs.append(doc)\n",
384
+ "\n",
385
+ "# upload the documents to the vector database\n",
386
+ "try:\n",
387
+ " uuids = [str(uuid4()) for _ in range(len(docs))]\n",
388
+ " vector_store.add_documents(documents=docs, ids=uuids)\n",
389
+ "except Exception as exception:\n",
390
+ " print(\"Error inserting data into Supabase:\", exception)\n",
391
+ "\n",
392
+ "# ALTERNATIVE : Save the documents (a list of dict) into a csv file, and manually upload it to Supabase\n",
393
+ "# import pandas as pd\n",
394
+ "# df = pd.DataFrame(docs)\n",
395
+ "# df.to_csv('supabase_docs.csv', index=False)\n"
396
+ ]
397
+ },
398
+ {
399
+ "cell_type": "markdown",
400
+ "id": "d1701d7c",
401
+ "metadata": {},
402
+ "source": [
403
+ "<div style=\"background-color:lightblue; color:black; font-weight:bold\">\n",
404
+ "\n",
405
+ "## 3. Querying the database and converting to a retriever to search using\n",
406
+ "\n",
407
+ "</div>\n"
408
+ ]
409
+ },
410
+ {
411
+ "cell_type": "code",
412
+ "execution_count": null,
413
+ "id": "0a7763a1",
414
+ "metadata": {},
415
+ "outputs": [
416
+ {
417
+ "name": "stdout",
418
+ "output_type": "stream",
419
+ "text": [
420
+ "* Question : How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.\n",
421
+ "\n",
422
+ "Final answer : 3 [{'source': '8e867cd7-cff9-4e6c-867a-ff5ddc2550be'}]\n",
423
+ "* Question : It is 1999. Before you party like it is 1999, please assist me in settling a bet.\n",
424
+ "\n",
425
+ "Fiona Apple and Paula Cole released albums prior to 1999. Of these albums, which didn't receive a letter grade from Robert Christgau? Provide your answer as a comma delimited list of album titles, sorted alphabetically.\n",
426
+ "\n",
427
+ "Final answer : Harbinger, Tidal [{'source': 'f46b4380-207e-4434-820b-f32ce04ae2a4'}]\n"
428
+ ]
429
+ }
430
+ ],
431
+ "source": [
432
+ "# Querying directly from the vector database\n",
433
+ "query = \"How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.\"\n",
434
+ "\n",
435
+ "results = vector_store.similarity_search(\n",
436
+ " query=query,\n",
437
+ " k=2,\n",
438
+ ")\n",
439
+ "for res in results:\n",
440
+ " print(f\"* {res.page_content} [{res.metadata}]\")\n"
441
+ ]
442
+ },
443
+ {
444
+ "cell_type": "code",
445
+ "execution_count": null,
446
+ "id": "05895e6c",
447
+ "metadata": {},
448
+ "outputs": [],
449
+ "source": [
450
+ "# Querying using a retriever\n",
451
+ "# Conver to a retriever\n",
452
+ "retriever = vector_store.as_retriever(\n",
453
+ " search_type=\"mmr\", search_kwargs={\"k\": 1, \"fetch_k\": 5}\n",
454
+ ")\n",
455
+ "results = retriever.invoke(input=query)\n"
456
+ ]
457
+ },
458
+ {
459
+ "cell_type": "code",
460
+ "execution_count": 17,
461
+ "id": "31649cce",
462
+ "metadata": {},
463
+ "outputs": [
464
+ {
465
+ "data": {
466
+ "text/plain": [
467
+ "[Document(id='454c552a-b27f-4eba-ac9a-d37300e515cd', metadata={'source': '8e867cd7-cff9-4e6c-867a-ff5ddc2550be'}, page_content='Question : How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.\\n\\nFinal answer : 3')]"
468
+ ]
469
+ },
470
+ "execution_count": 17,
471
+ "metadata": {},
472
+ "output_type": "execute_result"
473
+ }
474
+ ],
475
+ "source": [
476
+ "results"
477
+ ]
478
+ }
479
+ ],
480
+ "metadata": {
481
+ "kernelspec": {
482
+ "display_name": "llm-huggingface-agents-course-env",
483
+ "language": "python",
484
+ "name": "python3"
485
+ },
486
+ "language_info": {
487
+ "codemirror_mode": {
488
+ "name": "ipython",
489
+ "version": 3
490
+ },
491
+ "file_extension": ".py",
492
+ "mimetype": "text/x-python",
493
+ "name": "python",
494
+ "nbconvert_exporter": "python",
495
+ "pygments_lexer": "ipython3",
496
+ "version": "3.11.11"
497
+ }
498
+ },
499
+ "nbformat": 4,
500
+ "nbformat_minor": 5
501
+ }