Skip to content

Commit 582f333

Browse files
tylerhutchersonSpartee
authored andcommitted
Return keys on load (#93)
Returns the list of keys written to redis on load/write.
1 parent dbdb2d6 commit 582f333

File tree

9 files changed

+171
-95
lines changed

9 files changed

+171
-95
lines changed

docs/user_guide/getting_started_01.ipynb

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@
210210
"name": "stdout",
211211
"output_type": "stream",
212212
"text": [
213-
"\u001b[32m11:20:00\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
214-
"\u001b[32m11:20:00\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
213+
"\u001b[32m11:16:09\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
214+
"\u001b[32m11:16:09\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
215215
]
216216
}
217217
],
@@ -266,9 +266,19 @@
266266
"cell_type": "code",
267267
"execution_count": 6,
268268
"metadata": {},
269-
"outputs": [],
269+
"outputs": [
270+
{
271+
"name": "stdout",
272+
"output_type": "stream",
273+
"text": [
274+
"['user:bb34a7ba16f541679b6219ca8d1cf369', 'user:04d6f8b805dd45c4b83616272e08898c', 'user:5ccee56134bd460cbfaf9fa492633ba5']\n"
275+
]
276+
}
277+
],
270278
"source": [
271-
"index.load(data)"
279+
"keys = index.load(data)\n",
280+
"\n",
281+
"print(keys)"
272282
]
273283
},
274284
{
@@ -278,23 +288,37 @@
278288
">By default, `load` will create a unique Redis \"key\" as a combination of the index key `prefix` and a UUID."
279289
]
280290
},
291+
{
292+
"cell_type": "markdown",
293+
"metadata": {},
294+
"source": [
295+
"### Fetch an object from Redis\n",
296+
"\n",
297+
"Fetch one of the previously written objects:"
298+
]
299+
},
281300
{
282301
"cell_type": "code",
283302
"execution_count": 7,
284303
"metadata": {},
285304
"outputs": [
286305
{
287-
"name": "stdout",
288-
"output_type": "stream",
289-
"text": [
290-
"[b'user:75dc4a80a6344c69bdf6f7d017d156fd', b'user:4eac1d79ed2b4b008418cf2f72dcc620', b'user:904500d11c1e45d2a363db778c0ded11']\n"
291-
]
306+
"data": {
307+
"text/plain": [
308+
"{'user': 'john',\n",
309+
" 'age': '1',\n",
310+
" 'job': 'engineer',\n",
311+
" 'credit_score': 'high',\n",
312+
" 'user_embedding': b'\\xcd\\xcc\\xcc=\\xcd\\xcc\\xcc=\\x00\\x00\\x00?'}"
313+
]
314+
},
315+
"execution_count": 7,
316+
"metadata": {},
317+
"output_type": "execute_result"
292318
}
293319
],
294320
"source": [
295-
"# Investigate the written kes\n",
296-
"index_keys = [key for key in index.client.scan_iter(\"user:*\")]\n",
297-
"print(index_keys)"
321+
"index.fetch(id=keys[0].strip(\"user:\"))"
298322
]
299323
},
300324
{
@@ -309,7 +333,15 @@
309333
"cell_type": "code",
310334
"execution_count": 8,
311335
"metadata": {},
312-
"outputs": [],
336+
"outputs": [
337+
{
338+
"name": "stdout",
339+
"output_type": "stream",
340+
"text": [
341+
"['user:056675110eba40009886b4c7a186b91f']\n"
342+
]
343+
}
344+
],
313345
"source": [
314346
"# Add more data\n",
315347
"new_data = [{\n",
@@ -319,7 +351,9 @@
319351
" 'credit_score': 'high',\n",
320352
" 'user_embedding': np.array([0.1, 0.3, 0.5], dtype=np.float32).tobytes()\n",
321353
"}]\n",
322-
"index.load(new_data)"
354+
"keys = index.load(new_data)\n",
355+
"\n",
356+
"print(keys)"
323357
]
324358
},
325359
{
@@ -399,13 +433,6 @@
399433
"execution_count": 11,
400434
"metadata": {},
401435
"outputs": [
402-
{
403-
"name": "stdout",
404-
"output_type": "stream",
405-
"text": [
406-
"Index already exists, not overwriting.\n"
407-
]
408-
},
409436
{
410437
"data": {
411438
"text/html": [
@@ -426,9 +453,6 @@
426453
" use_async=True\n",
427454
")\n",
428455
"\n",
429-
"# create the index\n",
430-
"await index.acreate()\n",
431-
"\n",
432456
"# execute the vector query async\n",
433457
"results = await index.aquery(query)\n",
434458
"result_print(results)"
@@ -632,13 +656,13 @@
632656
"│ bytes_per_record_avg │ 1 │\n",
633657
"│ doc_table_size_mb │ 0.000400543 │\n",
634658
"│ inverted_sz_mb │ 1.52588e-05 │\n",
635-
"│ key_table_size_mb │ 0.000138283\n",
659+
"│ key_table_size_mb │ 0.000165939\n",
636660
"│ offset_bits_per_record_avg │ nan │\n",
637661
"│ offset_vectors_sz_mb │ 0 │\n",
638662
"│ offsets_per_term_avg │ 0 │\n",
639663
"│ records_per_doc_avg │ 4 │\n",
640664
"│ sortable_values_size_mb │ 0 │\n",
641-
"│ total_indexing_time │ 2.393\n",
665+
"│ total_indexing_time │ 0.822\n",
642666
"│ total_inverted_index_blocks │ 7 │\n",
643667
"│ vector_index_sz_mb │ 0.235603 │\n",
644668
"╰─────────────────────────────┴─────────────╯\n"

docs/user_guide/hash_vs_json_05.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"# import necessary modules\n",
3737
"import pickle\n",
3838
"\n",
39-
"from redisvl.utils.utils import table_print, result_print\n",
39+
"from redisvl.utils.utils import table_print, result_print, buffer_to_array\n",
4040
"from redisvl.index import SearchIndex\n",
4141
"\n",
4242
"\n",
@@ -205,7 +205,7 @@
205205
"outputs": [],
206206
"source": [
207207
"# load hash data\n",
208-
"hindex.load(data)"
208+
"keys = hindex.load(data)"
209209
]
210210
},
211211
{
@@ -232,13 +232,13 @@
232232
"│ bytes_per_record_avg │ 3.40909 │\n",
233233
"│ doc_table_size_mb │ 0.000700951 │\n",
234234
"│ inverted_sz_mb │ 0.000143051 │\n",
235-
"│ key_table_size_mb │ 0.000221252\n",
235+
"│ key_table_size_mb │ 0.000248909\n",
236236
"│ offset_bits_per_record_avg │ 8 │\n",
237237
"│ offset_vectors_sz_mb │ 8.58307e-06 │\n",
238238
"│ offsets_per_term_avg │ 0.204545 │\n",
239239
"│ records_per_doc_avg │ 6.28571 │\n",
240240
"│ sortable_values_size_mb │ 0 │\n",
241-
"│ total_indexing_time │ 0.323\n",
241+
"│ total_indexing_time │ 0.595\n",
242242
"│ total_inverted_index_blocks │ 18 │\n",
243243
"│ vector_index_sz_mb │ 0.0202332 │\n",
244244
"╰─────────────────────────────┴─────────────╯\n"
@@ -379,9 +379,9 @@
379379
"name": "stdout",
380380
"output_type": "stream",
381381
"text": [
382-
"\u001b[32m17:26:19\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
383-
"\u001b[32m17:26:19\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user-hashes\n",
384-
"\u001b[32m17:26:19\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 2. user-json\n"
382+
"\u001b[32m11:23:10\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
383+
"\u001b[32m11:23:10\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user-hashes\n",
384+
"\u001b[32m11:23:10\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 2. user-json\n"
385385
]
386386
}
387387
],
@@ -409,7 +409,7 @@
409409
"json_data = data.copy()\n",
410410
"\n",
411411
"for d in json_data:\n",
412-
" d['user_embedding'] = np.frombuffer(d['user_embedding'], dtype=np.float32).tolist()"
412+
" d['user_embedding'] = buffer_to_array(d['user_embedding'], dtype=np.float32)"
413413
]
414414
},
415415
{
@@ -444,7 +444,7 @@
444444
"metadata": {},
445445
"outputs": [],
446446
"source": [
447-
"jindex.load(json_data)"
447+
"keys = jindex.load(json_data)"
448448
]
449449
},
450450
{

docs/user_guide/hybrid_queries_02.ipynb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"cell_type": "markdown",
66
"metadata": {},
77
"source": [
8-
"# Query\n",
8+
"# Querying with RedisVL\n",
99
"\n",
1010
"In this notebook, we will explore more complex queries that can be performed with ``redisvl``\n",
1111
"\n",
@@ -97,8 +97,8 @@
9797
"name": "stdout",
9898
"output_type": "stream",
9999
"text": [
100-
"\u001b[32m17:11:26\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
101-
"\u001b[32m17:11:26\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
100+
"\u001b[32m11:17:50\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
101+
"\u001b[32m11:17:50\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
102102
]
103103
}
104104
],
@@ -113,8 +113,7 @@
113113
"metadata": {},
114114
"outputs": [],
115115
"source": [
116-
"# load expects an iterable of dictionaries\n",
117-
"index.load(data)"
116+
"keys = index.load(data)"
118117
]
119118
},
120119
{
@@ -1108,10 +1107,10 @@
11081107
"name": "stdout",
11091108
"output_type": "stream",
11101109
"text": [
1111-
"{'id': 'v1:533943d08dc44edcae8bdf3d0f87d93b', 'payload': None, 'user': 'john', 'age': '18', 'job': 'engineer', 'credit_score': 'high', 'office_location': '-122.4194,37.7749', 'user_embedding': '==\\x00\\x00\\x00?'}\n",
1112-
"{'id': 'v1:055a35683f094dcdae82d51ed2fb08ec', 'payload': None, 'user': 'nancy', 'age': '94', 'job': 'doctor', 'credit_score': 'high', 'office_location': '-122.4194,37.7749', 'user_embedding': '333?=\\x00\\x00\\x00?'}\n",
1113-
"{'id': 'v1:004060e2f35841c7aca9c757f4a49327', 'payload': None, 'user': 'tyler', 'age': '100', 'job': 'engineer', 'credit_score': 'high', 'office_location': '-122.0839,37.3861', 'user_embedding': '=>\\x00\\x00\\x00?'}\n",
1114-
"{'id': 'v1:b92b9bc533a64efd9e979ed176a5e036', 'payload': None, 'user': 'tim', 'age': '12', 'job': 'dermatologist', 'credit_score': 'high', 'office_location': '-122.0839,37.3861', 'user_embedding': '>>\\x00\\x00\\x00?'}\n"
1110+
"{'id': 'v1:c0b2cc8f2b384a47902b1497d6510a0a', 'payload': None, 'user': 'john', 'age': '18', 'job': 'engineer', 'credit_score': 'high', 'office_location': '-122.4194,37.7749', 'user_embedding': '==\\x00\\x00\\x00?'}\n",
1111+
"{'id': 'v1:b2668a5bcd64496b92faf1fdba4b4f68', 'payload': None, 'user': 'nancy', 'age': '94', 'job': 'doctor', 'credit_score': 'high', 'office_location': '-122.4194,37.7749', 'user_embedding': '333?=\\x00\\x00\\x00?'}\n",
1112+
"{'id': 'v1:e2b24b1c67784695b8c270b8a26c3126', 'payload': None, 'user': 'tyler', 'age': '100', 'job': 'engineer', 'credit_score': 'high', 'office_location': '-122.0839,37.3861', 'user_embedding': '=>\\x00\\x00\\x00?'}\n",
1113+
"{'id': 'v1:bdfd71ed59904c97a2c456c1c7adca7e', 'payload': None, 'user': 'tim', 'age': '12', 'job': 'dermatologist', 'credit_score': 'high', 'office_location': '-122.0839,37.3861', 'user_embedding': '>>\\x00\\x00\\x00?'}\n"
11151114
]
11161115
}
11171116
],

docs/user_guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
myst:
33
html_meta:
44
"description lang=en": |
5-
User Guides for RedisVL users
5+
User Guides for RedisVL
66
---
77

88
# User Guides

docs/user_guide/llmcache_03.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"\n",
3737
"def ask_openai(question: str) -> str:\n",
3838
" response = openai.Completion.create(\n",
39-
" engine=\"text-davinci-003\",\n",
39+
" engine=\"gpt-3.5-turbo-instruct\",\n",
4040
" prompt=question,\n",
4141
" max_tokens=200\n",
4242
" )\n",

0 commit comments

Comments
 (0)