|
210 | 210 | "name": "stdout", |
211 | 211 | "output_type": "stream", |
212 | 212 | "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" |
215 | 215 | ] |
216 | 216 | } |
217 | 217 | ], |
|
266 | 266 | "cell_type": "code", |
267 | 267 | "execution_count": 6, |
268 | 268 | "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 | + ], |
270 | 278 | "source": [ |
271 | | - "index.load(data)" |
| 279 | + "keys = index.load(data)\n", |
| 280 | + "\n", |
| 281 | + "print(keys)" |
272 | 282 | ] |
273 | 283 | }, |
274 | 284 | { |
|
278 | 288 | ">By default, `load` will create a unique Redis \"key\" as a combination of the index key `prefix` and a UUID." |
279 | 289 | ] |
280 | 290 | }, |
| 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 | + }, |
281 | 300 | { |
282 | 301 | "cell_type": "code", |
283 | 302 | "execution_count": 7, |
284 | 303 | "metadata": {}, |
285 | 304 | "outputs": [ |
286 | 305 | { |
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" |
292 | 318 | } |
293 | 319 | ], |
294 | 320 | "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:\"))" |
298 | 322 | ] |
299 | 323 | }, |
300 | 324 | { |
|
309 | 333 | "cell_type": "code", |
310 | 334 | "execution_count": 8, |
311 | 335 | "metadata": {}, |
312 | | - "outputs": [], |
| 336 | + "outputs": [ |
| 337 | + { |
| 338 | + "name": "stdout", |
| 339 | + "output_type": "stream", |
| 340 | + "text": [ |
| 341 | + "['user:056675110eba40009886b4c7a186b91f']\n" |
| 342 | + ] |
| 343 | + } |
| 344 | + ], |
313 | 345 | "source": [ |
314 | 346 | "# Add more data\n", |
315 | 347 | "new_data = [{\n", |
|
319 | 351 | " 'credit_score': 'high',\n", |
320 | 352 | " 'user_embedding': np.array([0.1, 0.3, 0.5], dtype=np.float32).tobytes()\n", |
321 | 353 | "}]\n", |
322 | | - "index.load(new_data)" |
| 354 | + "keys = index.load(new_data)\n", |
| 355 | + "\n", |
| 356 | + "print(keys)" |
323 | 357 | ] |
324 | 358 | }, |
325 | 359 | { |
|
399 | 433 | "execution_count": 11, |
400 | 434 | "metadata": {}, |
401 | 435 | "outputs": [ |
402 | | - { |
403 | | - "name": "stdout", |
404 | | - "output_type": "stream", |
405 | | - "text": [ |
406 | | - "Index already exists, not overwriting.\n" |
407 | | - ] |
408 | | - }, |
409 | 436 | { |
410 | 437 | "data": { |
411 | 438 | "text/html": [ |
|
426 | 453 | " use_async=True\n", |
427 | 454 | ")\n", |
428 | 455 | "\n", |
429 | | - "# create the index\n", |
430 | | - "await index.acreate()\n", |
431 | | - "\n", |
432 | 456 | "# execute the vector query async\n", |
433 | 457 | "results = await index.aquery(query)\n", |
434 | 458 | "result_print(results)" |
|
632 | 656 | "│ bytes_per_record_avg │ 1 │\n", |
633 | 657 | "│ doc_table_size_mb │ 0.000400543 │\n", |
634 | 658 | "│ inverted_sz_mb │ 1.52588e-05 │\n", |
635 | | - "│ key_table_size_mb │ 0.000138283 │\n", |
| 659 | + "│ key_table_size_mb │ 0.000165939 │\n", |
636 | 660 | "│ offset_bits_per_record_avg │ nan │\n", |
637 | 661 | "│ offset_vectors_sz_mb │ 0 │\n", |
638 | 662 | "│ offsets_per_term_avg │ 0 │\n", |
639 | 663 | "│ records_per_doc_avg │ 4 │\n", |
640 | 664 | "│ sortable_values_size_mb │ 0 │\n", |
641 | | - "│ total_indexing_time │ 2.393 │\n", |
| 665 | + "│ total_indexing_time │ 0.822 │\n", |
642 | 666 | "│ total_inverted_index_blocks │ 7 │\n", |
643 | 667 | "│ vector_index_sz_mb │ 0.235603 │\n", |
644 | 668 | "╰─────────────────────────────┴─────────────╯\n" |
|
0 commit comments