|
| 1 | +// Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package com.volcengine.vikingdb.runtime.vector.rerank; |
| 5 | + |
| 6 | +import com.volcengine.vikingdb.runtime.core.ApiClientTest; |
| 7 | +import com.volcengine.vikingdb.runtime.core.auth.AuthWithAkSk; |
| 8 | +import com.volcengine.vikingdb.runtime.enums.Scheme; |
| 9 | +import com.volcengine.vikingdb.runtime.exception.ApiClientException; |
| 10 | +import com.volcengine.vikingdb.runtime.exception.VectorApiException; |
| 11 | +import com.volcengine.vikingdb.runtime.vector.TestVar; |
| 12 | +import com.volcengine.vikingdb.runtime.vector.model.request.EmbeddingDataItem; |
| 13 | +import com.volcengine.vikingdb.runtime.vector.model.request.EmbeddingRequest; |
| 14 | +import com.volcengine.vikingdb.runtime.vector.model.request.FullModalData; |
| 15 | +import com.volcengine.vikingdb.runtime.vector.model.request.RerankRequest; |
| 16 | +import com.volcengine.vikingdb.runtime.vector.model.response.DataApiResponse; |
| 17 | +import com.volcengine.vikingdb.runtime.vector.model.response.EmbeddingResult; |
| 18 | +import com.volcengine.vikingdb.runtime.vector.model.response.RerankResult; |
| 19 | +import com.volcengine.vikingdb.runtime.vector.service.VectorService; |
| 20 | +import org.junit.jupiter.api.BeforeAll; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import java.io.IOException; |
| 24 | +import java.io.InputStream; |
| 25 | +import java.util.Arrays; |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.Properties; |
| 28 | + |
| 29 | +public class RerankTest { |
| 30 | + private static VectorService service; |
| 31 | + |
| 32 | + @BeforeAll |
| 33 | + public static void setUp() throws Exception { |
| 34 | + Properties properties = new Properties(); |
| 35 | + try (InputStream input = ApiClientTest.class.getClassLoader().getResourceAsStream("test-config.properties")) { |
| 36 | + if (input == null) { |
| 37 | + throw new IOException("Unable to find test-config.properties"); |
| 38 | + } |
| 39 | + properties.load(input); |
| 40 | + } |
| 41 | + |
| 42 | + service = new VectorService( |
| 43 | + Scheme.fromString(properties.getProperty("scheme")), |
| 44 | + properties.getProperty("host"), |
| 45 | + new AuthWithAkSk(properties.getProperty("ak"), properties.getProperty("sk")) |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testRerankForText() throws Exception { |
| 51 | + RerankRequest request = RerankRequest.builder() |
| 52 | + .modelName("doubao-seed-rerank") |
| 53 | + .modelVersion("251028") |
| 54 | + .query(Collections.singletonList(FullModalData.builder().text("apple").build())) |
| 55 | + .instruction("Whether the Document answers the Query or matches the content retrieval intent") |
| 56 | + .returnOriginData(true) |
| 57 | + .data(Arrays.asList( |
| 58 | + Collections.singletonList(FullModalData.builder().text("This is an apple.").build()), |
| 59 | + Collections.singletonList(FullModalData.builder().text("My name is John.").build()), |
| 60 | + Collections.singletonList(FullModalData.builder().text("How many fruits are there?").build()) |
| 61 | + )) |
| 62 | + .build(); |
| 63 | + DataApiResponse<RerankResult> response = service.rerank(request); |
| 64 | + System.out.println(response); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void testEmbeddingForMultiModal() throws Exception { |
| 69 | + RerankRequest request = RerankRequest.builder() |
| 70 | + .modelName("doubao-seed-rerank") |
| 71 | + .modelVersion("251028") |
| 72 | + .query(Collections.singletonList(FullModalData.builder().text("iceberg").build())) |
| 73 | + .instruction("Whether the Document answers the Query or matches the content retrieval intent") |
| 74 | + .returnOriginData(true) |
| 75 | + .data(Arrays.asList( |
| 76 | + Collections.singletonList(FullModalData.builder().text("Here is a mountain and it is very beautiful.").build()), |
| 77 | + Collections.singletonList(FullModalData.builder().image("https://ark-project.tos-cn-beijing.volces.com/images/view.jpeg").build()), |
| 78 | + Collections.singletonList(FullModalData.builder().video("https://ark-project.tos-cn-beijing.volces.com/doc_video/ark_vlm_video_input.mp4").build()) |
| 79 | + )).build(); |
| 80 | + DataApiResponse<RerankResult> response = service.rerank(request); |
| 81 | + System.out.println(response); |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments