Skip to content

Commit 6c50700

Browse files
committed
update for redisvl 0.4.0
1 parent 2eb9a1d commit 6c50700

22 files changed

+2343
-3614
lines changed

python-recipes/RAG/01_redisvl.ipynb

Lines changed: 169 additions & 1554 deletions
Large diffs are not rendered by default.

python-recipes/RAG/02_langchain.ipynb

Lines changed: 200 additions & 57 deletions
Large diffs are not rendered by default.

python-recipes/RAG/03_llamaindex.ipynb

Lines changed: 37 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,11 @@
6060
},
6161
{
6262
"cell_type": "code",
63-
"execution_count": 1,
63+
"execution_count": null,
6464
"metadata": {},
65-
"outputs": [
66-
{
67-
"name": "stdout",
68-
"output_type": "stream",
69-
"text": [
70-
"Note: you may need to restart the kernel to use updated packages.\n"
71-
]
72-
}
73-
],
65+
"outputs": [],
7466
"source": [
75-
"%pip install -q llama-index llama-index-vector-stores-redis llama-index-embeddings-cohere llama-index-embeddings-openai"
67+
"%pip install -q llama-index \"llama-index-vector-stores-redis>=0.4.0\" llama-index-embeddings-cohere llama-index-embeddings-openai"
7668
]
7769
},
7870
{
@@ -132,7 +124,7 @@
132124
},
133125
{
134126
"cell_type": "code",
135-
"execution_count": 1,
127+
"execution_count": 3,
136128
"metadata": {},
137129
"outputs": [],
138130
"source": [
@@ -171,7 +163,7 @@
171163
},
172164
{
173165
"cell_type": "code",
174-
"execution_count": 2,
166+
"execution_count": 4,
175167
"metadata": {
176168
"colab": {
177169
"base_uri": "https://localhost:8080/"
@@ -184,13 +176,8 @@
184176
"name": "stdout",
185177
"output_type": "stream",
186178
"text": [
187-
"Sample doc Doc ID: c013353e-dae7-4d17-befd-9e784c8acf79\n",
188-
"Text: UNITED STATES SECURITIES AND EXCHANGE COMMISSION Washington,\n",
189-
"D.C. 20549 FORM 10-K (Mark One) ☒ ANNUAL REPORT PURSUANT T O SECTION\n",
190-
"13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934 For the fiscal year\n",
191-
"ended September 24, 2022 or ☐ TRANSITION REPORT PURSUANT T O SECTION\n",
192-
"13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934 For the transition\n",
193-
"period...\n"
179+
"Sample doc Doc ID: b90e8ae9-7204-4e86-87ff-16cc68f9fff4\n",
180+
"Text: 2022 COLORADO\n"
194181
]
195182
}
196183
],
@@ -209,7 +196,7 @@
209196
},
210197
{
211198
"cell_type": "code",
212-
"execution_count": 3,
199+
"execution_count": 5,
213200
"metadata": {},
214201
"outputs": [],
215202
"source": [
@@ -229,7 +216,7 @@
229216
},
230217
{
231218
"cell_type": "code",
232-
"execution_count": 4,
219+
"execution_count": 6,
233220
"metadata": {},
234221
"outputs": [],
235222
"source": [
@@ -251,7 +238,7 @@
251238
},
252239
{
253240
"cell_type": "code",
254-
"execution_count": 5,
241+
"execution_count": 7,
255242
"metadata": {},
256243
"outputs": [],
257244
"source": [
@@ -269,30 +256,30 @@
269256
},
270257
{
271258
"cell_type": "code",
272-
"execution_count": 6,
259+
"execution_count": 8,
273260
"metadata": {},
274261
"outputs": [
275262
{
276263
"name": "stdout",
277264
"output_type": "stream",
278265
"text": [
279-
"Node ID: d2e6cd9c-0716-49d8-8563-407a00d05445\n",
280-
"Text: Table of Contents FISCAL 2023 NIKE BRAND REVENUE HIGHLIGHTS The\n",
266+
"Node ID: 023a5d47-4560-4591-ab20-37e4522863aa\n",
267+
"Text: Table of Contents FISCAL 2023 NIKE BRAND REVENUE HIGHLIGHTSThe\n",
281268
"following tables present NIKE Brand revenues disaggregated by\n",
282269
"reportable operating segment, distribution channel and major product\n",
283-
"line: FISCAL 2023 COMPARED TO FISCAL 2022 •NIKE, Inc. Revenues were\n",
270+
"line: FISCAL 2023 COMPARED TO FISCAL 2022 • NIKE, Inc. Revenues were\n",
284271
"$51.2 billion in fiscal 2023, which increased 10% and 16% compared to\n",
285272
"fiscal 2022 on...\n",
286-
"Score: 0.900\n",
273+
"Score: 0.899\n",
287274
"\n",
288-
"Node ID: 28542d3b-b345-4e9e-b675-f62361ec85d9\n",
289-
"Text: Table of Contents NORTH AMERICA (Dollars in millions) FISCAL\n",
290-
"2023FISCAL 2022 % CHANGE% CHANGE EXCLUDING CURRENCY CHANGESFISCAL 2021\n",
291-
"% CHANGE% CHANGE EXCLUDING CURRENCY CHANGES Revenues by: Footwear $\n",
292-
"14,897 $ 12,228 22 % 22 %$ 11,644 5 % 5 % Apparel 5,947 5,492 8 % 9 %\n",
293-
"5,028 9 % 9 % Equipment 764 633 21 % 21 % 507 25 % 25 % TOTAL REVENUES\n",
294-
"$ 21,6...\n",
295-
"Score: 0.885\n",
275+
"Node ID: 10b3b6b1-112c-4279-a75a-d4d866c07f6b\n",
276+
"Text: Sales through NIKE Direct Global Brand Divisions in FISCAL 2023\n",
277+
"amounted to $21,308 million. Total NIKE Brand Wholesale Equivalent\n",
278+
"Revenues for FISCAL 2023 were $48,763 million, with a 10% rise from\n",
279+
"FISCAL 2022. NIKE Brand Wholesale Equivalent Revenues included sales\n",
280+
"from Men's, Women's, and NIKE Kids' categories. Jordan Brand revenues\n",
281+
"increased...\n",
282+
"Score: 0.883\n",
296283
"\n"
297284
]
298285
}
@@ -313,7 +300,7 @@
313300
},
314301
{
315302
"cell_type": "code",
316-
"execution_count": 7,
303+
"execution_count": 9,
317304
"metadata": {},
318305
"outputs": [
319306
{
@@ -322,7 +309,7 @@
322309
"\"NIKE's revenue in fiscal 23 was $51.2 billion.\""
323310
]
324311
},
325-
"execution_count": 7,
312+
"execution_count": 9,
326313
"metadata": {},
327314
"output_type": "execute_result"
328315
}
@@ -347,7 +334,7 @@
347334
},
348335
{
349336
"cell_type": "code",
350-
"execution_count": 8,
337+
"execution_count": 10,
351338
"metadata": {},
352339
"outputs": [],
353340
"source": [
@@ -388,7 +375,7 @@
388375
},
389376
{
390377
"cell_type": "code",
391-
"execution_count": 9,
378+
"execution_count": 11,
392379
"metadata": {},
393380
"outputs": [
394381
{
@@ -397,7 +384,7 @@
397384
"IndexInfo(name='custom_index', prefix='docs', key_separator=':', storage_type=<StorageType.HASH: 'hash'>)"
398385
]
399386
},
400-
"execution_count": 9,
387+
"execution_count": 11,
401388
"metadata": {},
402389
"output_type": "execute_result"
403390
}
@@ -408,7 +395,7 @@
408395
},
409396
{
410397
"cell_type": "code",
411-
"execution_count": 10,
398+
"execution_count": 12,
412399
"metadata": {},
413400
"outputs": [
414401
{
@@ -422,7 +409,7 @@
422409
" 'vector': HNSWVectorField(name='vector', type='vector', path=None, attrs=HNSWVectorFieldAttributes(dims=1536, algorithm=<VectorIndexAlgorithm.HNSW: 'HNSW'>, datatype=<VectorDataType.FLOAT32: 'FLOAT32'>, distance_metric=<VectorDistanceMetric.COSINE: 'COSINE'>, initial_cap=None, m=16, ef_construction=200, ef_runtime=10, epsilon=0.01))}"
423410
]
424411
},
425-
"execution_count": 10,
412+
"execution_count": 12,
426413
"metadata": {},
427414
"output_type": "execute_result"
428415
}
@@ -433,28 +420,7 @@
433420
},
434421
{
435422
"cell_type": "code",
436-
"execution_count": 11,
437-
"metadata": {},
438-
"outputs": [],
439-
"source": [
440-
"# from datetime import datetime\n",
441-
"\n",
442-
"\n",
443-
"# def date_to_timestamp(date_string: str) -> int:\n",
444-
"# date_format: str = \"%Y-%m-%d\"\n",
445-
"# return int(datetime.strptime(date_string, date_format).timestamp())\n",
446-
"\n",
447-
"\n",
448-
"# # iterate through documents and add new field\n",
449-
"# for document in docs:\n",
450-
"# document.metadata[\"updated_at\"] = date_to_timestamp(\n",
451-
"# document.metadata[\"last_modified_date\"]\n",
452-
"# )"
453-
]
454-
},
455-
{
456-
"cell_type": "code",
457-
"execution_count": 12,
423+
"execution_count": 14,
458424
"metadata": {},
459425
"outputs": [],
460426
"source": [
@@ -482,7 +448,7 @@
482448
},
483449
{
484450
"cell_type": "code",
485-
"execution_count": 13,
451+
"execution_count": 15,
486452
"metadata": {},
487453
"outputs": [],
488454
"source": [
@@ -510,23 +476,23 @@
510476
},
511477
{
512478
"cell_type": "code",
513-
"execution_count": 14,
479+
"execution_count": 16,
514480
"metadata": {},
515481
"outputs": [
516482
{
517483
"name": "stdout",
518484
"output_type": "stream",
519485
"text": [
520-
"Node ID: cd0c5d8f-e3b1-4cbb-aa6a-5960003cdb2d\n",
486+
"Node ID: 013f339e-7fda-4fc7-baf0-afbb3dadf47d\n",
521487
"Text: Table of Contents valuation. In the ordinary course of our\n",
522488
"business, there are many transactions and calculations for which the\n",
523489
"ultimate tax determination is uncertain. Significant judgment is\n",
524490
"required in evaluating and estimating our tax expense, assets, and\n",
525491
"liabilities. We are also subject to tax controversies in various\n",
526492
"jurisdictions that can...\n",
527-
"Score: 0.746\n",
493+
"Score: 0.747\n",
528494
"\n",
529-
"Node ID: 6745f668-4c7a-43bf-a9c3-9b04e1a497f8\n",
495+
"Node ID: ac3f2b03-0520-4a50-ba3e-a97ad0a6f643\n",
530496
"Text: Table of Contents Included in other income (expense), net in\n",
531497
"2021 and 2022 is a marketable equity securities valuation gain (loss)\n",
532498
"of $11.8 billion and $(12.7) billion from our equity investment in\n",
@@ -535,7 +501,7 @@
535501
"observable changes in ...\n",
536502
"Score: 0.740\n",
537503
"\n",
538-
"Node ID: 717666fe-fea5-488b-999c-84e6d8b9a0db\n",
504+
"Node ID: 62ef1673-dcfe-4ba0-a437-7b142cda4114\n",
539505
"Text: Exhibit 31.1 CERTIFICATIONS I, Andrew R. Jassy, certify that: 1.\n",
540506
"I have reviewed this Form 10-K of Amazon.com, Inc.; 2. Based on my\n",
541507
"knowledge, this report does not contain any untrue statement of a\n",

python-recipes/RAG/04_advanced_redisvl.ipynb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
}
9393
],
9494
"source": [
95-
"%pip install -q redis redisvl pandas \"unstructured[pdf]\" sentence-transformers langchain langchain-community \"openai>=1.57.0\" tqdm"
95+
"%pip install -q \"redisvl>=0.4.1\" pandas \"unstructured[pdf]\" sentence-transformers langchain langchain-community \"openai>=1.57.0\" tqdm"
9696
]
9797
},
9898
{
@@ -730,7 +730,6 @@
730730
},
731731
"outputs": [],
732732
"source": [
733-
"from redis import Redis\n",
734733
"from redisvl.index import SearchIndex\n",
735734
"\n",
736735
"\n",
@@ -774,12 +773,8 @@
774773
"metadata": {},
775774
"outputs": [],
776775
"source": [
777-
"# connect to redis\n",
778-
"client = Redis.from_url(REDIS_URL)\n",
779-
"\n",
780776
"# create an index from schema and the client\n",
781-
"index = SearchIndex.from_dict(schema)\n",
782-
"index.set_client(client)\n",
777+
"index = SearchIndex.from_dict(schema, redis_url=REDIS_URL)\n",
783778
"index.create(overwrite=True, drop=True)"
784779
]
785780
},
@@ -862,16 +857,25 @@
862857
},
863858
{
864859
"cell_type": "code",
865-
"execution_count": 21,
860+
"execution_count": 1,
866861
"metadata": {},
867-
"outputs": [],
862+
"outputs": [
863+
{
864+
"ename": "NameError",
865+
"evalue": "name 'schema' is not defined",
866+
"output_type": "error",
867+
"traceback": [
868+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
869+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
870+
"Cell \u001b[0;32mIn[1], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mredisvl\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mindex\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m AsyncSearchIndex\n\u001b[0;32m----> 3\u001b[0m index \u001b[38;5;241m=\u001b[39m AsyncSearchIndex\u001b[38;5;241m.\u001b[39mfrom_dict(\u001b[43mschema\u001b[49m, redis_url\u001b[38;5;241m=\u001b[39mREDIS_URL)\n",
871+
"\u001b[0;31mNameError\u001b[0m: name 'schema' is not defined"
872+
]
873+
}
874+
],
868875
"source": [
869-
"from redis.asyncio import Redis as AsyncRedis\n",
870876
"from redisvl.index import AsyncSearchIndex\n",
871877
"\n",
872-
"client = AsyncRedis.from_url(REDIS_URL)\n",
873-
"index = AsyncSearchIndex.from_dict(schema)\n",
874-
"_ = await index.set_client(client)"
878+
"index = AsyncSearchIndex.from_dict(schema, redis_url=REDIS_URL)"
875879
]
876880
},
877881
{

python-recipes/RAG/05_nvidia_ai_rag_redis.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"source": [
5454
"%pip install --upgrade -q langchain-core langchain-community langchain-nvidia-ai-endpoints\n",
5555
"%pip install -q \"unstructured[pdf]\" sentence-transformers\n",
56-
"%pip install -q redisvl>=0.3.0"
56+
"%pip install -q \"redisvl>=0.4.1\""
5757
]
5858
},
5959
{
@@ -608,7 +608,8 @@
608608
"name": "python3"
609609
},
610610
"language_info": {
611-
"name": "python"
611+
"name": "python",
612+
"version": "3.11.9"
612613
}
613614
},
614615
"nbformat": 4,

0 commit comments

Comments
 (0)