-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from nulib/4585-hybrid-search
- Loading branch information
Showing
3 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ruff: noqa: E402 | ||
import sys | ||
sys.path.append('./src') | ||
|
||
from unittest import TestCase | ||
from handlers.opensearch_neural_search import OpenSearchNeuralSearch | ||
from langchain_core.documents import Document | ||
|
||
class MockClient(): | ||
def search(self, index, body, params): | ||
return { | ||
"hits": { | ||
"hits": [ | ||
{ | ||
"_source": { | ||
"id": "test" | ||
}, | ||
"_score": 0.12345 | ||
} | ||
] | ||
} | ||
} | ||
|
||
class TestOpenSearchNeuralSearch(TestCase): | ||
def test_similarity_search(self): | ||
docs = OpenSearchNeuralSearch(client=MockClient(), endpoint="test", index="test", model_id="test").similarity_search(query="test", subquery={"_source": {"excludes": ["embedding"]}}, size=10) | ||
self.assertEqual(docs, [Document(page_content='test', metadata={'id': 'test'})]) | ||
|
||
def test_similarity_search_with_score(self): | ||
docs = OpenSearchNeuralSearch(client=MockClient(), endpoint="test", index="test", model_id="test").similarity_search_with_score(query="test") | ||
self.assertEqual(docs, [(Document(page_content='test', metadata={'id': 'test'}), 0.12345)]) | ||
|
||
def test_add_texts(self): | ||
try: | ||
OpenSearchNeuralSearch(client=MockClient(), endpoint="test", index="test", model_id="test").add_texts(texts=["test"], metadatas=[{"id": "test"}]) | ||
except Exception as e: | ||
self.fail(f"from_texts raised an exception: {e}") | ||
|
||
def test_from_texts(self): | ||
try: | ||
OpenSearchNeuralSearch.from_texts(clas="test", texts=["test"], metadatas=[{"id": "test"}]) | ||
except Exception as e: | ||
self.fail(f"from_texts raised an exception: {e}") |