-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add integrated inference #181
Open
rohanshah18
wants to merge
6
commits into
main
Choose a base branch
from
rshah/integrated-inference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b47d6f7
add upsert and search records
rohanshah18 f4ceca5
reorganize and add createIndexForModel
rohanshah18 d79f288
update docstrings and reorganize
rohanshah18 8855415
add embed to configure request
rohanshah18 1fe95d4
add overloads and clean up
rohanshah18 4f1b653
add tests for overloaded search methods
rohanshah18 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 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
This file contains 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
This file contains 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
This file contains 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/dataPlane/UpsertAndSearchRecordsTest.java
This file contains 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.dataPlane; | ||
|
||
import io.pinecone.clients.Index; | ||
import io.pinecone.clients.Pinecone; | ||
import io.pinecone.helpers.RandomStringBuilder; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.db_control.client.model.CreateIndexForModelRequest; | ||
import org.openapitools.db_control.client.model.CreateIndexForModelRequestEmbed; | ||
import org.openapitools.db_control.client.model.DeletionProtection; | ||
import org.openapitools.db_data.client.ApiException; | ||
import org.openapitools.db_data.client.model.SearchRecordsRequestQuery; | ||
import org.openapitools.db_data.client.model.SearchRecordsRequestRerank; | ||
import org.openapitools.db_data.client.model.SearchRecordsResponse; | ||
|
||
import java.util.*; | ||
|
||
public class UpsertAndSearchRecordsTest { | ||
@Test | ||
public void upsertAndSearchRecordsTest() throws ApiException, org.openapitools.db_control.client.ApiException, InterruptedException { | ||
Pinecone pinecone = new Pinecone.Builder(System.getenv("PINECONE_API_KEY")).build(); | ||
String indexName = RandomStringBuilder.build("inf", 8); | ||
HashMap<String, String> fieldMap = new HashMap<>(); | ||
fieldMap.put("text", "chunk_text"); | ||
CreateIndexForModelRequestEmbed embed = new CreateIndexForModelRequestEmbed() | ||
.model("multilingual-e5-large") | ||
.fieldMap(fieldMap); | ||
pinecone.createIndexForModel(indexName, CreateIndexForModelRequest.CloudEnum.AWS, "us-west-2", embed, DeletionProtection.DISABLED, new HashMap<>()); | ||
|
||
// Wait for index to be created | ||
Thread.sleep(10000); | ||
|
||
Index index = pinecone.getIndexConnection(indexName); | ||
ArrayList<Map<String, String>> upsertRecords = new ArrayList<>(); | ||
|
||
HashMap<String, String> record1 = new HashMap<>(); | ||
record1.put("_id", "rec1"); | ||
record1.put("category", "digestive system"); | ||
record1.put("chunk_text", "Apples are a great source of dietary fiber, which supports digestion and helps maintain a healthy gut."); | ||
|
||
HashMap<String, String> record2 = new HashMap<>(); | ||
record2.put("_id", "rec2"); | ||
record2.put("category", "cultivation"); | ||
record2.put("chunk_text", "Apples originated in Central Asia and have been cultivated for thousands of years, with over 7,500 varieties available today."); | ||
|
||
HashMap<String, String> record3 = new HashMap<>(); | ||
record3.put("_id", "rec3"); | ||
record3.put("category", "immune system"); | ||
record3.put("chunk_text", "Rich in vitamin C and other antioxidants, apples contribute to immune health and may reduce the risk of chronic diseases."); | ||
|
||
HashMap<String, String> record4 = new HashMap<>(); | ||
record4.put("_id", "rec4"); | ||
record4.put("category", "endocrine system"); | ||
record4.put("chunk_text", "The high fiber content in apples can also help regulate blood sugar levels, making them a favorable snack for people with diabetes."); | ||
|
||
upsertRecords.add(record1); | ||
upsertRecords.add(record2); | ||
upsertRecords.add(record3); | ||
upsertRecords.add(record4); | ||
|
||
index.upsertRecords("example-namespace", upsertRecords); | ||
|
||
String namespace = "example-namespace"; | ||
HashMap<String, String> inputsMap = new HashMap<>(); | ||
inputsMap.put("text", "Disease prevention"); | ||
SearchRecordsRequestQuery query = new SearchRecordsRequestQuery() | ||
.topK(4) | ||
.inputs(inputsMap); | ||
|
||
List<String> fields = new ArrayList<>(); | ||
fields.add("category"); | ||
fields.add("chunk_text"); | ||
|
||
// Wait for vectors to be upserted | ||
Thread.sleep(5000); | ||
|
||
SearchRecordsResponse recordsResponse = index.searchRecords(namespace, query, fields, null); | ||
Assertions.assertEquals(upsertRecords.size(), recordsResponse.getResult().getHits().size()); | ||
Assertions.assertEquals(record3.get("_id"), recordsResponse.getResult().getHits().get(0).getId()); | ||
|
||
recordsResponse = index.searchRecordsById(record1.get("_id"), namespace, fields, 1, null, null); | ||
Assertions.assertEquals(1, recordsResponse.getResult().getHits().size()); | ||
Assertions.assertEquals(record1.get("_id"), recordsResponse.getResult().getHits().get(0).getId()); | ||
|
||
SearchRecordsRequestRerank rerank = new SearchRecordsRequestRerank() | ||
.model("bge-reranker-v2-m3") | ||
.topN(2) | ||
.rankFields(Arrays.asList("chunk_text")); | ||
|
||
recordsResponse = index.searchRecordsByText("Disease prevention", namespace, fields, 4, null, rerank); | ||
Assertions.assertEquals(record3.get("_id"), recordsResponse.getResult().getHits().get(0).getId()); | ||
|
||
pinecone.deleteIndex(indexName); | ||
} | ||
} |
This file contains 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
This file contains 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.
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.
I think we should consider creating some API abstractions over the
SearchRecordsRequestQuery
interface.For example, it might feel more natural if the user could query with something like:
We could also support ID and vector queries in a similar way?