Skip to content

Commit ffcee4b

Browse files
authored
Add support for models api (#187)
## Problem Add support for models api. ## Solution This PR contains following changes: 1. Regenerated code based on the latest changes in the 2025-04 OAS, which introduced a breaking change in `listProjectBackups()`. It previously accepted no arguments but now accepts two optional ones: an Integer limit and a String paginationToken. 2. Added support for models api by adding the following methods: 1. listModels() 2. listModels(String type) 3. listModels(String type, String vectorType) 4. describeModel(String modelName) 3. Added integration test for various list and describe model methods. Following code shows how to list and describe an embedding model: ```java import io.pinecone.clients.Inference; import io.pinecone.clients.Pinecone; import org.openapitools.inference.client.ApiException; import org.openapitools.inference.client.model.ModelInfo; import org.openapitools.inference.client.model.ModelInfoList; ... Pinecone pinecone = new Pinecone .Builder(System.getenv("PINECONE_API_KEY")) .build(); Inference inference = pinecone.getInferenceClient(); // list models ModelInfoList models = inference.listModels(); System.out.println(models); // list models by filtering with type models = inference.listModels("rerank"); System.out.println(models); // list models by filtering with type and vectorType models = inference.listModels("embed", "dense"); System.out.println(models); // describe a model ModelInfo modelInfo = inference.describeModel("llama-text-embed-v2"); System.out.println(modelInfo); ``` ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [X] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Added integration tests.
1 parent cb00bc3 commit ffcee4b

File tree

119 files changed

+407
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+407
-435
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ pinecone.deleteCollection("example-collection");
651651

652652
# Inference
653653
## Embed
654+
654655
The Pinecone SDK now supports creating embeddings via the [Inference API](https://docs.pinecone.io/guides/inference/understanding-inference).
655656

656657
```java
@@ -689,6 +690,7 @@ List<Embedding> embeddedData = embeddings.getData();
689690
```
690691

691692
## Rerank
693+
692694
The following example shows how to rerank items according to their relevance to a query.
693695

694696
```java
@@ -751,6 +753,41 @@ RerankResult result = inference.rerank(model, query, documents, rankFields, topN
751753
System.out.println(result.getData());
752754
```
753755

756+
## Models
757+
758+
The following example shows how to list and describe an embedding model.
759+
760+
```java
761+
import io.pinecone.clients.Inference;
762+
import io.pinecone.clients.Pinecone;
763+
import org.openapitools.inference.client.ApiException;
764+
import org.openapitools.inference.client.model.ModelInfo;
765+
import org.openapitools.inference.client.model.ModelInfoList;
766+
...
767+
768+
Pinecone pinecone = new Pinecone
769+
.Builder(System.getenv("PINECONE_API_KEY"))
770+
.build();
771+
772+
Inference inference = pinecone.getInferenceClient();
773+
774+
// list models
775+
ModelInfoList models = inference.listModels();
776+
System.out.println(models);
777+
778+
// list models by filtering with type
779+
models = inference.listModels("rerank");
780+
System.out.println(models);
781+
782+
// list models by filtering with type and vectorType
783+
models = inference.listModels("embed", "dense");
784+
System.out.println(models);
785+
786+
// describe a model
787+
ModelInfo modelInfo = inference.describeModel("llama-text-embed-v2");
788+
System.out.println(modelInfo);
789+
```
790+
754791
# Imports
755792
## Start an import
756793

@@ -862,7 +899,7 @@ BackupList backupList = pinecone.listIndexBackups(indexName1);
862899
System.out.println("backupList for index1: " + backupList);
863900

864901
// list all backups for a project
865-
backupList = pinecone.listProjectBackups();
902+
backupList = pinecone.listProjectBackups(3, "some-pagination-token");
866903
System.out.println("backupList for project: " + backupList);
867904

868905
// describe backup

codegen/apis

Submodule apis updated from daf808c to a915858
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.pinecone.integration.inference;
2+
3+
import io.pinecone.clients.Inference;
4+
import io.pinecone.clients.Pinecone;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
import org.openapitools.inference.client.ApiException;
8+
import org.openapitools.inference.client.model.ModelInfo;
9+
import org.openapitools.inference.client.model.ModelInfoList;
10+
11+
public class ModelsTest {
12+
private static final Pinecone pinecone = new Pinecone
13+
.Builder(System.getenv("PINECONE_API_KEY"))
14+
.withSourceTag("pinecone_test")
15+
.build();
16+
17+
private static final Inference inference = pinecone.getInferenceClient();
18+
19+
@Test
20+
public void testListAndDescribeModels() throws ApiException {
21+
ModelInfoList models = inference.listModels();
22+
Assertions.assertNotNull(models.getModels());
23+
24+
models = inference.listModels("rerank");
25+
Assertions.assertNotNull(models.getModels());
26+
27+
models = inference.listModels("embed", "dense");
28+
Assertions.assertNotNull(models.getModels());
29+
30+
ModelInfo modelInfo = inference.describeModel("llama-text-embed-v2");
31+
Assertions.assertNotNull(modelInfo);
32+
}
33+
}

src/main/java/io/pinecone/clients/Inference.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,46 @@ public RerankResult rerank(String model,
116116
return inferenceApi.rerank(rerankRequest);
117117
}
118118

119+
/**
120+
* Overloaded method to list available models.
121+
* @return ModelInfoList
122+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
123+
*/
124+
public ModelInfoList listModels() throws ApiException {
125+
return inferenceApi.listModels(null, null);
126+
}
127+
128+
/**
129+
* Overloaded method to list available models based on type parameter only.
130+
* @param type Filter models by type (&#39;embed&#39; or &#39;rerank&#39;). (optional)
131+
* @return ModelInfoList
132+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
133+
*/
134+
public ModelInfoList listModels(String type) throws ApiException {
135+
return inferenceApi.listModels(type, null);
136+
}
137+
138+
/**
139+
* List available models.
140+
* @param type Filter models by type (&#39;embed&#39; or &#39;rerank&#39;). (optional)
141+
* @param vectorType Filter embedding models by vector type (&#39;dense&#39; or &#39;sparse&#39;). Only relevant when &#x60;type&#x3D;embed&#x60;. (optional)
142+
* @return ModelInfoList
143+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
144+
*/
145+
public ModelInfoList listModels(String type, String vectorType) throws ApiException {
146+
return inferenceApi.listModels(type, vectorType);
147+
}
148+
149+
/**
150+
* Get available model details.
151+
* @param modelName The name of the model to look up. (required)
152+
* @return ModelInfo
153+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
154+
*/
155+
public ModelInfo describeModel(String modelName) throws ApiException {
156+
return inferenceApi.getModel(modelName);
157+
}
158+
119159
/**
120160
* Converts a list of input strings to EmbedRequestInputsInner objects.
121161
*

src/main/java/io/pinecone/clients/Pinecone.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -913,17 +913,26 @@ public BackupList listIndexBackups(String indexName, Integer limit, String pagin
913913

914914
/**
915915
* List backups for all indexes in a project
916-
* List all backups for a project.
917916
*
918917
* @return BackupList
919918
*/
920919
public BackupList listProjectBackups() throws ApiException {
921-
return manageIndexesApi.listProjectBackups();
920+
return listProjectBackups(null, null);
921+
}
922+
923+
/**
924+
* List backups for all indexes in a project
925+
* @param limit The number of results to return per page. (optional)
926+
* @param paginationToken The token to use to retrieve the next page of results. (optional)
927+
*
928+
* @return BackupList
929+
*/
930+
public BackupList listProjectBackups(Integer limit, String paginationToken) throws ApiException {
931+
return manageIndexesApi.listProjectBackups(limit, paginationToken);
922932
}
923933

924934
/**
925935
* Describe a backup
926-
* Get a description of a backup.
927936
*
928937
* @param backupId The ID of the backup to describe. (required)
929938
* @return BackupModel
@@ -959,7 +968,7 @@ public void createIndexFromBackup(String backupId, String indexName, Map<String,
959968
if (deletionProtection != null) {
960969
createIndexFromBackupRequest.deletionProtection(deletionProtection);
961970
}
962-
manageIndexesApi.createIndexFromBackup(backupId, createIndexFromBackupRequest);
971+
manageIndexesApi.createIndexFromBackupOperation(backupId, createIndexFromBackupRequest);
963972
}
964973

965974
/**
@@ -974,7 +983,7 @@ public void createIndexFromBackup(String backupId, String indexName, Map<String,
974983
public CreateIndexFromBackupResponse createIndexFromBackup(String backupId, String indexName) throws ApiException {
975984
CreateIndexFromBackupRequest createIndexFromBackupRequest = new CreateIndexFromBackupRequest()
976985
.name(indexName);
977-
return manageIndexesApi.createIndexFromBackup(backupId, createIndexFromBackupRequest);
986+
return manageIndexesApi.createIndexFromBackupOperation(backupId, createIndexFromBackupRequest);
978987
}
979988

980989
/**

src/main/java/org/openapitools/db_control/client/ApiException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* <p>ApiException class.</p>
2222
*/
2323
@SuppressWarnings("serial")
24-
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-04-29T13:39:23.829370Z[Etc/UTC]")
24+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-05-22T16:07:13.211110Z[Etc/UTC]")
2525
public class ApiException extends Exception {
2626
private int code = 0;
2727
private Map<String, List<String>> responseHeaders = null;

src/main/java/org/openapitools/db_control/client/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
package org.openapitools.db_control.client;
1515

16-
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-04-29T13:39:23.829370Z[Etc/UTC]")
16+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-05-22T16:07:13.211110Z[Etc/UTC]")
1717
public class Configuration {
1818
public static final String VERSION = "2025-04";
1919

src/main/java/org/openapitools/db_control/client/Pair.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
package org.openapitools.db_control.client;
1515

16-
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-04-29T13:39:23.829370Z[Etc/UTC]")
16+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-05-22T16:07:13.211110Z[Etc/UTC]")
1717
public class Pair {
1818
private String name = "";
1919
private String value = "";

src/main/java/org/openapitools/db_control/client/StringUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.Collection;
1717
import java.util.Iterator;
1818

19-
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-04-29T13:39:23.829370Z[Etc/UTC]")
19+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-05-22T16:07:13.211110Z[Etc/UTC]")
2020
public class StringUtil {
2121
/**
2222
* Check if the given array contains the given value (with case-insensitive comparison).

0 commit comments

Comments
 (0)