Skip to content

Commit 4f120b0

Browse files
Redis connection refactor (#104)
For ultimate clarity and safety of our library, the decision was made to separate the sync and async search index modules for now until we can better utilize the redis-py client to serve both needs simultaneously. This PR splits `SearchIndex` and `AsyncSearchIndex` into two classes. It also refactors the way RedisVL handles Redis connections (much more lightweight) and makes some major improvements to the overall documentation on these topics.
1 parent 8a55e35 commit 4f120b0

38 files changed

+1511
-1192
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ servedocs:
7777
# help: test - Run all tests
7878
.PHONY: test
7979
test:
80-
@python -m pytest
80+
@python -m pytest --log-level=CRITICAL
8181

8282
# help: test-verbose - Run all tests verbosely
8383
.PHONY: test-verbose
8484
test-verbose:
85-
@python -m pytest -vv -s
85+
@python -m pytest -vv -s --log-level=CRITICAL
8686

8787
# help: test-cov - Run all tests with coverage
8888
.PHONY: test-cov
8989
test-cov:
90-
@python -m pytest -vv --cov=./redisvl
90+
@python -m pytest -vv --cov=./redisvl --log-level=CRITICAL
9191

9292
# help: cov - generate html coverage report
9393
.PHONY: cov

conftest.py

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22
import pytest
33
import asyncio
44

5-
from redisvl.utils.connection import RedisConnection
5+
from redisvl.redis.connection import RedisConnectionFactory
66

7-
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379")
8-
9-
aredis = RedisConnection.get_async_redis_connection(REDIS_URL)
10-
redis = RedisConnection.get_redis_connection(REDIS_URL)
117

128
@pytest.fixture()
139
def redis_url():
14-
return REDIS_URL
10+
return os.getenv("REDIS_URL", "redis://localhost:6379")
1511

1612
@pytest.fixture
17-
def async_client():
18-
return aredis
13+
def async_client(redis_url):
14+
return RedisConnectionFactory.get_async_redis_connection(redis_url)
1915

2016
@pytest.fixture
21-
def client():
22-
return redis
23-
17+
def client(redis_url):
18+
return RedisConnectionFactory.get_redis_connection(redis_url)
2419

2520
@pytest.fixture
2621
def openai_key():
@@ -38,6 +33,68 @@ def gcp_location():
3833
def gcp_project_id():
3934
return os.getenv("GCP_PROJECT_ID")
4035

36+
37+
@pytest.fixture
38+
def sample_data():
39+
return [
40+
{
41+
"user": "john",
42+
"age": 18,
43+
"job": "engineer",
44+
"credit_score": "high",
45+
"location": "-122.4194,37.7749",
46+
"user_embedding": [0.1, 0.1, 0.5]
47+
},
48+
{
49+
"user": "mary",
50+
"age": 14,
51+
"job": "doctor",
52+
"credit_score": "low",
53+
"location": "-122.4194,37.7749",
54+
"user_embedding": [0.1, 0.1, 0.5]
55+
},
56+
{
57+
"user": "nancy",
58+
"age": 94,
59+
"job": "doctor",
60+
"credit_score": "high",
61+
"location": "-122.4194,37.7749",
62+
"user_embedding": [0.7, 0.1, 0.5]
63+
},
64+
{
65+
"user": "tyler",
66+
"age": 100,
67+
"job": "engineer",
68+
"credit_score": "high",
69+
"location": "-110.0839,37.3861",
70+
"user_embedding": [0.1, 0.4, 0.5]
71+
},
72+
{
73+
"user": "tim",
74+
"age": 12,
75+
"job": "dermatologist",
76+
"credit_score": "high",
77+
"location": "-110.0839,37.3861",
78+
"user_embedding": [0.4, 0.4, 0.5]
79+
},
80+
{
81+
"user": "taimur",
82+
"age": 15,
83+
"job": "CEO",
84+
"credit_score": "low",
85+
"location": "-110.0839,37.3861",
86+
"user_embedding": [0.6, 0.1, 0.5]
87+
},
88+
{
89+
"user": "joe",
90+
"age": 35,
91+
"job": "dentist",
92+
"credit_score": "medium",
93+
"location": "-110.0839,37.3861",
94+
"user_embedding": [0.9, 0.9, 0.1]
95+
},
96+
]
97+
4198
@pytest.fixture(scope="session")
4299
def event_loop():
43100
try:
@@ -48,7 +105,7 @@ def event_loop():
48105
loop.close()
49106

50107
@pytest.fixture
51-
def clear_db():
108+
def clear_db(redis):
52109
redis.flushall()
53110
yield
54111
redis.flushall()

docs/_static/gallery.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
- title: Arxiv Paper Search
3-
website: https://docsearch.redisventures.com
3+
website: https://docsearch.redisvl.com
44
img-bottom: ../_static/gallery-images/arxiv-search.png
55
- title: Real-Time Embeddings with Redis and Bytewax
66
website: https://github.com/awmatheson/real-time-embeddings

docs/_static/js/sidebar.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ const toc = [
22
{ header: "Overview", toc: [
33
{ title: "RedisVL", path: "/index.html" },
44
{ title: "Install", path: "/overview/installation.html" },
5-
{ title: "CLI", path: "/user_guide/cli.html" },
5+
{ title: "CLI", path: "/overview/cli.html" },
66
]},
77
{ header: "User Guides", toc: [
88
{ title: "Getting Started", path: "/user_guide/getting_started_01.html" },
99
{ title: "Query and Filter", path: "/user_guide/hybrid_queries_02.html" },
1010
{ title: "JSON vs Hash Storage", path: "/user_guide/hash_vs_json_05.html" },
1111
{ title: "Vectorizers", path: "/user_guide/vectorizers_04.html" },
1212
{ title: "Semantic Caching", path: "/user_guide/llmcache_03.html" },
13-
1413
]},
1514
{ header: "API", toc: [
16-
{ title: "Schema", path: "/api/indexschema.html"},
17-
{ title: "Index", path: "/api/searchindex.html" },
15+
{ title: "Schema", path: "/api/schema.html"},
16+
{ title: "Search Index", path: "/api/searchindex.html" },
1817
{ title: "Query", path: "/api/query.html" },
1918
{ title: "Filter", path: "/api/filter.html" },
2019
{ title: "Vectorizers", path: "/api/vectorizer.html" },

docs/api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ myst:
1111
:caption: RedisVL
1212
:maxdepth: 2
1313
14-
indexschema
14+
schema
1515
searchindex
1616
query
1717
filter
File renamed without changes.

docs/api/searchindex.rst

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
***********
2-
SearchIndex
3-
***********
1+
********************
2+
Search Index Classes
3+
********************
4+
5+
.. list-table::
6+
:widths: 25 75
7+
:header-rows: 1
8+
9+
* - Class
10+
- Description
11+
* - `SearchIndex <#searchindex_api>`_
12+
- Primary class to write, read, and search across data structures in Redis.
13+
* - `AsyncSearchIndex <#asyncsearchindex_api>`_
14+
- Async version of the SearchIndex to write, read, and search across data structures in Redis.
415

516
SearchIndex
617
===========
@@ -9,36 +20,19 @@ SearchIndex
920

1021
.. currentmodule:: redisvl.index
1122

12-
.. autosummary::
13-
14-
SearchIndex.from_yaml
15-
SearchIndex.from_dict
16-
SearchIndex.client
17-
SearchIndex.name
18-
SearchIndex.prefix
19-
SearchIndex.key_separator
20-
SearchIndex.storage_type
21-
SearchIndex.connect
22-
SearchIndex.disconnect
23-
SearchIndex.set_client
24-
SearchIndex.create
25-
SearchIndex.acreate
26-
SearchIndex.exists
27-
SearchIndex.aexists
28-
SearchIndex.load
29-
SearchIndex.aload
30-
SearchIndex.search
31-
SearchIndex.asearch
32-
SearchIndex.query
33-
SearchIndex.aquery
34-
SearchIndex.query_batch
35-
SearchIndex.aquery_batch
36-
SearchIndex.delete
37-
SearchIndex.adelete
38-
SearchIndex.info
39-
SearchIndex.ainfo
40-
4123
.. autoclass:: SearchIndex
4224
:show-inheritance:
4325
:inherited-members:
4426
:members:
27+
28+
AsyncSearchIndex
29+
================
30+
31+
.. _asyncsearchindex_api:
32+
33+
.. currentmodule:: redisvl.index
34+
35+
.. autoclass:: AsyncSearchIndex
36+
:show-inheritance:
37+
:inherited-members:
38+
:members:

0 commit comments

Comments
 (0)