add tests to redis vectorstore (#8116)

# What
- Add function to get similarity with score with threshold in Redis
vector store.
- Add tests to Redis vector store.
This commit is contained in:
shibuiwilliam 2023-08-01 09:07:09 +09:00 committed by GitHub
parent c19a0b9c10
commit de61ebd9e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -124,3 +124,38 @@ def test_ip(texts: List[str]) -> None:
_, score = output[1]
assert score == IP_SCORE
assert drop(docsearch.index_name)
def test_similarity_search_limit_score(texts: List[str]) -> None:
"""Test similarity search limit score."""
docsearch = Redis.from_texts(
texts, FakeEmbeddings(), redis_url=TEST_REDIS_URL, distance_metric="COSINE"
)
output = docsearch.similarity_search_limit_score("far", k=2, score_threshold=0.1)
assert len(output) == 1
_, score = output[0]
assert score == COSINE_SCORE
assert drop(docsearch.index_name)
def test_similarity_search_with_score_with_limit_score(texts: List[str]) -> None:
"""Test similarity search with score with limit score."""
docsearch = Redis.from_texts(
texts, FakeEmbeddings(), redis_url=TEST_REDIS_URL, distance_metric="COSINE"
)
output = docsearch.similarity_search_with_relevance_scores(
"far", k=2, score_threshold=0.1
)
assert len(output) == 1
_, score = output[0]
assert score == COSINE_SCORE
assert drop(docsearch.index_name)
def test_delete(texts: List[str]) -> None:
"""Test deleting a new document"""
docsearch = Redis.from_texts(texts, FakeEmbeddings(), redis_url=TEST_REDIS_URL)
ids = docsearch.add_texts(["foo"])
got = docsearch.delete(ids=ids)
assert got
assert drop(docsearch.index_name)