public class Pinecone
extends java.lang.Object
To instantiate the Pinecone class, use the Pinecone.Builder class to pass
an API key and any other optional configuration.
import io.pinecone.clients.Pinecone;
Pinecone client = new Pinecone.Builder("PINECONE_API_KEY").build();
// Use the client to interact with Pinecone
client.describeIndex("YOUR-INDEX");
// Use the client to obtain an Index or AsyncIndex instance to upsert or query
Index index = client.getIndexConnection("YOUR-INDEX");
index.upsert(...);
| Modifier and Type | Class and Description |
|---|---|
static class |
Pinecone.Builder
A builder class for creating a
Pinecone instance. |
| Modifier and Type | Method and Description |
|---|---|
IndexModel |
configureIndex(java.lang.String indexName,
java.lang.Integer replicas)
Overload for configureIndex to only change the number of replicas for an index.
|
IndexModel |
configureIndex(java.lang.String indexName,
java.lang.String podType)
Overload for configureIndex to only change the podType of an index.
|
IndexModel |
configureIndex(java.lang.String indexName,
java.lang.String podType,
java.lang.Integer replicas)
Configures an existing pod-based index with new settings.
|
CollectionModel |
createCollection(java.lang.String collectionName,
java.lang.String sourceIndex)
Creates a new collection from a source index.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType)
Overload for creating a new pods index with environment and podType, the minimum required parameters.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.Integer pods)
Overload for creating a new pods index with environment, podType, and pods.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.Integer pods,
CreateIndexRequestSpecPodMetadataConfig metadataConfig)
Overload for creating a new pods index with environment, podType, pods, and metadataConfig.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.Integer replicas,
java.lang.Integer shards)
Overload for creating a new pods index with environment, podType, replicas, and shards.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.Integer replicas,
java.lang.Integer shards,
CreateIndexRequestSpecPodMetadataConfig metadataConfig)
Overload for creating a new pods index with environment, podType, replicas, shards, and metadataConfig.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.String metric)
Overload for creating a new pods index with environment, podType, and metric.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.String metric,
CreateIndexRequestSpecPodMetadataConfig metadataConfig)
Overload for creating a new pods index with environment, podType, metric, and metadataConfig.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.String metric,
java.lang.Integer replicas,
java.lang.Integer shards,
java.lang.Integer pods,
CreateIndexRequestSpecPodMetadataConfig metadataConfig,
java.lang.String sourceCollection)
Creates a new pods index with the specified parameters.
|
IndexModel |
createPodsIndex(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.String metric,
java.lang.String sourceCollection)
Overload for creating a new pods index with environment, podType, metric, and sourceCollection.
|
IndexModel |
createServerlessIndex(java.lang.String indexName,
java.lang.String metric,
int dimension,
java.lang.String cloud,
java.lang.String region)
Creates a new serverless index with the specified parameters.
|
void |
deleteCollection(java.lang.String collectionName)
Deletes a collection.
|
void |
deleteIndex(java.lang.String indexName)
Deletes an index.
|
CollectionModel |
describeCollection(java.lang.String collectionName)
Describes an existing collection.
|
IndexModel |
describeIndex(java.lang.String indexName)
Retrieves information about an existing index.
|
AsyncIndex |
getAsyncIndexConnection(java.lang.String indexName)
Retrieves a connection to a specific index for asynchronous operations.
|
Index |
getIndexConnection(java.lang.String indexName)
Retrieves a connection to a specific index for synchronous operations.
|
CollectionList |
listCollections()
Lists all collections in the project.
|
IndexList |
listIndexes()
Lists all indexes in your project, including the index name, dimension, metric, status, and spec.
|
static void |
validatePodIndexParams(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.String metric,
java.lang.Integer replicas,
java.lang.Integer shards,
java.lang.Integer pods) |
public IndexModel createServerlessIndex(java.lang.String indexName, java.lang.String metric, int dimension, java.lang.String cloud, java.lang.String region) throws PineconeException
Example:
client.createServerlessIndex("YOUR-INDEX", "cosine", 1536, "aws", "us-west-2");
indexName - The name of the index to be created.metric - The metric type for the index. Must be one of "cosine", "euclidean", or "dotproduct".dimension - The number of dimensions for the index.cloud - The cloud provider for the index.region - The cloud region for the index.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType)
Example:
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2");
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.String metric)
Example:
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine");
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.metric - The metric type for the index. Must be one of "cosine", "euclidean", or "dotproduct".IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.String metric, CreateIndexRequestSpecPodMetadataConfig metadataConfig)
Example:
import org.openapitools.client.model.CreateIndexRequestSpecPodMetadataConfig;
...
CreateIndexRequestSpecPodMetadataConfig metadataConfig =
new CreateIndexRequestSpecPodMetadataConfig()
.fields(Arrays.asList("genre", "year"));
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", metadataConfig);
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.metric - The metric type for the index. Must be one of "cosine", "euclidean", or "dotproduct".metadataConfig - The configuration for the behavior of Pinecone's internal metadata index. By default, all metadata is indexed;
when metadataConfig is present, only specified metadata fields are indexed.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.String metric, java.lang.String sourceCollection)
Example:
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", "my-collection");
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.metric - The metric type for the index. Must be one of "cosine", "euclidean", or "dotproduct".sourceCollection - The name of the collection to be used as the source for the index. Collections are snapshots of an index at a point in time.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.Integer pods)
Example:
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", 6);
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.pods - The number of pods to be used in the index.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.Integer pods, CreateIndexRequestSpecPodMetadataConfig metadataConfig)
Example:
import org.openapitools.client.model.CreateIndexRequestSpecPodMetadataConfig;
...
CreateIndexRequestSpecPodMetadataConfig metadataConfig =
new CreateIndexRequestSpecPodMetadataConfig()
.fields(Arrays.asList("genre", "year"));
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", 6);
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.pods - The number of pods to be used in the index.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.Integer replicas, java.lang.Integer shards)
Example:
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", 2, 2);
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.replicas - The number of replicas. Replicas duplicate your index. They provide higher availability and throughput and can be scaled.shards - The number of shards. Shards split your data across multiple pods so you can fit more data into an index.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.Integer replicas, java.lang.Integer shards, CreateIndexRequestSpecPodMetadataConfig metadataConfig)
Example:
import org.openapitools.client.model.CreateIndexRequestSpecPodMetadataConfig;
...
CreateIndexRequestSpecPodMetadataConfig metadataConfig =
new CreateIndexRequestSpecPodMetadataConfig()
.fields(Arrays.asList("genre", "year"));
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", 2, 2, metadataConfig);
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.replicas - The number of replicas. Replicas duplicate your index. They provide higher availability and throughput and can be scaled.shards - The number of shards. Shards split your data across multiple pods so you can fit more data into an index.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public IndexModel createPodsIndex(java.lang.String indexName, java.lang.Integer dimension, java.lang.String environment, java.lang.String podType, java.lang.String metric, java.lang.Integer replicas, java.lang.Integer shards, java.lang.Integer pods, CreateIndexRequestSpecPodMetadataConfig metadataConfig, java.lang.String sourceCollection) throws PineconeException
Example:
import org.openapitools.client.model.CreateIndexRequestSpecPodMetadataConfig;
...
CreateIndexRequestSpecPodMetadataConfig metadataConfig =
new CreateIndexRequestSpecPodMetadataConfig()
.fields(Arrays.asList("genre", "year"));
client.createPodsIndex("YOUR-INDEX", 1536, "us-east4-gcp", "p1.x2", "cosine", 2, 2, 4, null, null);
indexName - The name of the index to be created.dimension - The number of dimensions for the index.environment - The cloud environment where you want the index to be hosted.podType - The type of pod to use. A string with one of s1, p1, or p2 appended with a "." and one of x1, x2, x4, or x8.metric - The metric type for the index. Must be one of "cosine", "euclidean", or "dotproduct".replicas - The number of replicas. Replicas duplicate your index. They provide higher availability and throughput and can be scaled.shards - The number of shards. Shards split your data across multiple pods so you can fit more data into an index.pods - The number of pods to be used in the index. This should be equal to shards x replicas.metadataConfig - The configuration for the behavior of Pinecone's internal metadata index. By default, all metadata is indexed;
when metadataConfig is present, only specified metadata fields are indexed.sourceCollection - The name of the collection to be used as the source for the index. Collections are snapshots of an index at a point in time.IndexModel representing the created serverless index.PineconeException - if the API encounters an error during index creation or if any of the arguments are invalid.public static void validatePodIndexParams(java.lang.String indexName,
java.lang.Integer dimension,
java.lang.String environment,
java.lang.String podType,
java.lang.String metric,
java.lang.Integer replicas,
java.lang.Integer shards,
java.lang.Integer pods)
public IndexModel describeIndex(java.lang.String indexName) throws PineconeException
Example:
import org.openapitools.client.model.IndexModel;
...
IndexModel indexModel = client.describeIndex("YOUR-INDEX");
indexName - The name of the index to describe.IndexModel with the details of the index.PineconeException - if an error occurs during the operation or the index does not exist.public IndexModel configureIndex(java.lang.String indexName, java.lang.String podType, java.lang.Integer replicas) throws PineconeException
Example:
import org.openapitools.client.model.IndexModel;
...
// Make a configuration change
IndexModel indexModel = client.configureIndex("YOUR-INDEX", "p1.x2", 4);
// Call describeIndex to see the index status as the change is applied.
indexModel = client.describeIndex("YOUR-INDEX");
indexName - The name of the index to configure.podType - The new podType for the index. Can be null if not changing the pod type.replicas - The desired number of replicas for the index, lowest value is 0. Can be null if not changing the number of replicas.IndexModel representing the configured index.PineconeException - if an error occurs during the operation, the index does not exist, or if any of the arguments are invalid.public IndexModel configureIndex(java.lang.String indexName, java.lang.Integer replicas) throws PineconeException
Example:
import org.openapitools.client.model.IndexModel;
...
IndexModel indexModel = client.configureIndex("YOUR-INDEX", 4);
indexName - The name of the index.replicas - The desired number of replicas for the index, lowest value is 0.IndexModel of the configured index.PineconeException - if an error occurs during the operation, the index does not exist, or if the number of replicas is invalid.public IndexModel configureIndex(java.lang.String indexName, java.lang.String podType) throws PineconeException
Example:
import org.openapitools.client.model.IndexModel;
...
IndexModel indexModel = client.configureIndex("YOUR-INDEX", "p1.x2");
indexName - The name of the index.podType - The new podType for the index.IndexModel of the configured index.PineconeException - if an error occurs during the operation, the index does not exist, or if the podType is invalid.public IndexList listIndexes() throws PineconeException
Example:
import org.openapitools.client.model.IndexList;
...
IndexList indexes = client.listIndexes();
IndexList containing all indexes.PineconeException - if an error occurs during the operation.public void deleteIndex(java.lang.String indexName)
throws PineconeException
Deleting an index is an irreversible operation. All data in the index will be lost. When you use this command, a request is sent to the Pinecone control plane to delete the index, but the termination is not synchronous because resources take a few moments to be released.
You can check the status of the index by calling the describeIndex command. With repeated polling of the describeIndex command, you will see the index transition to a Terminating state before eventually resulting in a 404 after it has been removed.
Example:
import org.openapitools.client.model.IndexModel;
...
// Delete an index
client.deleteIndex("YOUR-INDEX");
// Get index status with describeIndex
IndexModel indexModel = client.describeIndex("YOUR-INDEX");
indexModel.getStatus().getState();
indexName - The name of the index to delete.PineconeException - if an error occurs during the deletion operation or the index does not exist.public CollectionModel createCollection(java.lang.String collectionName, java.lang.String sourceIndex) throws PineconeException
Example:
import org.openapitools.client.model.CollectionModel;
...
CollectionModel collection = client.createCollection("my-collection", "my-source-index");
collectionName - The name of the new collection.sourceIndex - The name of the source index.CollectionModel representing the created collection.PineconeException - if an error occurs during the operation, or the source collection is invalid.public CollectionModel describeCollection(java.lang.String collectionName) throws PineconeException
Example:
import io.pinecone.clients.Pinecone;
import org.openapitools.client.model.CollectionModel;
...
CollectionModel collection = client.describeCollection("my-collection");
collectionName - The name of the collection to describe.CollectionModel with the description of the collection.PineconeException - if an error occurs during the operation or the collection does not exist.public CollectionList listCollections() throws PineconeException
Example:
import org.openapitools.client.model.CollectionList;
...
CollectionList collections = client.listCollections();
CollectionList containing all collections.PineconeException - if an error occurs during the listing operation.public void deleteCollection(java.lang.String collectionName)
throws PineconeException
Deleting a collection is an irreversible operation. All data in the collection will be lost. This method tells Pinecone you would like to delete a collection, but it takes a few moments to complete the operation. Use the describeCollection() method to confirm that the collection has been deleted.
Example:
client.deleteCollection('my-collection');
// Verify collection status with describeCollection
client.describeCollection('my-collection');
collectionName - The name of the collection to delete.PineconeException - if an error occurs during the deletion operation or the collection does not exist.public Index getIndexConnection(java.lang.String indexName) throws PineconeValidationException
Index object that represents a connection to an index and allowing for
synchronous operations against it.
Example:
import io.pinecone.clients.Index;
...
Index index = client.getIndexConnection("YOUR-INDEX");
// Use the index object to interact with the index
index.describeIndexStats();
indexName - The name of the index to connect to. Must not be null or empty.Index object representing the connection to the specified index.PineconeValidationException - If the indexName is null or empty.public AsyncIndex getAsyncIndexConnection(java.lang.String indexName) throws PineconeValidationException
AsyncIndex object that represents a connection to an index and allowing for
synchronous operations against it.
Example:
import io.pinecone.clients.AsyncIndex;
...
AsyncIndex asyncIndex = client.getAsyncIndexConnection("YOUR-INDEX");
// Use the index object to interact with the index
asyncIndex.describeIndexStats();
indexName - The name of the index to connect to. Must not be null or empty.AsyncIndex object representing the connection to the specified index.PineconeValidationException - If the indexName is null or empty.