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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

public record NvidiaReranker(
@SerializedName("model") String model,
@SerializedName("baseUrl") String baseUrl) implements Reranker {
/**
* The module reads this as {@code baseURL}: {@code reranker-nvidia} looks the
* key up verbatim, so a {@code baseUrl} spelling is stored in the schema and
* then ignored, and reranking silently goes to the default endpoint. The
* {@code alternate} keeps configs written by older versions of this client
* readable; Gson only ever writes {@code value}.
*/
@SerializedName(value = "baseURL", alternate = { "baseUrl" }) String baseUrl) implements Reranker {

@Override
public Kind _kind() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.weaviate.client6.v1.api.collections.rerankers;

import org.assertj.core.api.Assertions;
import org.junit.Test;

import io.weaviate.client6.v1.api.collections.Reranker;
import io.weaviate.client6.v1.internal.json.JSON;

public class NvidiaRerankerTest {

/**
* Collections created by earlier versions of this client have the base URL
* stored under the "baseUrl" key the module never read. Those configs still
* have to deserialize, otherwise upgrading turns a wrong value into a missing
* one.
*/
@Test
public void test_readsLegacyBaseUrlKey() {
var legacy = """
{"reranker-nvidia": {"baseUrl": "https://legacy.example.com"}}
""";

var reranker = JSON.deserialize(legacy, Reranker.class);

Assertions.assertThat(reranker)
.asInstanceOf(org.assertj.core.api.InstanceOfAssertFactories.type(NvidiaReranker.class))
.returns("https://legacy.example.com", NvidiaReranker::baseUrl);
}

/** ...but writing always uses the key the module actually reads. */
@Test
public void test_writesCanonicalBaseUrlKey() {
var json = JSON.serialize(Reranker.nvidia(r -> r.baseUrl("https://example.com")));

Assertions.assertThat(json).contains("\"baseURL\"").doesNotContain("\"baseUrl\"");
}
}
17 changes: 17 additions & 0 deletions src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,23 @@ public static Object[][] testCases() {
}
""",
},
// reranker-nvidia reads "baseURL" like every other module. It had no test
// row, which is how it kept sending "baseUrl" -- stored in the schema and
// then ignored, so reranking silently used the default endpoint.
{
Reranker.class,
Reranker.nvidia(rerank -> rerank
.baseUrl("example.com")
.model("nvidia/rerank-qa-mistral-4b")),
"""
{
"reranker-nvidia": {
"baseURL": "example.com",
"model": "nvidia/rerank-qa-mistral-4b"
}
}
""",
},

// BatchReference.CustomTypeAdapterFactory
{
Expand Down
Loading