Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/marqo/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def refresh(self):
def search(self, q: str, searchable_attributes: Optional[List[str]] = None,
limit: int = 10, offset: int = 0, search_method: Union[SearchMethods.TENSOR, str] = SearchMethods.TENSOR,
highlights=None, device: Optional[str] = None, filter_string: str = None,
show_highlights=True, reranker=None,
show_highlights=True, reranker: str = None, reranker_properties: dict = None,
attributes_to_retrieve: Optional[List[str]] = None
) -> Dict[str, Any]:
"""Search the index.
Expand All @@ -129,7 +129,10 @@ def search(self, q: str, searchable_attributes: Optional[List[str]] = None,
offset: The number of search results to skip (for pagination)
search_method: Indicates TENSOR or LEXICAL (keyword) search
show_highlights: True if highlights are to be returned
reranker:
reranker: the name of the reranker
reranker_properties: a dict of reranker-specific settings. Please see
our documentation for more information:
https://docs.marqo.ai/latest/Models-Reference/reranking/
device: the device used to index the data. Examples include "cpu",
"cuda" and "cuda:2". Overrides the Client's default device.
filter_string: a filter string, used to prefilter documents during the
Expand Down Expand Up @@ -161,6 +164,7 @@ def search(self, q: str, searchable_attributes: Optional[List[str]] = None,
"searchMethod": search_method,
"showHighlights": show_highlights,
"reRanker": reranker,
"reRankerProperties": reranker_properties
}
if attributes_to_retrieve is not None:
body["attributesToRetrieve"] = attributes_to_retrieve
Expand Down
24 changes: 23 additions & 1 deletion tests/v0_tests/test_tensor_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from marqo import enums
from unittest import mock
from marqo.client import Client
from marqo.errors import MarqoApiError
from marqo.errors import MarqoApiError, MarqoWebError
import unittest
import pprint
import requests
Expand Down Expand Up @@ -248,3 +248,25 @@ def test_pagination_single_field(self):

# TODO: re-add this assert when KNN incosistency bug is fixed
# assert full_search_results["hits"] == paginated_search_results["hits"]

def test_reranker_properties(self):
self.client.create_index(index_name=self.index_name_1)
d1 = {
"doc title": "Very heavy, dense metallic lead.",
"abc-123": "some text blah",
"an_int": 2,
"_id": "my-cool-doc"
}
self.client.index(self.index_name_1).add_documents([d1], auto_refresh=True)
try:
res = self.client.index(self.index_name_1).search(
q="example of metals",
reranker="openai/gpt3-summarise",
searchable_attributes=["doc title"],
reranker_properties={"api_key": "f"}
)
except MarqoWebError as e:
options = [["api", "key"], ["open", "ai"]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a comment here like "# test the format of the error message" for clarification.

assert any([all([must_have in str(e).lower() for must_have in option]) for option in options])