Skip to content

Commit 6a2809b

Browse files
tylerhutchersonSam Partee
andauthored
Refactor Redis Storage and add JSON support (#78)
PR introduces a new `BaseStorage` class, subclassed by `HashStorage` and `JsonStorage`, to handle the underlying data structures (as well as I/O) for Redis. Includes: - New storage classes and type enums - New `key_separator` param for better use-customizability when constructing redis keys - Updated documentation and new user guide - Updated docstrings and examples --------- Co-authored-by: Sam Partee <sam.partee@redis.com>
1 parent 2f23e10 commit 6a2809b

35 files changed

+1999
-561
lines changed

docs/_extension/gallery_directive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""A directive to generate a gallery of images from structured data.
22
3-
Generating a gallery of images that are all the same size is a common
4-
pattern in documentation, and this can be cumbersome if the gallery is
5-
generated programmatically. This directive wraps this particular use-case
6-
in a helper-directive to generate it with a single YAML configuration file.
3+
Generating a gallery of images that are all the same size is a common pattern in
4+
documentation, and this can be cumbersome if the gallery is generated
5+
programmatically. This directive wraps this particular use-case in a helper-
6+
directive to generate it with a single YAML configuration file.
77
8-
It currently exists for maintainers of the pydata-sphinx-theme,
9-
but might be abstracted into a standalone package if it proves useful.
8+
It currently exists for maintainers of the pydata-sphinx-theme, but might be
9+
abstracted into a standalone package if it proves useful.
1010
"""
1111
from pathlib import Path
1212
from typing import Any, Dict, List

docs/api/searchindex.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ SearchIndex
1313
.. autosummary::
1414

1515
SearchIndex.__init__
16+
SearchIndex.client
17+
SearchIndex.name
18+
SearchIndex.prefix
19+
SearchIndex.key_separator
20+
SearchIndex.storage_type
1621
SearchIndex.from_yaml
1722
SearchIndex.from_dict
1823
SearchIndex.from_existing
24+
SearchIndex.connect
25+
SearchIndex.create
26+
SearchIndex.load
1927
SearchIndex.search
2028
SearchIndex.query
21-
SearchIndex.create
2229
SearchIndex.delete
23-
SearchIndex.load
24-
SearchIndex.client
25-
SearchIndex.connect
26-
SearchIndex.disconnect
2730
SearchIndex.info
31+
SearchIndex.disconnect
2832

2933

3034

@@ -44,17 +48,22 @@ AsyncSearchIndex
4448
.. autosummary::
4549

4650
AsyncSearchIndex.__init__
51+
AsyncSearchIndex.client
52+
AsyncSearchIndex.name
53+
AsyncSearchIndex.prefix
54+
AsyncSearchIndex.key_separator
55+
AsyncSearchIndex.storage_type
4756
AsyncSearchIndex.from_yaml
4857
AsyncSearchIndex.from_dict
4958
AsyncSearchIndex.from_existing
59+
AsyncSearchIndex.connect
60+
AsyncSearchIndex.create
61+
AsyncSearchIndex.load
5062
AsyncSearchIndex.search
5163
AsyncSearchIndex.query
52-
AsyncSearchIndex.create
5364
AsyncSearchIndex.delete
54-
AsyncSearchIndex.load
55-
AsyncSearchIndex.connect
56-
AsyncSearchIndex.disconnect
5765
AsyncSearchIndex.info
66+
AsyncSearchIndex.disconnect
5867

5968

6069

docs/examples/openai_qna.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"source": [
4747
"# first we need to install a few things\n",
4848
"\n",
49-
"!pip install pandas wget tenacity tiktoken openai"
49+
"!pip install pandas wget tenacity tiktoken openai==0.28.1"
5050
]
5151
},
5252
{

docs/user_guide/getting_started_01.ipynb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
"index:\n",
128128
" name: user_index\n",
129129
" prefix: user\n",
130+
" storage_type: hash\n",
131+
" key_separator: ':'\n",
130132
"\n",
131133
"fields:\n",
132134
" # define tag fields\n",
@@ -162,6 +164,8 @@
162164
" \"index\": {\n",
163165
" \"name\": \"user_index\",\n",
164166
" \"prefix\": \"user\",\n",
167+
" \"storage_type\": \"hash\",\n",
168+
" \"key_separator\": \":\"\n",
165169
" },\n",
166170
" \"fields\": {\n",
167171
" \"tag\": [{\"name\": \"credit_score\"}],\n",
@@ -217,8 +221,8 @@
217221
"name": "stdout",
218222
"output_type": "stream",
219223
"text": [
220-
"\u001b[32m16:03:01\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
221-
"\u001b[32m16:03:01\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
224+
"\u001b[32m22:49:46\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
225+
"\u001b[32m22:49:46\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
222226
]
223227
}
224228
],
@@ -465,7 +469,7 @@
465469
],
466470
"source": [
467471
"# create a new SearchIndex instance from an existing index\n",
468-
"existing_index = SearchIndex.from_existing(\"user_index\", \"redis://localhost:6379\")\n",
472+
"existing_index = SearchIndex.from_existing(name=\"user_index\", redis_url=\"redis://localhost:6379\")\n",
469473
"\n",
470474
"# run the same query\n",
471475
"results = existing_index.query(query)\n",
@@ -583,7 +587,10 @@
583587
{
584588
"data": {
585589
"text/plain": [
586-
"{'index': {'name': 'user_index', 'prefix': 'user'},\n",
590+
"{'index': {'name': 'user_index',\n",
591+
" 'prefix': 'user',\n",
592+
" 'storage_type': 'hash',\n",
593+
" 'key_separator': ':'},\n",
587594
" 'fields': {'tag': [{'name': 'credit_score'}],\n",
588595
" 'text': [{'name': 'job'}],\n",
589596
" 'numeric': [{'name': 'age'}],\n",
@@ -612,7 +619,10 @@
612619
{
613620
"data": {
614621
"text/plain": [
615-
"{'index': {'name': 'user_index', 'prefix': 'user'},\n",
622+
"{'index': {'name': 'user_index',\n",
623+
" 'prefix': 'user',\n",
624+
" 'storage_type': 'hash',\n",
625+
" 'key_separator': ':'},\n",
616626
" 'fields': {'tag': [{'name': 'credit_score'}, {'name': 'job'}],\n",
617627
" 'text': [],\n",
618628
" 'numeric': [{'name': 'age'}],\n",
@@ -725,7 +735,7 @@
725735
"│ offsets_per_term_avg │ 0 │\n",
726736
"│ records_per_doc_avg │ 4 │\n",
727737
"│ sortable_values_size_mb │ 0 │\n",
728-
"│ total_indexing_time │ 0.59 \n",
738+
"│ total_indexing_time │ 1.738\n",
729739
"│ total_inverted_index_blocks │ 7 │\n",
730740
"│ vector_index_sz_mb │ 0.235603 │\n",
731741
"╰─────────────────────────────┴─────────────╯\n"

0 commit comments

Comments
 (0)