From de61ebd9e01b69d9509e1752dd33bdf65f0203f6 Mon Sep 17 00:00:00 2001 From: shibuiwilliam Date: Tue, 1 Aug 2023 09:07:09 +0900 Subject: [PATCH] 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. --- .../vectorstores/test_redis.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libs/langchain/tests/integration_tests/vectorstores/test_redis.py b/libs/langchain/tests/integration_tests/vectorstores/test_redis.py index 1fe7558682..aef3138e84 100644 --- a/libs/langchain/tests/integration_tests/vectorstores/test_redis.py +++ b/libs/langchain/tests/integration_tests/vectorstores/test_redis.py @@ -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)