-
Notifications
You must be signed in to change notification settings - Fork 13
Add rerank #159
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
Add rerank #159
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/integration/java/io/pinecone/integration/inference/RerankTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package io.pinecone.integration.inference; | ||
|
|
||
| import io.pinecone.clients.Inference; | ||
| import io.pinecone.clients.Pinecone; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openapitools.inference.client.ApiException; | ||
| import org.openapitools.inference.client.model.RerankResult; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| public class RerankTest { | ||
| private static final Pinecone pinecone = new Pinecone | ||
| .Builder(System.getenv("PINECONE_API_KEY")) | ||
| .withSourceTag("pinecone_test") | ||
| .build(); | ||
| private static final Inference inference = pinecone.getInferenceClient(); | ||
|
|
||
| @Test | ||
| public void testRerank() throws ApiException { | ||
| String model = "bge-reranker-v2-m3"; | ||
| String query = "The tech company Apple is known for its innovative products like the iPhone."; | ||
| List<Map<String, String>> documents = new ArrayList<>(); | ||
|
|
||
| Map<String, String> doc1 = new HashMap<>(); | ||
| doc1.put("id", "vec1"); | ||
| doc1.put("my_field", "Apple is a popular fruit known for its sweetness and crisp texture."); | ||
| documents.add(doc1); | ||
|
|
||
| Map<String, String> doc2 = new HashMap<>(); | ||
| doc2.put("id", "vec2"); | ||
| doc2.put("my_field", "Many people enjoy eating apples as a healthy snack."); | ||
| documents.add(doc2); | ||
|
|
||
| Map<String, String> doc3 = new HashMap<>(); | ||
| doc3.put("id", "vec3"); | ||
| doc3.put("my_field", "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."); | ||
| documents.add(doc3); | ||
|
|
||
| Map<String, String> doc4 = new HashMap<>(); | ||
| doc4.put("id", "vec4"); | ||
| doc4.put("my_field", "An apple a day keeps the doctor away, as the saying goes."); | ||
| documents.add(doc4); | ||
|
|
||
| List<String> rankFields = Arrays.asList("my_field"); | ||
| int topN = 2; | ||
| boolean returnDocuments = true; | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| parameters.put("truncate", "END"); | ||
|
|
||
| RerankResult result = inference.rerank(model, query, documents, rankFields, topN, returnDocuments, parameters); | ||
|
|
||
| assertNotNull(result); | ||
| Assertions.assertEquals(result.getData().size(), topN); | ||
| Assertions.assertEquals(result.getData().get(0).getIndex(), 2); | ||
| Assertions.assertEquals(result.getData().get(0).getDocument().get("my_field"), doc3.get("my_field")); | ||
| Assertions.assertEquals(result.getData().size(), 2); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRerankWithRequiredParameters() throws ApiException { | ||
| String model = "bge-reranker-v2-m3"; | ||
| String query = "The tech company Apple is known for its innovative products like the iPhone."; | ||
| List<Map<String, String>> documents = new ArrayList<>(); | ||
|
|
||
| Map<String, String> doc1 = new HashMap<>(); | ||
| doc1.put("id", "vec1"); | ||
| doc1.put("text", "Apple is a popular fruit known for its sweetness and crisp texture."); | ||
| documents.add(doc1); | ||
|
|
||
| Map<String, String> doc2 = new HashMap<>(); | ||
| doc2.put("id", "vec2"); | ||
| doc2.put("text", "Many people enjoy eating apples as a healthy snack."); | ||
| documents.add(doc2); | ||
|
|
||
| Map<String, String> doc3 = new HashMap<>(); | ||
| doc3.put("id", "vec3"); | ||
| doc3.put("text", "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."); | ||
| documents.add(doc3); | ||
|
|
||
| Map<String, String> doc4 = new HashMap<>(); | ||
| doc4.put("id", "vec4"); | ||
| doc4.put("text", "An apple a day keeps the doctor away, as the saying goes."); | ||
| documents.add(doc4); | ||
|
|
||
| RerankResult result = inference.rerank(model, query, documents); | ||
|
|
||
| assertNotNull(result); | ||
| Assertions.assertEquals(result.getData().size(), documents.size()); | ||
| Assertions.assertEquals(result.getData().get(0).getIndex(), 2); | ||
| Assertions.assertEquals(result.getData().get(0).getDocument().get("text"), doc3.get("text")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error from before.