Skip to content

Changes related to the next Meilisearch release (v1.11.0) #1018

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
merged 5 commits into from
Oct 28, 2024
Merged
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
16 changes: 13 additions & 3 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def get_settings(self) -> Dict[str, Any]:

return settings

def update_settings(self, body: Mapping[str, Any]) -> TaskInfo:
def update_settings(self, body: MutableMapping[str, Any]) -> TaskInfo:
"""Update settings of the index.

https://www.meilisearch.com/docs/reference/api/settings#update-settings
Expand All @@ -978,6 +978,11 @@ def update_settings(self, body: Mapping[str, Any]) -> TaskInfo:
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
if body.get("embedders"):
for _, v in body["embedders"].items():
if "documentTemplateMaxBytes" in v and v["documentTemplateMaxBytes"] is None:
del v["documentTemplateMaxBytes"]

task = self.http.patch(
f"{self.config.paths.index}/{self.uid}/{self.config.paths.setting}", body
)
Expand Down Expand Up @@ -1867,7 +1872,6 @@ def get_embedders(self) -> Embedders | None:

embedders: dict[str, OpenAiEmbedder | HuggingFaceEmbedder | UserProvidedEmbedder] = {}
for k, v in response.items():
print(v.get("source"))
if v.get("source") == "openAi":
embedders[k] = OpenAiEmbedder(**v)
elif v.get("source") == "huggingFace":
Expand All @@ -1877,7 +1881,7 @@ def get_embedders(self) -> Embedders | None:

return Embedders(embedders=embedders)

def update_embedders(self, body: Union[Mapping[str, Any], None]) -> TaskInfo:
def update_embedders(self, body: Union[MutableMapping[str, Any], None]) -> TaskInfo:
"""Update embedders of the index.

Parameters
Expand All @@ -1896,6 +1900,12 @@ def update_embedders(self, body: Union[Mapping[str, Any], None]) -> TaskInfo:
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""

if body:
for _, v in body.items():
if "documentTemplateMaxBytes" in v and v["documentTemplateMaxBytes"] is None:
del v["documentTemplateMaxBytes"]

task = self.http.patch(self.__settings_url_for(self.config.paths.embedders), body)

return TaskInfo(**task)
Expand Down
4 changes: 3 additions & 1 deletion meilisearch/models/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ class ProximityPrecision(str, Enum):

class OpenAiEmbedder(CamelBase):
source: str = "openAi"
model: Optional[str] = None # Defaults to text-embedding-ada-002
model: Optional[str] = None # Defaults to text-embedding-3-small
dimensions: Optional[int] = None # Uses the model default
api_key: Optional[str] = None # Can be provided through a CLI option or environment variable
document_template: Optional[str] = None
document_template_max_bytes: Optional[int] = None # Default to 400


class HuggingFaceEmbedder(CamelBase):
source: str = "huggingFace"
model: Optional[str] = None # Defaults to BAAI/bge-base-en-v1.5
revision: Optional[str] = None
document_template: Optional[str] = None
document_template_max_bytes: Optional[int] = None # Default to 400


class UserProvidedEmbedder(CamelBase):
Expand Down
3 changes: 2 additions & 1 deletion tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ def test_show_ranking_score(index_with_documents):
@pytest.mark.usefixtures("enable_vector_search")
def test_vector_search(index_with_documents_and_vectors):
response = index_with_documents_and_vectors().search(
"", opt_params={"vector": [0.1, 0.2], "hybrid": {"semanticRatio": 1.0}}
"",
opt_params={"vector": [0.1, 0.2], "hybrid": {"semanticRatio": 1.0, "embedder": "default"}},
)
assert len(response["hits"]) > 0

Expand Down