Skip to content

Commit 76df66f

Browse files
Sam Parteechayimtylerhutcherson
authored
Text Matrix: Python, Redis Stack, and hiredis (#73)
Building off of Chayims Pr in #62, This PR extends the test suite capability to more variations supported by Redis. --------- Co-authored-by: Chayim I. Kirshen <c@kirshen.com> Co-authored-by: Chayim <chayim@users.noreply.github.com> Co-authored-by: Tyler Hutcherson <tyler.hutcherson@redis.com>
1 parent 474c4c8 commit 76df66f

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

.github/workflows/run_tests.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,82 @@ name: Test Suite
22

33
on:
44
pull_request:
5+
56
push:
67
branches:
78
- main
89

910
jobs:
1011
test:
11-
name: Test on ${{ matrix.python-version }} - ${{ matrix.os }}
12+
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}]
1213
runs-on: ubuntu-latest
1314

1415
strategy:
16+
fail-fast: false
1517
matrix:
1618
python-version: [3.8, 3.9, '3.10', 3.11]
19+
connection: ['hiredis', 'plain']
20+
redis-stack-version: ['6.2.6-v9', 'latest']
1721

1822
services:
1923
redis:
20-
image: redis/redis-stack-server:latest
24+
image: redis/redis-stack-server:${{matrix.redis-stack-version}}
2125
ports:
2226
- 6379:6379
2327

2428
steps:
2529
- uses: actions/checkout@v2
2630
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v2
31+
uses: actions/setup-python@v4
2832
with:
2933
python-version: ${{ matrix.python-version }}
34+
cache: 'pip'
35+
3036
- name: Install dependencies
3137
run: |
3238
python -m pip install --upgrade pip
3339
pip install .[dev,all]
40+
41+
- name: Install hiredis if needed
42+
if: matrix.connection == 'hiredis'
43+
run: |
44+
pip install hiredis
45+
3446
- name: Start Redis
3547
run: |
3648
REDIS_URL=redis://localhost:6379
3749
echo REDIS_URL=$REDIS_URL >> $GITHUB_ENV
50+
3851
- name: Authenticate to Google Cloud
3952
uses: google-github-actions/auth@v1
4053
with:
4154
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
55+
4256
- name: Run tests
57+
if: matrix.connection == 'plain' && matrix.redis-stack-version == 'latest'
4358
env:
4459
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
4560
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
4661
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
4762
run: |
4863
make test-cov
64+
65+
- name: Run tests
66+
if: matrix.connection != 'plain' || matrix.redis-stack-version != 'latest'
67+
run: |
68+
SKIP_VECTORIZERS=True make test-cov
69+
4970
- name: Run notebooks
71+
if: matrix.connection == 'plain' && matrix.redis-stack-version == 'latest'
5072
env:
5173
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
5274
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
5375
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
5476
run: |
5577
cd docs/ && treon -v --exclude="./examples/openai_qna.ipynb"
78+
5679
- name: Publish coverage results
5780
uses: codecov/codecov-action@v2
5881
with:
5982
token: ${{ secrets.CODECOV_TOKEN }}
60-
fail_ci_if_error: true
83+
fail_ci_if_error: true

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Install `redisvl` using `pip`:
6161
pip install redisvl
6262
```
6363

64+
This library supports the use of hiredis, so you can also install by running:
65+
66+
```bash
67+
pip install redisvl[hiredis]
68+
```
69+
6470
Then make sure to have [Redis](https://redis.io) accessible with Search & Query features enabled on [Redis Cloud](https://redis.com/try-free) or locally in docker with [Redis Stack](https://redis.io/docs/getting-started/install-stack/docker/):
6571

6672
```bash
@@ -195,5 +201,3 @@ cache.check("What is the capital of France?")
195201
cache.check("What really is the capital of France?")
196202
["Paris"]
197203
```
198-
199-

tests/integration/test_vectorizers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@
99
)
1010

1111

12+
@pytest.fixture
13+
def skip_vectorizer() -> bool:
14+
# os.getenv returns a string
15+
return os.getenv("SKIP_VECTORIZERS", 'False').lower() == 'true'
16+
17+
skip_vectorizer_test = lambda: pytest.config.getfixturevalue("skip_vectorizer")
18+
19+
1220
@pytest.fixture(params=[HFTextVectorizer, OpenAITextVectorizer, VertexAITextVectorizer])
1321
def vectorizer(request, openai_key, gcp_location, gcp_project_id):
22+
# if skip_vectorizer:
23+
# pytest.skip("Skipping vectorizer tests")
1424
# Here we use actual models for integration test
1525
if request.param == HFTextVectorizer:
1626
return request.param(model="sentence-transformers/all-mpnet-base-v2")
@@ -29,6 +39,7 @@ def vectorizer(request, openai_key, gcp_location, gcp_project_id):
2939
)
3040

3141

42+
@pytest.mark.skipif(skip_vectorizer_test, reason="Skipping vectorizer tests")
3243
def test_vectorizer_embed(vectorizer):
3344
text = "This is a test sentence."
3445
embedding = vectorizer.embed(text)
@@ -37,6 +48,7 @@ def test_vectorizer_embed(vectorizer):
3748
assert len(embedding) == vectorizer.dims
3849

3950

51+
@pytest.mark.skipif(skip_vectorizer_test, reason="Skipping vectorizer tests")
4052
def test_vectorizer_embed_many(vectorizer):
4153
texts = ["This is the first test sentence.", "This is the second test sentence."]
4254
embeddings = vectorizer.embed_many(texts)
@@ -48,6 +60,7 @@ def test_vectorizer_embed_many(vectorizer):
4860
)
4961

5062

63+
@pytest.mark.skipif(skip_vectorizer_test, reason="Skipping vectorizer tests")
5164
def test_vectorizer_bad_input(vectorizer):
5265
with pytest.raises(TypeError):
5366
vectorizer.embed(1)
@@ -68,6 +81,7 @@ def avectorizer(request, openai_key):
6881
)
6982

7083

84+
@pytest.mark.skipif(skip_vectorizer_test, reason="Skipping vectorizer tests")
7185
@pytest.mark.asyncio
7286
async def test_vectorizer_aembed(avectorizer):
7387
text = "This is a test sentence."
@@ -77,6 +91,7 @@ async def test_vectorizer_aembed(avectorizer):
7791
assert len(embedding) == avectorizer.dims
7892

7993

94+
@pytest.mark.skipif(skip_vectorizer_test, reason="Skipping vectorizer tests")
8095
@pytest.mark.asyncio
8196
async def test_vectorizer_aembed_many(avectorizer):
8297
texts = ["This is the first test sentence.", "This is the second test sentence."]
@@ -89,6 +104,7 @@ async def test_vectorizer_aembed_many(avectorizer):
89104
)
90105

91106

107+
@pytest.mark.skipif(skip_vectorizer_test, reason="Skipping vectorizer tests")
92108
@pytest.mark.asyncio
93109
async def test_avectorizer_bad_input(avectorizer):
94110
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)