Omar Solano commited on
Commit
030fa83
Β·
1 Parent(s): 7c97045

add long context caching nb

Browse files
notebooks/Long_Context_Caching_vs_RAG.ipynb ADDED
@@ -0,0 +1,1278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/03-RAG_with_LlamaIndex.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "markdown",
12
+ "metadata": {
13
+ "id": "v9bpz99INAc1"
14
+ },
15
+ "source": [
16
+ "# Install Packages and Setup Variables\n"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": null,
22
+ "metadata": {
23
+ "colab": {
24
+ "base_uri": "https://localhost:8080/"
25
+ },
26
+ "id": "BeuFJKlj9jKz",
27
+ "outputId": "6419987a-aa8c-49f8-de20-42aa9d7528c3"
28
+ },
29
+ "outputs": [],
30
+ "source": [
31
+ "!pip install -q llama-index==0.10.57 llama-index-llms-gemini==0.1.11 openai==1.37.0 google-generativeai==0.7.2"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 1,
37
+ "metadata": {
38
+ "id": "CWholrWlt2OQ"
39
+ },
40
+ "outputs": [],
41
+ "source": [
42
+ "import os\n",
43
+ "import time\n",
44
+ "from IPython.display import Markdown, display\n",
45
+ "\n",
46
+ "# Set the following API Keys in the Python environment. Will be used later.\n",
47
+ "# We use OpenAI for the embedding model and Gemini-1.5-flash as our LLM.\n",
48
+ "os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\"\n",
49
+ "os.environ[\"GOOGLE_API_KEY\"] = \"<YOUR_API_KEY>\""
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "markdown",
54
+ "metadata": {
55
+ "id": "f5eV5EnvNCMM"
56
+ },
57
+ "source": [
58
+ "# Load Dataset\n"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "markdown",
63
+ "metadata": {
64
+ "id": "q-7mRQ-mNJlm"
65
+ },
66
+ "source": [
67
+ "## Download\n"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "markdown",
72
+ "metadata": {
73
+ "id": "3PsdOdMUNmEi"
74
+ },
75
+ "source": [
76
+ "The dataset includes a subset of the documentation from the Llama-index library.\n"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 2,
82
+ "metadata": {
83
+ "colab": {
84
+ "base_uri": "https://localhost:8080/"
85
+ },
86
+ "id": "3ImRCP7pACaI",
87
+ "outputId": "ff52cd9a-67e0-4243-9774-98288c3cf248"
88
+ },
89
+ "outputs": [
90
+ {
91
+ "name": "stdout",
92
+ "output_type": "stream",
93
+ "text": [
94
+ " % Total % Received % Xferd Average Speed Time Time Time Current\n",
95
+ " Dload Upload Total Spent Left Speed\n",
96
+ "100 570k 100 570k 0 0 3407k 0 --:--:-- --:--:-- --:--:-- 3417k\n"
97
+ ]
98
+ }
99
+ ],
100
+ "source": [
101
+ "!curl -o ./llama_index_150k.jsonl https://huggingface.co/datasets/towardsai-buster/llama-index-docs/raw/main/llama_index_data_150k.jsonl"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "markdown",
106
+ "metadata": {
107
+ "id": "bZZLK_wyEc-L"
108
+ },
109
+ "source": [
110
+ "## Read File and create LlamaIndex Documents\n"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 3,
116
+ "metadata": {
117
+ "colab": {
118
+ "base_uri": "https://localhost:8080/"
119
+ },
120
+ "id": "miUqycqAEfr7",
121
+ "outputId": "6c3068a9-a9a3-465a-8f84-8d329e0cd02a"
122
+ },
123
+ "outputs": [],
124
+ "source": [
125
+ "from llama_index.core import Document\n",
126
+ "import json\n",
127
+ "\n",
128
+ "\n",
129
+ "def create_docs(input_file: str) -> list[Document]:\n",
130
+ " with open(input_file, \"r\") as f:\n",
131
+ " documents = []\n",
132
+ " for line in f:\n",
133
+ " data = json.loads(line)\n",
134
+ "\n",
135
+ " documents.append(\n",
136
+ " Document(\n",
137
+ " doc_id=data[\"doc_id\"],\n",
138
+ " text=data[\"content\"],\n",
139
+ " metadata={ # type: ignore\n",
140
+ " \"url\": data[\"url\"],\n",
141
+ " \"title\": data[\"name\"],\n",
142
+ " \"tokens\": data[\"tokens\"],\n",
143
+ " \"source\": data[\"source\"],\n",
144
+ " },\n",
145
+ " excluded_llm_metadata_keys=[\n",
146
+ " \"title\",\n",
147
+ " \"tokens\",\n",
148
+ " \"source\",\n",
149
+ " ],\n",
150
+ " excluded_embed_metadata_keys=[\n",
151
+ " \"url\",\n",
152
+ " \"tokens\",\n",
153
+ " \"source\",\n",
154
+ " ],\n",
155
+ " )\n",
156
+ " )\n",
157
+ " return documents"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "markdown",
162
+ "metadata": {
163
+ "id": "f86yksB9K571"
164
+ },
165
+ "source": [
166
+ "# Generate Embedding\n"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "execution_count": 7,
172
+ "metadata": {
173
+ "id": "iXrr5-tnEfm9"
174
+ },
175
+ "outputs": [
176
+ {
177
+ "name": "stdout",
178
+ "output_type": "stream",
179
+ "text": [
180
+ "Number of documents: 56\n"
181
+ ]
182
+ }
183
+ ],
184
+ "source": [
185
+ "from llama_index.core import Document\n",
186
+ "\n",
187
+ "# Convert the texts to Document objects so the LlamaIndex framework can process them.\n",
188
+ "documents = create_docs(\"llama_index_150k.jsonl\")\n",
189
+ "print(\"Number of documents:\", len(documents))"
190
+ ]
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "execution_count": 5,
195
+ "metadata": {
196
+ "colab": {
197
+ "base_uri": "https://localhost:8080/",
198
+ "height": 81,
199
+ "referenced_widgets": [
200
+ "6e893cde79734e408bb8d0b4305bedab",
201
+ "51242f18dfd14aba963ed72b008d6dd6",
202
+ "a88124e34ad24f19bdcbcd73e998168a",
203
+ "fff2627bdf20445f8507a7792a17546d",
204
+ "f5f3f69abfd149f281a2f0c3f58d3284",
205
+ "d1a558eb15cf43f8a013a91b9262eee5",
206
+ "946ebbd88b344a248564a1b2c593653e",
207
+ "4e905c17eddc44c299aabf699ec33642",
208
+ "ab738a29078d43aaa3364b3076f1eca0",
209
+ "ae615040ed1a4a47838aaa99192fd33b",
210
+ "7e3db69b3e20451f8fc88631b7915a39",
211
+ "27fd17bf0eaa49868321cf2d31a5a0a1",
212
+ "a0ba4f46f20b435cb6b811317a935b1e",
213
+ "4026c7a3aead4dc1bb0525535c885601",
214
+ "8ab7550005bf4d8f80c87716c769e2ec",
215
+ "3e0e3f06c25543e9877d30ed378edd8d",
216
+ "4a766f37197b41d7bfa496c0c6d393bf",
217
+ "a436c3949572481cbde16838298cbf93",
218
+ "ab59db85ad504297a3c56e3d63f5d474",
219
+ "2b3e4d550bce4effb83939e026ea6538",
220
+ "93e9287c92034d36a44a3855f38ef6d8",
221
+ "12380f5aab5e4c41843036e4f12883cd"
222
+ ]
223
+ },
224
+ "id": "Bsa7Q-DoNWBk",
225
+ "outputId": "b6f4f826-e4cd-4745-fc99-13b91c2d4d1b"
226
+ },
227
+ "outputs": [
228
+ {
229
+ "name": "stderr",
230
+ "output_type": "stream",
231
+ "text": [
232
+ "/Users/omar/Documents/ai_repos/ai-tutor-rag-system/env/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
233
+ " from .autonotebook import tqdm as notebook_tqdm\n",
234
+ "Parsing nodes: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 56/56 [00:00<00:00, 181.20it/s]\n",
235
+ "Generating embeddings: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 375/375 [00:05<00:00, 74.36it/s]\n"
236
+ ]
237
+ }
238
+ ],
239
+ "source": [
240
+ "from llama_index.core import VectorStoreIndex\n",
241
+ "from llama_index.core.node_parser import SentenceSplitter\n",
242
+ "from llama_index.embeddings.openai import OpenAIEmbedding\n",
243
+ "\n",
244
+ "\n",
245
+ "# Build index / generate embeddings using OpenAI embedding model\n",
246
+ "index = VectorStoreIndex.from_documents(\n",
247
+ " documents,\n",
248
+ " embed_model=OpenAIEmbedding(model=\"text-embedding-3-small\"),\n",
249
+ " transformations=[SentenceSplitter(chunk_size=800, chunk_overlap=400)],\n",
250
+ " show_progress=True,\n",
251
+ ")"
252
+ ]
253
+ },
254
+ {
255
+ "cell_type": "markdown",
256
+ "metadata": {
257
+ "id": "3DoUxd8KK--Q"
258
+ },
259
+ "source": [
260
+ "# Query Dataset\n"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "execution_count": 8,
266
+ "metadata": {
267
+ "id": "bUaNH97dEfh9"
268
+ },
269
+ "outputs": [
270
+ {
271
+ "name": "stderr",
272
+ "output_type": "stream",
273
+ "text": [
274
+ "I0000 00:00:1722879021.990521 1763413 check_gcp_environment_no_op.cc:29] ALTS: Platforms other than Linux and Windows are not supported\n"
275
+ ]
276
+ }
277
+ ],
278
+ "source": [
279
+ "# Define a query engine that is responsible for retrieving related pieces of text,\n",
280
+ "# and using a LLM to formulate the final answer.\n",
281
+ "\n",
282
+ "from llama_index.llms.gemini import Gemini\n",
283
+ "\n",
284
+ "llm = Gemini(model=\"models/gemini-1.5-flash\", temperature=1, max_tokens=1000)\n",
285
+ "\n",
286
+ "query_engine = index.as_query_engine(llm=llm, similarity_top_k=10)"
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": 9,
292
+ "metadata": {
293
+ "colab": {
294
+ "base_uri": "https://localhost:8080/"
295
+ },
296
+ "id": "KHK4V_GRR6ZG",
297
+ "outputId": "105cf2b3-3a65-4eb7-f629-38ce22bb20aa"
298
+ },
299
+ "outputs": [
300
+ {
301
+ "name": "stderr",
302
+ "output_type": "stream",
303
+ "text": [
304
+ "I0000 00:00:1722879022.480648 1763413 check_gcp_environment_no_op.cc:29] ALTS: Platforms other than Linux and Windows are not supported\n"
305
+ ]
306
+ },
307
+ {
308
+ "data": {
309
+ "text/markdown": [
310
+ "To set up a query engine in code, first create an index from your documents. Then, use the index to create a query engine. You can then query the query engine using the `query` method. \n"
311
+ ],
312
+ "text/plain": [
313
+ "<IPython.core.display.Markdown object>"
314
+ ]
315
+ },
316
+ "metadata": {},
317
+ "output_type": "display_data"
318
+ },
319
+ {
320
+ "name": "stdout",
321
+ "output_type": "stream",
322
+ "text": [
323
+ "time taken: 3.4835610389709473\n"
324
+ ]
325
+ }
326
+ ],
327
+ "source": [
328
+ "start = time.time()\n",
329
+ "response = query_engine.query(\"How to setup a query engine in code?\")\n",
330
+ "end = time.time()\n",
331
+ "display(Markdown(response.response))\n",
332
+ "print(\"time taken: \", end - start)"
333
+ ]
334
+ },
335
+ {
336
+ "cell_type": "code",
337
+ "execution_count": 10,
338
+ "metadata": {
339
+ "colab": {
340
+ "base_uri": "https://localhost:8080/"
341
+ },
342
+ "id": "S-BmyTBbNd9y",
343
+ "outputId": "662f49d2-8c19-400a-c7fd-dd0018dcd74e"
344
+ },
345
+ "outputs": [
346
+ {
347
+ "data": {
348
+ "text/markdown": [
349
+ "An agent can be set up in code by defining a set of tools and providing them to a `ReActAgent` implementation.\n"
350
+ ],
351
+ "text/plain": [
352
+ "<IPython.core.display.Markdown object>"
353
+ ]
354
+ },
355
+ "metadata": {},
356
+ "output_type": "display_data"
357
+ },
358
+ {
359
+ "name": "stdout",
360
+ "output_type": "stream",
361
+ "text": [
362
+ "time taken: 3.3619420528411865\n"
363
+ ]
364
+ }
365
+ ],
366
+ "source": [
367
+ "start = time.time()\n",
368
+ "response = query_engine.query(\"How to setup an agent in code?\")\n",
369
+ "end = time.time()\n",
370
+ "display(Markdown(response.response))\n",
371
+ "print(\"time taken: \", end - start)"
372
+ ]
373
+ },
374
+ {
375
+ "cell_type": "markdown",
376
+ "metadata": {},
377
+ "source": [
378
+ "# Setup Long Context Caching\n"
379
+ ]
380
+ },
381
+ {
382
+ "cell_type": "markdown",
383
+ "metadata": {},
384
+ "source": [
385
+ "For this section, we will be using the Gemini API\n"
386
+ ]
387
+ },
388
+ {
389
+ "cell_type": "code",
390
+ "execution_count": 11,
391
+ "metadata": {},
392
+ "outputs": [],
393
+ "source": [
394
+ "# Import the Python SDK\n",
395
+ "import google.generativeai as genai\n",
396
+ "from google.generativeai import caching\n",
397
+ "from google.generativeai import GenerationConfig\n",
398
+ "\n",
399
+ "genai.configure(api_key=os.environ[\"GOOGLE_API_KEY\"])"
400
+ ]
401
+ },
402
+ {
403
+ "cell_type": "markdown",
404
+ "metadata": {},
405
+ "source": [
406
+ "Convert the jsonl file to a text file for the Gemini API"
407
+ ]
408
+ },
409
+ {
410
+ "cell_type": "code",
411
+ "execution_count": 12,
412
+ "metadata": {},
413
+ "outputs": [
414
+ {
415
+ "name": "stdout",
416
+ "output_type": "stream",
417
+ "text": [
418
+ "Contents saved to llama_index_contents.txt\n"
419
+ ]
420
+ }
421
+ ],
422
+ "source": [
423
+ "import json\n",
424
+ "\n",
425
+ "\n",
426
+ "def create_text_file(input_file: str, output_file: str) -> None:\n",
427
+ " with open(input_file, \"r\") as f, open(output_file, \"w\") as out:\n",
428
+ " for line in f:\n",
429
+ " data = json.loads(line)\n",
430
+ " out.write(data[\"content\"] + \"\\n\\n\") # Add two newlines between documents\n",
431
+ "\n",
432
+ " print(f\"Contents saved to {output_file}\")\n",
433
+ "\n",
434
+ "\n",
435
+ "create_text_file(\"llama_index_150k.jsonl\", \"llama_index_contents.txt\")"
436
+ ]
437
+ },
438
+ {
439
+ "cell_type": "code",
440
+ "execution_count": null,
441
+ "metadata": {},
442
+ "outputs": [],
443
+ "source": [
444
+ "document = genai.upload_file(path=\"llama_index_contents.txt\")\n",
445
+ "model_name = \"gemini-1.5-flash-001\"\n",
446
+ "\n",
447
+ "cache = genai.caching.CachedContent.create(\n",
448
+ " model=model_name,\n",
449
+ " system_instruction=\"You answer questions about the LlamaIndex framework.\",\n",
450
+ " contents=[document],\n",
451
+ ")"
452
+ ]
453
+ },
454
+ {
455
+ "cell_type": "code",
456
+ "execution_count": 14,
457
+ "metadata": {},
458
+ "outputs": [
459
+ {
460
+ "data": {
461
+ "text/markdown": [
462
+ "Here's a breakdown of how to set up a query engine in LlamaIndex, along with different methods and explanations:\n",
463
+ "\n",
464
+ "**1. The Most Common Approach: Using an Index**\n",
465
+ "\n",
466
+ " The simplest way to get a `QueryEngine` is to leverage an existing `Index` object. Each index type in LlamaIndex has an `as_query_engine()` method that creates a specialized engine for that index:\n",
467
+ "\n",
468
+ " ```python\n",
469
+ " from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n",
470
+ "\n",
471
+ " # Load your data\n",
472
+ " documents = SimpleDirectoryReader(\"data\").load_data() \n",
473
+ "\n",
474
+ " # Create a VectorStoreIndex\n",
475
+ " index = VectorStoreIndex.from_documents(documents) \n",
476
+ "\n",
477
+ " # Get a query engine\n",
478
+ " query_engine = index.as_query_engine() \n",
479
+ "\n",
480
+ " # Now you can use the query engine to ask questions\n",
481
+ " response = query_engine.query(\"What is the main point of this document?\")\n",
482
+ " print(response)\n",
483
+ " ```\n",
484
+ "\n",
485
+ "**2. Customization Through Composition: Advanced Query Engines**\n",
486
+ "\n",
487
+ " For fine-grained control, you can build a `QueryEngine` from its component parts using the `RetrieverQueryEngine`:\n",
488
+ "\n",
489
+ " ```python\n",
490
+ " from llama_index.core import VectorStoreIndex, get_response_synthesizer\n",
491
+ " from llama_index.core.retrievers import VectorIndexRetriever\n",
492
+ " from llama_index.core.query_engine import RetrieverQueryEngine\n",
493
+ " from llama_index.core.postprocessor import SimilarityPostprocessor\n",
494
+ "\n",
495
+ " # Build your index (as above)\n",
496
+ " index = VectorStoreIndex.from_documents(documents) \n",
497
+ "\n",
498
+ " # Configure the retriever\n",
499
+ " retriever = VectorIndexRetriever(\n",
500
+ " index=index,\n",
501
+ " similarity_top_k=10, \n",
502
+ " )\n",
503
+ "\n",
504
+ " # Configure the response synthesizer (the core LLM)\n",
505
+ " response_synthesizer = get_response_synthesizer()\n",
506
+ "\n",
507
+ " # Assemble the query engine\n",
508
+ " query_engine = RetrieverQueryEngine(\n",
509
+ " retriever=retriever,\n",
510
+ " response_synthesizer=response_synthesizer,\n",
511
+ " node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.7)],\n",
512
+ " )\n",
513
+ "\n",
514
+ " # Query the engine\n",
515
+ " response = query_engine.query(\"What are the key takeaways from this data?\")\n",
516
+ " print(response)\n",
517
+ " ```\n",
518
+ "\n",
519
+ "**Key Components and Customization:**\n",
520
+ "\n",
521
+ "* **Retrieval:** How your engine finds relevant information from the index (e.g., top-k semantic search, keyword matching, etc.).\n",
522
+ "* **Postprocessing:** Additional steps to refine the retrieved results (e.g., reranking, filtering based on metadata, etc.).\n",
523
+ "* **Response Synthesis:** The LLM used to generate the final response (e.g., OpenAI's GPT-3.5, a local model, etc.).\n",
524
+ "* **Prompt Engineering:** Crafting effective prompts to guide your LLM in synthesizing a meaningful answer.\n",
525
+ "\n",
526
+ "**Types of Query Engines:**\n",
527
+ "\n",
528
+ "* **RetrieverQueryEngine:** Combines a retriever and response synthesizer for standard question answering.\n",
529
+ "* **SubQuestionQueryEngine:** Decomposes a complex query into sub-queries, especially suited for multi-document analysis and compare/contrast scenarios.\n",
530
+ "* **RouterQueryEngine:** Routes a query to the most appropriate index or data source, especially helpful when you have a heterogeneous collection of information.\n",
531
+ "\n",
532
+ "**Choosing the Right Approach:**\n",
533
+ "\n",
534
+ "* For straightforward scenarios, using an index's `as_query_engine()` method is the easiest option.\n",
535
+ "* When you need finer control over retrieval, postprocessing, or the LLM used, create a `RetrieverQueryEngine` and customize its components.\n",
536
+ "\n",
537
+ "Let me know if you'd like to see a specific type of query engine setup or have more advanced use cases in mind! \n"
538
+ ],
539
+ "text/plain": [
540
+ "<IPython.core.display.Markdown object>"
541
+ ]
542
+ },
543
+ "metadata": {},
544
+ "output_type": "display_data"
545
+ },
546
+ {
547
+ "name": "stdout",
548
+ "output_type": "stream",
549
+ "text": [
550
+ "time taken: 32.33650302886963\n"
551
+ ]
552
+ }
553
+ ],
554
+ "source": [
555
+ "model = genai.GenerativeModel.from_cached_content(cache)\n",
556
+ "start = time.time()\n",
557
+ "response = model.generate_content(\n",
558
+ " \"How to setup a query engine in code?\",\n",
559
+ " generation_config=GenerationConfig(max_output_tokens=1000),\n",
560
+ ")\n",
561
+ "end = time.time()\n",
562
+ "display(Markdown(response.text))\n",
563
+ "print(\"time taken: \", end - start)"
564
+ ]
565
+ }
566
+ ],
567
+ "metadata": {
568
+ "colab": {
569
+ "provenance": []
570
+ },
571
+ "kernelspec": {
572
+ "display_name": "Python 3",
573
+ "name": "python3"
574
+ },
575
+ "language_info": {
576
+ "codemirror_mode": {
577
+ "name": "ipython",
578
+ "version": 3
579
+ },
580
+ "file_extension": ".py",
581
+ "mimetype": "text/x-python",
582
+ "name": "python",
583
+ "nbconvert_exporter": "python",
584
+ "pygments_lexer": "ipython3",
585
+ "version": "3.12.4"
586
+ },
587
+ "widgets": {
588
+ "application/vnd.jupyter.widget-state+json": {
589
+ "12380f5aab5e4c41843036e4f12883cd": {
590
+ "model_module": "@jupyter-widgets/controls",
591
+ "model_module_version": "1.5.0",
592
+ "model_name": "DescriptionStyleModel",
593
+ "state": {
594
+ "_model_module": "@jupyter-widgets/controls",
595
+ "_model_module_version": "1.5.0",
596
+ "_model_name": "DescriptionStyleModel",
597
+ "_view_count": null,
598
+ "_view_module": "@jupyter-widgets/base",
599
+ "_view_module_version": "1.2.0",
600
+ "_view_name": "StyleView",
601
+ "description_width": ""
602
+ }
603
+ },
604
+ "27fd17bf0eaa49868321cf2d31a5a0a1": {
605
+ "model_module": "@jupyter-widgets/controls",
606
+ "model_module_version": "1.5.0",
607
+ "model_name": "HBoxModel",
608
+ "state": {
609
+ "_dom_classes": [],
610
+ "_model_module": "@jupyter-widgets/controls",
611
+ "_model_module_version": "1.5.0",
612
+ "_model_name": "HBoxModel",
613
+ "_view_count": null,
614
+ "_view_module": "@jupyter-widgets/controls",
615
+ "_view_module_version": "1.5.0",
616
+ "_view_name": "HBoxView",
617
+ "box_style": "",
618
+ "children": [
619
+ "IPY_MODEL_a0ba4f46f20b435cb6b811317a935b1e",
620
+ "IPY_MODEL_4026c7a3aead4dc1bb0525535c885601",
621
+ "IPY_MODEL_8ab7550005bf4d8f80c87716c769e2ec"
622
+ ],
623
+ "layout": "IPY_MODEL_3e0e3f06c25543e9877d30ed378edd8d"
624
+ }
625
+ },
626
+ "2b3e4d550bce4effb83939e026ea6538": {
627
+ "model_module": "@jupyter-widgets/controls",
628
+ "model_module_version": "1.5.0",
629
+ "model_name": "ProgressStyleModel",
630
+ "state": {
631
+ "_model_module": "@jupyter-widgets/controls",
632
+ "_model_module_version": "1.5.0",
633
+ "_model_name": "ProgressStyleModel",
634
+ "_view_count": null,
635
+ "_view_module": "@jupyter-widgets/base",
636
+ "_view_module_version": "1.2.0",
637
+ "_view_name": "StyleView",
638
+ "bar_color": null,
639
+ "description_width": ""
640
+ }
641
+ },
642
+ "3e0e3f06c25543e9877d30ed378edd8d": {
643
+ "model_module": "@jupyter-widgets/base",
644
+ "model_module_version": "1.2.0",
645
+ "model_name": "LayoutModel",
646
+ "state": {
647
+ "_model_module": "@jupyter-widgets/base",
648
+ "_model_module_version": "1.2.0",
649
+ "_model_name": "LayoutModel",
650
+ "_view_count": null,
651
+ "_view_module": "@jupyter-widgets/base",
652
+ "_view_module_version": "1.2.0",
653
+ "_view_name": "LayoutView",
654
+ "align_content": null,
655
+ "align_items": null,
656
+ "align_self": null,
657
+ "border": null,
658
+ "bottom": null,
659
+ "display": null,
660
+ "flex": null,
661
+ "flex_flow": null,
662
+ "grid_area": null,
663
+ "grid_auto_columns": null,
664
+ "grid_auto_flow": null,
665
+ "grid_auto_rows": null,
666
+ "grid_column": null,
667
+ "grid_gap": null,
668
+ "grid_row": null,
669
+ "grid_template_areas": null,
670
+ "grid_template_columns": null,
671
+ "grid_template_rows": null,
672
+ "height": null,
673
+ "justify_content": null,
674
+ "justify_items": null,
675
+ "left": null,
676
+ "margin": null,
677
+ "max_height": null,
678
+ "max_width": null,
679
+ "min_height": null,
680
+ "min_width": null,
681
+ "object_fit": null,
682
+ "object_position": null,
683
+ "order": null,
684
+ "overflow": null,
685
+ "overflow_x": null,
686
+ "overflow_y": null,
687
+ "padding": null,
688
+ "right": null,
689
+ "top": null,
690
+ "visibility": null,
691
+ "width": null
692
+ }
693
+ },
694
+ "4026c7a3aead4dc1bb0525535c885601": {
695
+ "model_module": "@jupyter-widgets/controls",
696
+ "model_module_version": "1.5.0",
697
+ "model_name": "FloatProgressModel",
698
+ "state": {
699
+ "_dom_classes": [],
700
+ "_model_module": "@jupyter-widgets/controls",
701
+ "_model_module_version": "1.5.0",
702
+ "_model_name": "FloatProgressModel",
703
+ "_view_count": null,
704
+ "_view_module": "@jupyter-widgets/controls",
705
+ "_view_module_version": "1.5.0",
706
+ "_view_name": "ProgressView",
707
+ "bar_style": "success",
708
+ "description": "",
709
+ "description_tooltip": null,
710
+ "layout": "IPY_MODEL_ab59db85ad504297a3c56e3d63f5d474",
711
+ "max": 56,
712
+ "min": 0,
713
+ "orientation": "horizontal",
714
+ "style": "IPY_MODEL_2b3e4d550bce4effb83939e026ea6538",
715
+ "value": 56
716
+ }
717
+ },
718
+ "4a766f37197b41d7bfa496c0c6d393bf": {
719
+ "model_module": "@jupyter-widgets/base",
720
+ "model_module_version": "1.2.0",
721
+ "model_name": "LayoutModel",
722
+ "state": {
723
+ "_model_module": "@jupyter-widgets/base",
724
+ "_model_module_version": "1.2.0",
725
+ "_model_name": "LayoutModel",
726
+ "_view_count": null,
727
+ "_view_module": "@jupyter-widgets/base",
728
+ "_view_module_version": "1.2.0",
729
+ "_view_name": "LayoutView",
730
+ "align_content": null,
731
+ "align_items": null,
732
+ "align_self": null,
733
+ "border": null,
734
+ "bottom": null,
735
+ "display": null,
736
+ "flex": null,
737
+ "flex_flow": null,
738
+ "grid_area": null,
739
+ "grid_auto_columns": null,
740
+ "grid_auto_flow": null,
741
+ "grid_auto_rows": null,
742
+ "grid_column": null,
743
+ "grid_gap": null,
744
+ "grid_row": null,
745
+ "grid_template_areas": null,
746
+ "grid_template_columns": null,
747
+ "grid_template_rows": null,
748
+ "height": null,
749
+ "justify_content": null,
750
+ "justify_items": null,
751
+ "left": null,
752
+ "margin": null,
753
+ "max_height": null,
754
+ "max_width": null,
755
+ "min_height": null,
756
+ "min_width": null,
757
+ "object_fit": null,
758
+ "object_position": null,
759
+ "order": null,
760
+ "overflow": null,
761
+ "overflow_x": null,
762
+ "overflow_y": null,
763
+ "padding": null,
764
+ "right": null,
765
+ "top": null,
766
+ "visibility": null,
767
+ "width": null
768
+ }
769
+ },
770
+ "4e905c17eddc44c299aabf699ec33642": {
771
+ "model_module": "@jupyter-widgets/base",
772
+ "model_module_version": "1.2.0",
773
+ "model_name": "LayoutModel",
774
+ "state": {
775
+ "_model_module": "@jupyter-widgets/base",
776
+ "_model_module_version": "1.2.0",
777
+ "_model_name": "LayoutModel",
778
+ "_view_count": null,
779
+ "_view_module": "@jupyter-widgets/base",
780
+ "_view_module_version": "1.2.0",
781
+ "_view_name": "LayoutView",
782
+ "align_content": null,
783
+ "align_items": null,
784
+ "align_self": null,
785
+ "border": null,
786
+ "bottom": null,
787
+ "display": null,
788
+ "flex": null,
789
+ "flex_flow": null,
790
+ "grid_area": null,
791
+ "grid_auto_columns": null,
792
+ "grid_auto_flow": null,
793
+ "grid_auto_rows": null,
794
+ "grid_column": null,
795
+ "grid_gap": null,
796
+ "grid_row": null,
797
+ "grid_template_areas": null,
798
+ "grid_template_columns": null,
799
+ "grid_template_rows": null,
800
+ "height": null,
801
+ "justify_content": null,
802
+ "justify_items": null,
803
+ "left": null,
804
+ "margin": null,
805
+ "max_height": null,
806
+ "max_width": null,
807
+ "min_height": null,
808
+ "min_width": null,
809
+ "object_fit": null,
810
+ "object_position": null,
811
+ "order": null,
812
+ "overflow": null,
813
+ "overflow_x": null,
814
+ "overflow_y": null,
815
+ "padding": null,
816
+ "right": null,
817
+ "top": null,
818
+ "visibility": null,
819
+ "width": null
820
+ }
821
+ },
822
+ "51242f18dfd14aba963ed72b008d6dd6": {
823
+ "model_module": "@jupyter-widgets/controls",
824
+ "model_module_version": "1.5.0",
825
+ "model_name": "HTMLModel",
826
+ "state": {
827
+ "_dom_classes": [],
828
+ "_model_module": "@jupyter-widgets/controls",
829
+ "_model_module_version": "1.5.0",
830
+ "_model_name": "HTMLModel",
831
+ "_view_count": null,
832
+ "_view_module": "@jupyter-widgets/controls",
833
+ "_view_module_version": "1.5.0",
834
+ "_view_name": "HTMLView",
835
+ "description": "",
836
+ "description_tooltip": null,
837
+ "layout": "IPY_MODEL_d1a558eb15cf43f8a013a91b9262eee5",
838
+ "placeholder": "​",
839
+ "style": "IPY_MODEL_946ebbd88b344a248564a1b2c593653e",
840
+ "value": "Parsing nodes: 100%"
841
+ }
842
+ },
843
+ "6e893cde79734e408bb8d0b4305bedab": {
844
+ "model_module": "@jupyter-widgets/controls",
845
+ "model_module_version": "1.5.0",
846
+ "model_name": "HBoxModel",
847
+ "state": {
848
+ "_dom_classes": [],
849
+ "_model_module": "@jupyter-widgets/controls",
850
+ "_model_module_version": "1.5.0",
851
+ "_model_name": "HBoxModel",
852
+ "_view_count": null,
853
+ "_view_module": "@jupyter-widgets/controls",
854
+ "_view_module_version": "1.5.0",
855
+ "_view_name": "HBoxView",
856
+ "box_style": "",
857
+ "children": [
858
+ "IPY_MODEL_51242f18dfd14aba963ed72b008d6dd6",
859
+ "IPY_MODEL_a88124e34ad24f19bdcbcd73e998168a",
860
+ "IPY_MODEL_fff2627bdf20445f8507a7792a17546d"
861
+ ],
862
+ "layout": "IPY_MODEL_f5f3f69abfd149f281a2f0c3f58d3284"
863
+ }
864
+ },
865
+ "7e3db69b3e20451f8fc88631b7915a39": {
866
+ "model_module": "@jupyter-widgets/controls",
867
+ "model_module_version": "1.5.0",
868
+ "model_name": "DescriptionStyleModel",
869
+ "state": {
870
+ "_model_module": "@jupyter-widgets/controls",
871
+ "_model_module_version": "1.5.0",
872
+ "_model_name": "DescriptionStyleModel",
873
+ "_view_count": null,
874
+ "_view_module": "@jupyter-widgets/base",
875
+ "_view_module_version": "1.2.0",
876
+ "_view_name": "StyleView",
877
+ "description_width": ""
878
+ }
879
+ },
880
+ "8ab7550005bf4d8f80c87716c769e2ec": {
881
+ "model_module": "@jupyter-widgets/controls",
882
+ "model_module_version": "1.5.0",
883
+ "model_name": "HTMLModel",
884
+ "state": {
885
+ "_dom_classes": [],
886
+ "_model_module": "@jupyter-widgets/controls",
887
+ "_model_module_version": "1.5.0",
888
+ "_model_name": "HTMLModel",
889
+ "_view_count": null,
890
+ "_view_module": "@jupyter-widgets/controls",
891
+ "_view_module_version": "1.5.0",
892
+ "_view_name": "HTMLView",
893
+ "description": "",
894
+ "description_tooltip": null,
895
+ "layout": "IPY_MODEL_93e9287c92034d36a44a3855f38ef6d8",
896
+ "placeholder": "​",
897
+ "style": "IPY_MODEL_12380f5aab5e4c41843036e4f12883cd",
898
+ "value": " 56/56 [00:01&lt;00:00, 36.56it/s]"
899
+ }
900
+ },
901
+ "93e9287c92034d36a44a3855f38ef6d8": {
902
+ "model_module": "@jupyter-widgets/base",
903
+ "model_module_version": "1.2.0",
904
+ "model_name": "LayoutModel",
905
+ "state": {
906
+ "_model_module": "@jupyter-widgets/base",
907
+ "_model_module_version": "1.2.0",
908
+ "_model_name": "LayoutModel",
909
+ "_view_count": null,
910
+ "_view_module": "@jupyter-widgets/base",
911
+ "_view_module_version": "1.2.0",
912
+ "_view_name": "LayoutView",
913
+ "align_content": null,
914
+ "align_items": null,
915
+ "align_self": null,
916
+ "border": null,
917
+ "bottom": null,
918
+ "display": null,
919
+ "flex": null,
920
+ "flex_flow": null,
921
+ "grid_area": null,
922
+ "grid_auto_columns": null,
923
+ "grid_auto_flow": null,
924
+ "grid_auto_rows": null,
925
+ "grid_column": null,
926
+ "grid_gap": null,
927
+ "grid_row": null,
928
+ "grid_template_areas": null,
929
+ "grid_template_columns": null,
930
+ "grid_template_rows": null,
931
+ "height": null,
932
+ "justify_content": null,
933
+ "justify_items": null,
934
+ "left": null,
935
+ "margin": null,
936
+ "max_height": null,
937
+ "max_width": null,
938
+ "min_height": null,
939
+ "min_width": null,
940
+ "object_fit": null,
941
+ "object_position": null,
942
+ "order": null,
943
+ "overflow": null,
944
+ "overflow_x": null,
945
+ "overflow_y": null,
946
+ "padding": null,
947
+ "right": null,
948
+ "top": null,
949
+ "visibility": null,
950
+ "width": null
951
+ }
952
+ },
953
+ "946ebbd88b344a248564a1b2c593653e": {
954
+ "model_module": "@jupyter-widgets/controls",
955
+ "model_module_version": "1.5.0",
956
+ "model_name": "DescriptionStyleModel",
957
+ "state": {
958
+ "_model_module": "@jupyter-widgets/controls",
959
+ "_model_module_version": "1.5.0",
960
+ "_model_name": "DescriptionStyleModel",
961
+ "_view_count": null,
962
+ "_view_module": "@jupyter-widgets/base",
963
+ "_view_module_version": "1.2.0",
964
+ "_view_name": "StyleView",
965
+ "description_width": ""
966
+ }
967
+ },
968
+ "a0ba4f46f20b435cb6b811317a935b1e": {
969
+ "model_module": "@jupyter-widgets/controls",
970
+ "model_module_version": "1.5.0",
971
+ "model_name": "HTMLModel",
972
+ "state": {
973
+ "_dom_classes": [],
974
+ "_model_module": "@jupyter-widgets/controls",
975
+ "_model_module_version": "1.5.0",
976
+ "_model_name": "HTMLModel",
977
+ "_view_count": null,
978
+ "_view_module": "@jupyter-widgets/controls",
979
+ "_view_module_version": "1.5.0",
980
+ "_view_name": "HTMLView",
981
+ "description": "",
982
+ "description_tooltip": null,
983
+ "layout": "IPY_MODEL_4a766f37197b41d7bfa496c0c6d393bf",
984
+ "placeholder": "​",
985
+ "style": "IPY_MODEL_a436c3949572481cbde16838298cbf93",
986
+ "value": "Generating embeddings: 100%"
987
+ }
988
+ },
989
+ "a436c3949572481cbde16838298cbf93": {
990
+ "model_module": "@jupyter-widgets/controls",
991
+ "model_module_version": "1.5.0",
992
+ "model_name": "DescriptionStyleModel",
993
+ "state": {
994
+ "_model_module": "@jupyter-widgets/controls",
995
+ "_model_module_version": "1.5.0",
996
+ "_model_name": "DescriptionStyleModel",
997
+ "_view_count": null,
998
+ "_view_module": "@jupyter-widgets/base",
999
+ "_view_module_version": "1.2.0",
1000
+ "_view_name": "StyleView",
1001
+ "description_width": ""
1002
+ }
1003
+ },
1004
+ "a88124e34ad24f19bdcbcd73e998168a": {
1005
+ "model_module": "@jupyter-widgets/controls",
1006
+ "model_module_version": "1.5.0",
1007
+ "model_name": "FloatProgressModel",
1008
+ "state": {
1009
+ "_dom_classes": [],
1010
+ "_model_module": "@jupyter-widgets/controls",
1011
+ "_model_module_version": "1.5.0",
1012
+ "_model_name": "FloatProgressModel",
1013
+ "_view_count": null,
1014
+ "_view_module": "@jupyter-widgets/controls",
1015
+ "_view_module_version": "1.5.0",
1016
+ "_view_name": "ProgressView",
1017
+ "bar_style": "success",
1018
+ "description": "",
1019
+ "description_tooltip": null,
1020
+ "layout": "IPY_MODEL_4e905c17eddc44c299aabf699ec33642",
1021
+ "max": 14,
1022
+ "min": 0,
1023
+ "orientation": "horizontal",
1024
+ "style": "IPY_MODEL_ab738a29078d43aaa3364b3076f1eca0",
1025
+ "value": 14
1026
+ }
1027
+ },
1028
+ "ab59db85ad504297a3c56e3d63f5d474": {
1029
+ "model_module": "@jupyter-widgets/base",
1030
+ "model_module_version": "1.2.0",
1031
+ "model_name": "LayoutModel",
1032
+ "state": {
1033
+ "_model_module": "@jupyter-widgets/base",
1034
+ "_model_module_version": "1.2.0",
1035
+ "_model_name": "LayoutModel",
1036
+ "_view_count": null,
1037
+ "_view_module": "@jupyter-widgets/base",
1038
+ "_view_module_version": "1.2.0",
1039
+ "_view_name": "LayoutView",
1040
+ "align_content": null,
1041
+ "align_items": null,
1042
+ "align_self": null,
1043
+ "border": null,
1044
+ "bottom": null,
1045
+ "display": null,
1046
+ "flex": null,
1047
+ "flex_flow": null,
1048
+ "grid_area": null,
1049
+ "grid_auto_columns": null,
1050
+ "grid_auto_flow": null,
1051
+ "grid_auto_rows": null,
1052
+ "grid_column": null,
1053
+ "grid_gap": null,
1054
+ "grid_row": null,
1055
+ "grid_template_areas": null,
1056
+ "grid_template_columns": null,
1057
+ "grid_template_rows": null,
1058
+ "height": null,
1059
+ "justify_content": null,
1060
+ "justify_items": null,
1061
+ "left": null,
1062
+ "margin": null,
1063
+ "max_height": null,
1064
+ "max_width": null,
1065
+ "min_height": null,
1066
+ "min_width": null,
1067
+ "object_fit": null,
1068
+ "object_position": null,
1069
+ "order": null,
1070
+ "overflow": null,
1071
+ "overflow_x": null,
1072
+ "overflow_y": null,
1073
+ "padding": null,
1074
+ "right": null,
1075
+ "top": null,
1076
+ "visibility": null,
1077
+ "width": null
1078
+ }
1079
+ },
1080
+ "ab738a29078d43aaa3364b3076f1eca0": {
1081
+ "model_module": "@jupyter-widgets/controls",
1082
+ "model_module_version": "1.5.0",
1083
+ "model_name": "ProgressStyleModel",
1084
+ "state": {
1085
+ "_model_module": "@jupyter-widgets/controls",
1086
+ "_model_module_version": "1.5.0",
1087
+ "_model_name": "ProgressStyleModel",
1088
+ "_view_count": null,
1089
+ "_view_module": "@jupyter-widgets/base",
1090
+ "_view_module_version": "1.2.0",
1091
+ "_view_name": "StyleView",
1092
+ "bar_color": null,
1093
+ "description_width": ""
1094
+ }
1095
+ },
1096
+ "ae615040ed1a4a47838aaa99192fd33b": {
1097
+ "model_module": "@jupyter-widgets/base",
1098
+ "model_module_version": "1.2.0",
1099
+ "model_name": "LayoutModel",
1100
+ "state": {
1101
+ "_model_module": "@jupyter-widgets/base",
1102
+ "_model_module_version": "1.2.0",
1103
+ "_model_name": "LayoutModel",
1104
+ "_view_count": null,
1105
+ "_view_module": "@jupyter-widgets/base",
1106
+ "_view_module_version": "1.2.0",
1107
+ "_view_name": "LayoutView",
1108
+ "align_content": null,
1109
+ "align_items": null,
1110
+ "align_self": null,
1111
+ "border": null,
1112
+ "bottom": null,
1113
+ "display": null,
1114
+ "flex": null,
1115
+ "flex_flow": null,
1116
+ "grid_area": null,
1117
+ "grid_auto_columns": null,
1118
+ "grid_auto_flow": null,
1119
+ "grid_auto_rows": null,
1120
+ "grid_column": null,
1121
+ "grid_gap": null,
1122
+ "grid_row": null,
1123
+ "grid_template_areas": null,
1124
+ "grid_template_columns": null,
1125
+ "grid_template_rows": null,
1126
+ "height": null,
1127
+ "justify_content": null,
1128
+ "justify_items": null,
1129
+ "left": null,
1130
+ "margin": null,
1131
+ "max_height": null,
1132
+ "max_width": null,
1133
+ "min_height": null,
1134
+ "min_width": null,
1135
+ "object_fit": null,
1136
+ "object_position": null,
1137
+ "order": null,
1138
+ "overflow": null,
1139
+ "overflow_x": null,
1140
+ "overflow_y": null,
1141
+ "padding": null,
1142
+ "right": null,
1143
+ "top": null,
1144
+ "visibility": null,
1145
+ "width": null
1146
+ }
1147
+ },
1148
+ "d1a558eb15cf43f8a013a91b9262eee5": {
1149
+ "model_module": "@jupyter-widgets/base",
1150
+ "model_module_version": "1.2.0",
1151
+ "model_name": "LayoutModel",
1152
+ "state": {
1153
+ "_model_module": "@jupyter-widgets/base",
1154
+ "_model_module_version": "1.2.0",
1155
+ "_model_name": "LayoutModel",
1156
+ "_view_count": null,
1157
+ "_view_module": "@jupyter-widgets/base",
1158
+ "_view_module_version": "1.2.0",
1159
+ "_view_name": "LayoutView",
1160
+ "align_content": null,
1161
+ "align_items": null,
1162
+ "align_self": null,
1163
+ "border": null,
1164
+ "bottom": null,
1165
+ "display": null,
1166
+ "flex": null,
1167
+ "flex_flow": null,
1168
+ "grid_area": null,
1169
+ "grid_auto_columns": null,
1170
+ "grid_auto_flow": null,
1171
+ "grid_auto_rows": null,
1172
+ "grid_column": null,
1173
+ "grid_gap": null,
1174
+ "grid_row": null,
1175
+ "grid_template_areas": null,
1176
+ "grid_template_columns": null,
1177
+ "grid_template_rows": null,
1178
+ "height": null,
1179
+ "justify_content": null,
1180
+ "justify_items": null,
1181
+ "left": null,
1182
+ "margin": null,
1183
+ "max_height": null,
1184
+ "max_width": null,
1185
+ "min_height": null,
1186
+ "min_width": null,
1187
+ "object_fit": null,
1188
+ "object_position": null,
1189
+ "order": null,
1190
+ "overflow": null,
1191
+ "overflow_x": null,
1192
+ "overflow_y": null,
1193
+ "padding": null,
1194
+ "right": null,
1195
+ "top": null,
1196
+ "visibility": null,
1197
+ "width": null
1198
+ }
1199
+ },
1200
+ "f5f3f69abfd149f281a2f0c3f58d3284": {
1201
+ "model_module": "@jupyter-widgets/base",
1202
+ "model_module_version": "1.2.0",
1203
+ "model_name": "LayoutModel",
1204
+ "state": {
1205
+ "_model_module": "@jupyter-widgets/base",
1206
+ "_model_module_version": "1.2.0",
1207
+ "_model_name": "LayoutModel",
1208
+ "_view_count": null,
1209
+ "_view_module": "@jupyter-widgets/base",
1210
+ "_view_module_version": "1.2.0",
1211
+ "_view_name": "LayoutView",
1212
+ "align_content": null,
1213
+ "align_items": null,
1214
+ "align_self": null,
1215
+ "border": null,
1216
+ "bottom": null,
1217
+ "display": null,
1218
+ "flex": null,
1219
+ "flex_flow": null,
1220
+ "grid_area": null,
1221
+ "grid_auto_columns": null,
1222
+ "grid_auto_flow": null,
1223
+ "grid_auto_rows": null,
1224
+ "grid_column": null,
1225
+ "grid_gap": null,
1226
+ "grid_row": null,
1227
+ "grid_template_areas": null,
1228
+ "grid_template_columns": null,
1229
+ "grid_template_rows": null,
1230
+ "height": null,
1231
+ "justify_content": null,
1232
+ "justify_items": null,
1233
+ "left": null,
1234
+ "margin": null,
1235
+ "max_height": null,
1236
+ "max_width": null,
1237
+ "min_height": null,
1238
+ "min_width": null,
1239
+ "object_fit": null,
1240
+ "object_position": null,
1241
+ "order": null,
1242
+ "overflow": null,
1243
+ "overflow_x": null,
1244
+ "overflow_y": null,
1245
+ "padding": null,
1246
+ "right": null,
1247
+ "top": null,
1248
+ "visibility": null,
1249
+ "width": null
1250
+ }
1251
+ },
1252
+ "fff2627bdf20445f8507a7792a17546d": {
1253
+ "model_module": "@jupyter-widgets/controls",
1254
+ "model_module_version": "1.5.0",
1255
+ "model_name": "HTMLModel",
1256
+ "state": {
1257
+ "_dom_classes": [],
1258
+ "_model_module": "@jupyter-widgets/controls",
1259
+ "_model_module_version": "1.5.0",
1260
+ "_model_name": "HTMLModel",
1261
+ "_view_count": null,
1262
+ "_view_module": "@jupyter-widgets/controls",
1263
+ "_view_module_version": "1.5.0",
1264
+ "_view_name": "HTMLView",
1265
+ "description": "",
1266
+ "description_tooltip": null,
1267
+ "layout": "IPY_MODEL_ae615040ed1a4a47838aaa99192fd33b",
1268
+ "placeholder": "​",
1269
+ "style": "IPY_MODEL_7e3db69b3e20451f8fc88631b7915a39",
1270
+ "value": " 14/14 [00:00&lt;00:00, 78.64it/s]"
1271
+ }
1272
+ }
1273
+ }
1274
+ }
1275
+ },
1276
+ "nbformat": 4,
1277
+ "nbformat_minor": 0
1278
+ }