Skip to content

Generate code for 2025-04, automate ndjson handling, add backups, restore, and namespaces. #183

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 5 commits into from
May 9, 2025

Conversation

rohanshah18
Copy link
Contributor

@rohanshah18 rohanshah18 commented Apr 9, 2025

Problem

  1. Generate code for 2025-04 and automate ndjson handling.
  2. Add support for backups and restore.
  3. Add support for namespaces

Solution

  1. Generated code using the 2025-04 open api spec and added sed command to automate the process of handling ndjson which is currently not handled by the open api genearted code in ApiClient.java of data.yaml module.
  2. Added support for backups and restore
  3. Added support for namespaces

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • 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

Integration tests were added for new features.

## Problem

Add support for backups and restore.

## Solution

Added support for backups and restore. Following code exactly shows how
to add a backup from an index and restore a serverless index from a
backup.
```java
import io.pinecone.clients.Pinecone;
import org.openapitools.db_control.client.ApiException;
import org.openapitools.db_control.client.model.*;

public class restoreAndBackups {
    public static void main(String[] args) throws ApiException, InterruptedException {
        Pinecone pinecone = new Pinecone.Builder("PINECONE_API_KEY").build();

        String indexName1 = "test-index-1";
        String indexName2 = "test-index-2";

        // create a backup from index
        BackupModel backupModel1 = pinecone.createBackup(indexName1, "backup-id-1", "description-for-backup-1");
        System.out.println("backupModel1: " + backupModel1);

        BackupModel backupModel2 = pinecone.createBackup(indexName2, "backup-id-2", "description-for-backup-2");
        System.out.println("backupModel2: " + backupModel2);

        // list all backups for an index
        BackupList backupList = pinecone.listIndexBackups(indexName1);
        System.out.println("backupList for index1: " + backupList);

        // list all backups for a project
        backupList = pinecone.listProjectBackups();
        System.out.println("backupList for project: " + backupList);

        // describe backup
        backupModel1 = pinecone.describeBackup(backupModel1.getBackupId());
        System.out.println("describe backup for index1: " + backupModel1);

        backupModel2 = pinecone.describeBackup(backupModel2.getBackupId());
        System.out.println("describe backup index2: " + backupModel2);

        // delete backup
        pinecone.deleteBackup(backupModel1.getBackupId());

        // wait for the backup to be ready
        Thread.sleep(10000);

        // create index from a backup
        CreateIndexFromBackupResponse backupResponse = pinecone.createIndexFromBackup(backupModel1.getBackupId(), "test-index-3");
        System.out.println(backupResponse.getRestoreJobId());

        // wait for index to be created
        Thread.sleep(5000);

        // describeRestoreJob
        RestoreJobModel restoreJobModel = pinecone.describeRestoreJob(backupResponse.getRestoreJobId());
        System.out.println("restore model: " + restoreJobModel);

        // listRestoreJobs
        RestoreJobList restoreJobList = pinecone.listRestoreJobs(2);
        System.out.println("restore job list: " + restoreJobList);
    }
}
```



## Type of Change

- [X] New feature (non-breaking change which adds functionality)

## Test Plan

Manually tested backups and restore by running the sample code above.
## Problem

Add support for list, describe, and delete namespaces.

## Solution

Generated code using 2025-04 protos and added the following methods for
namespaces for both `index` and `asyncIndex`:
1. `listNamespaces()`
2. `listNamespaces(String paginationToken)`
3. `listNamespaces(String paginationToken, int limit)`
4. `describeNamespace(String namespace) `
5. `deleteNamespace(String namespace) `

Following example shows `listNamespaces()`, `describeNamespace()`, and
`deleteNamespace()` methods for both `index` and `asyncIndex`.

```java
import io.pinecone.clients.AsyncIndex;
import io.pinecone.clients.Index;
import io.pinecone.clients.Pinecone;
import io.pinecone.proto.ListNamespacesResponse;
import io.pinecone.proto.NamespaceDescription;

import java.util.concurrent.ExecutionException;
...

String indexName = "PINECONE_INDEX_NAME";
Pinecone pinecone = new Pinecone.Builder("PINECONE_API_KEY").build();

//// Sync index example
Index index = pinecone.getIndexConnection(indexName);

// list namespaces without pagination token and limit (if no limit is passed, it'll default to 100)
ListNamespacesResponse listNamespacesResponse = index.listNamespaces();

// list namespaces with pagination token
listNamespacesResponse = index.listNamespaces("some-pagination-token");

// list namespaces with pagination token and a custom limit of 5
listNamespacesResponse = index.listNamespaces("some-pagination-token", 5);

// describe a namespace
NamespaceDescription namespaceDescription = index.describeNamespace("namespace");

// delete a namespace
index.deleteNamespace("namespace");


//// AsyncIndex example
AsyncIndex asyncIndex = pinecone.getAsyncIndexConnection(indexName);

// list namespaces without pagination token and limit (if no limit is passed, it'll default to 100)
ListNamespacesResponse asyncListNamespacesResponse = index.listNamespaces();

// list namespaces with pagination token
asyncListNamespacesResponse = asyncIndex.listNamespaces("some-pagination-token").get();

// list namespaces with pagination token and a custom limit of 5
asyncListNamespacesResponse = asyncIndex.listNamespaces("some-pagination-token", 5).get();

// describe a namespace
NamespaceDescription asyncNamespaceDescription = asyncIndex.describeNamespace("some-namespace").get();

// delete a namespace
asyncIndex.deleteNamespace("some-namespace");
```


## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] 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.
@rohanshah18 rohanshah18 marked this pull request as ready for review May 9, 2025 18:02
@rohanshah18 rohanshah18 changed the title Generate code for 2025-04 and automate ndjson handling Generate code for 2025-04, automate ndjson handling, add backups, restore, and namespaces. May 9, 2025
Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@rohanshah18 rohanshah18 merged commit cb00bc3 into main May 9, 2025
6 checks passed
@rohanshah18 rohanshah18 deleted the rshah/release-candidate/2025-04 branch May 9, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants