Skip to content

Commit

Permalink
Merge #1018
Browse files Browse the repository at this point in the history
1018: Changes related to the next Meilisearch release (v1.11.0) r=brunoocasali a=meili-bot

Related to this issue: meilisearch/integration-guides#303

This PR:
- gathers the changes related to the next Meilisearch release (v1.11.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v1.11.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.11.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._


Co-authored-by: meili-bot <[email protected]>
Co-authored-by: Louis Dureuil <[email protected]>
Co-authored-by: Paul Sanders <[email protected]>
Co-authored-by: Clémentine <[email protected]>
  • Loading branch information
5 people authored Oct 28, 2024
2 parents 7edda62 + 9f811c8 commit 4036306
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
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

0 comments on commit 4036306

Please sign in to comment.