diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index c0347a0b..31e055b3 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -648,3 +648,14 @@ webhooks_patch_1: |- Webhook updated_webhook = this.client.updateWebhook(webhook.getUuid(), webhookReq2); webhooks_delete_1: |- this.client.deleteWebhook("WEBHOOK_UUID"); +search_parameter_reference_media_1: |- + Hybrid hybrid = Hybrid.builder().embedder("EMBEDDER_NAME").build(); + SearchRequest searchRequest = SearchRequest.builder(). + hybrid(hybrid).media(JsonParser.parseString(""" + { + "FIELD_A": "VALUE_A", + "FIELD_B": { + "FIELD_C": "VALUE_B", + "FIELD_D": "VALUE_C" + }}""")).build(); + client.search("movies", searchRequest); diff --git a/gradlew.bat b/gradlew.bat index e509b2dd..c4bdd3ab 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,93 +1,93 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/com/meilisearch/sdk/SearchRequest.java b/src/main/java/com/meilisearch/sdk/SearchRequest.java index 43e043cc..a0d6ad82 100644 --- a/src/main/java/com/meilisearch/sdk/SearchRequest.java +++ b/src/main/java/com/meilisearch/sdk/SearchRequest.java @@ -1,5 +1,6 @@ package com.meilisearch.sdk; +import com.google.gson.JsonElement; import com.meilisearch.sdk.model.Hybrid; import com.meilisearch.sdk.model.MatchingStrategy; import lombok.AccessLevel; @@ -46,6 +47,7 @@ public class SearchRequest { protected Hybrid hybrid; protected Double[] vector; protected Boolean retrieveVectors; + protected JsonElement media; /** * Constructor for SearchRequest for building search queries with the default values: offset: 0, * limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, @@ -110,7 +112,8 @@ public String toString() { .putOpt("locales", this.locales) .putOpt("distinct", this.distinct) .putOpt("vector", this.vector) - .putOpt("retrieveVectors", this.retrieveVectors); + .putOpt("retrieveVectors", this.retrieveVectors) + .putOpt("media", this.media); if (this.hybrid != null) { jsonObject.put("hybrid", this.hybrid.toJSONObject()); diff --git a/src/main/java/com/meilisearch/sdk/model/Embedder.java b/src/main/java/com/meilisearch/sdk/model/Embedder.java index 7179428d..715b8901 100644 --- a/src/main/java/com/meilisearch/sdk/model/Embedder.java +++ b/src/main/java/com/meilisearch/sdk/model/Embedder.java @@ -1,6 +1,7 @@ package com.meilisearch.sdk.model; import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.HashMap; import java.util.Map; import lombok.*; import lombok.experimental.Accessors; @@ -69,5 +70,15 @@ public class Embedder { /** Query for the embedder. Optional. */ protected String query; + /** + * Template fragments that will be reassembled and sent to the remote embedder at indexing time. + */ + protected HashMap indexingFragments; + + /** + * Template fragments that will be reassembled and sent to the remote embedder at search time. + */ + protected HashMap searchFragments; + public Embedder() {} } diff --git a/src/main/java/com/meilisearch/sdk/model/EmbedderFragment.java b/src/main/java/com/meilisearch/sdk/model/EmbedderFragment.java new file mode 100644 index 00000000..1b016d57 --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/EmbedderFragment.java @@ -0,0 +1,14 @@ +package com.meilisearch.sdk.model; + +import com.google.gson.JsonElement; +import lombok.*; + +@Builder +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PACKAGE) +@EqualsAndHashCode +public class EmbedderFragment { + protected JsonElement value; +} diff --git a/src/test/java/com/meilisearch/integration/SettingsTest.java b/src/test/java/com/meilisearch/integration/SettingsTest.java index bbb8c84e..f5d5104a 100644 --- a/src/test/java/com/meilisearch/integration/SettingsTest.java +++ b/src/test/java/com/meilisearch/integration/SettingsTest.java @@ -14,23 +14,12 @@ import static org.hamcrest.Matchers.notNullValue; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.google.gson.JsonParser; import com.meilisearch.integration.classes.AbstractIT; import com.meilisearch.integration.classes.TestData; import com.meilisearch.sdk.Index; import com.meilisearch.sdk.exceptions.GranularFilterableAttributesException; -import com.meilisearch.sdk.model.Embedder; -import com.meilisearch.sdk.model.EmbedderDistribution; -import com.meilisearch.sdk.model.EmbedderSource; -import com.meilisearch.sdk.model.FacetSortValue; -import com.meilisearch.sdk.model.Faceting; -import com.meilisearch.sdk.model.FilterableAttributesConfig; -import com.meilisearch.sdk.model.FilterableAttributesFeatures; -import com.meilisearch.sdk.model.FilterableAttributesFilter; -import com.meilisearch.sdk.model.LocalizedAttribute; -import com.meilisearch.sdk.model.Pagination; -import com.meilisearch.sdk.model.Settings; -import com.meilisearch.sdk.model.TaskInfo; -import com.meilisearch.sdk.model.TypoTolerance; +import com.meilisearch.sdk.model.*; import com.meilisearch.sdk.utils.Movie; import java.util.ArrayList; import java.util.Arrays; @@ -1586,11 +1575,45 @@ public void testGetEmbeddersSettings() throws Exception { } public Embedder createUserProvidedEmbedder() { + HashMap indexingFragment = new HashMap<>(); + indexingFragment.put( + "text", + EmbedderFragment.builder() + .value( + JsonParser.parseString( + """ + { + "content": [ + { + "type": "text", + "text": "A movie titled {{doc.title}} whose description starts with {{doc.overview|truncateWords:20}}." + } + ] + }""")) + .build()); + HashMap searchFragment = new HashMap<>(); + searchFragment.put( + "text", + EmbedderFragment.builder() + .value( + JsonParser.parseString( + """ + { + "content": [ + { + "type": "image_url", + "image_url": "https://static.vecteezy.com/system/resources/thumbnails/057/068/323/small/single-fresh-red-strawberry-on-table-green-background-food-fruit-sweet-macro-juicy-plant-image-photo.jpg" + } + ] + }""")) + .build()); return Embedder.builder() .source(EmbedderSource.USER_PROVIDED) .dimensions(1) .distribution(EmbedderDistribution.builder().mean(0.7).sigma(0.3).build()) .binaryQuantized(false) + .indexingFragments(indexingFragment) + .searchFragments(searchFragment) .build(); } @@ -1618,6 +1641,11 @@ public void testUpdateEmbeddersSettings() throws Exception { is(equalTo(embedder.getDistribution().getSigma()))); assertThat( retrievedEmbedder.getBinaryQuantized(), is(equalTo(embedder.getBinaryQuantized()))); + assertThat( + retrievedEmbedder.getIndexingFragments(), + is(equalTo(embedder.getIndexingFragments()))); + assertThat( + retrievedEmbedder.getSearchFragments(), is(equalTo(embedder.getSearchFragments()))); } @Test