-
Notifications
You must be signed in to change notification settings - Fork 5
Add sortby and relevance cutoff parameters and add a unit tests workflow #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wanliAlex
merged 8 commits into
mainline
from
li/add-sortby-and-relevance-cutoff-parameters
Jul 10, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7d081b
Added sort by
wanliAlex 8c6c140
Add sort-by parameters
wanliAlex 099d200
Update branch with mainline
wanliAlex 171cf63
Add a unit tests workflow
wanliAlex 78b7d60
Add a unit tests workflow
wanliAlex 67cb2db
Add a unit tests workflow
wanliAlex 867922d
Add a unit tests workflow
wanliAlex ea76ec7
Add a unit tests workflow
wanliAlex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,40 @@ | ||
|
|
||
|
|
||
| name: Py-marqo Unit Tests | ||
| run-name: Py-marqo unit tests | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: | ||
| - mainline | ||
| - releases/* | ||
| push: | ||
| branches: | ||
| - mainline | ||
| - releases/* | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Run Pytest | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: 3.9 | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install -r requirements-dev.txt | ||
|
|
||
| - name: Run UnitTests | ||
| run: | | ||
| export PYTHONPATH="${PYTHONPATH}:$(pwd)/src" | ||
| pytest unit_tests |
This file contains hidden or 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
Empty file.
This file contains hidden or 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,5 @@ | ||
| from unittest import TestCase | ||
|
|
||
|
|
||
| class MarqoUnitTests(TestCase): | ||
| pass |
This file contains hidden or 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,132 @@ | ||
| from unittest.mock import patch, MagicMock | ||
|
|
||
| from marqo.config import Config | ||
| from marqo.default_instance_mappings import DefaultInstanceMappings | ||
| from marqo.index import Index | ||
| from unit_tests.marqo_unit_tests import MarqoUnitTests | ||
|
|
||
|
|
||
| class TestIndexSearchEndpointSortBy(MarqoUnitTests): | ||
| """ | ||
| Test class for the Index search endpoint sort_by parameter. | ||
| """ | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| """ | ||
| Set up the class by creating a test index. | ||
| """ | ||
| config = Config( | ||
| instance_mappings=DefaultInstanceMappings(url="http://unit-tests-url:8882"), | ||
| ) | ||
| cls.index = Index(config=config, index_name="test_index") | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_search_by_parameters_one_fields(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
| sort_by = {"fields":[{"fieldName": "price", "order": "asc"}]} | ||
| self.index.search(q= "test", sort_by= sort_by) | ||
|
|
||
| self.assertEqual(1, mock_send_request.call_count) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertEqual({"fields": [{"fieldName": "price", "order": "asc"}]}, body["sortBy"]) | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_search_by_parameters_three_fields(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
|
|
||
| sort_by = { | ||
| "fields": [ | ||
| {"fieldName": "price", "order": "asc"}, | ||
| {"fieldName": "rating", "order": "desc"}, | ||
| {"fieldName": "date", "order": "asc"} | ||
| ] | ||
| } | ||
|
|
||
| self.index.search(q= "test", sort_by=sort_by) | ||
|
|
||
| self.assertEqual(1, mock_send_request.call_count) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertEqual(sort_by, body["sortBy"]) | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_search_by_parameters_none(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
|
|
||
| sort_by = None | ||
|
|
||
| self.index.search(q= "test", sort_by=sort_by) | ||
|
|
||
| self.assertEqual(1, mock_send_request.call_count) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertNotIn("sortBy", body) | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_search_by_parameters_not_exists(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
|
|
||
| self.index.search(q= "test") | ||
|
|
||
| self.assertEqual(1, mock_send_request.call_count) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertNotIn("sortBy", body) | ||
|
|
||
|
|
||
| class TestIndexSearchEndpointRelevanceCutoff(MarqoUnitTests): | ||
| """ | ||
| Test class for the Index search endpoint relevance_cutoff parameter. | ||
| """ | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| """ | ||
| Set up the class by creating a test index. | ||
| """ | ||
| config = Config( | ||
| instance_mappings=DefaultInstanceMappings(url="http://unit-tests-url:8882"), | ||
| ) | ||
| cls.index = Index(config=config, index_name="test_index") | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_relevance_cutoff_parameter(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
|
|
||
| relevance_cutoff = { | ||
| "method": "mean_std_dev", | ||
| "parameters": { | ||
| "stdDevFactor": 1.0, | ||
| }, | ||
| "probeDepth": 1000 | ||
| } | ||
|
|
||
| self.index.search(q= "test", relevance_cutoff=relevance_cutoff) | ||
|
|
||
| self.assertEqual(1, mock_send_request.call_count) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertEqual(relevance_cutoff, body["relevanceCutoff"]) | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_relevance_cutoff_parameter_none(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
|
|
||
| relevance_cutoff = None | ||
|
|
||
| self.index.search(q= "test", relevance_cutoff=relevance_cutoff) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertNotIn("relevanceCutoff", body) | ||
|
|
||
| @patch('marqo._httprequests.HttpRequests.send_request') | ||
| def test_relevance_cutoff_parameter_not_exists(self, mock_send_request): | ||
| mock_response = MagicMock() | ||
| mock_send_request.return_value = mock_response | ||
|
|
||
| self.index.search(q= "test") | ||
|
|
||
| self.assertEqual(1, mock_send_request.call_count) | ||
| body = mock_send_request.call_args[0][2] | ||
| self.assertNotIn("relevanceCutoff", body) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.