Skip to content

Conversation

@rohanshah18
Copy link
Contributor

@rohanshah18 rohanshah18 commented Nov 12, 2025

Problem

Add support for createNamespace() endpoint, and add prefix + totalCount to listNamespaces().

Solution

This PR adds the createNamespace method and enhances listNamespaces with prefix filtering and total count support for both Index and AsyncIndex clients.

Create Namespace:

  1. Basic Namespace Creation: Create a namespace explicitly by name:
// Create a namespace explicitly
NamespaceDescription createdNamespace = index.createNamespace("my-namespace");
assertNotNull(createdNamespace);
assertEquals("my-namespace", createdNamespace.getName());

// Verify the namespace was created
ListNamespacesResponse response = index.listNamespaces();
assertTrue(response.getNamespacesList().stream()
    .anyMatch(ns -> ns.getName().equals("my-namespace")));
  1. Metadata Schema Support: Create a namespace with a metadata schema to define filterable fields:
// Create a namespace with metadata schema
MetadataSchema schema = MetadataSchema.newBuilder()
    .putFields("genre", MetadataFieldProperties.newBuilder().setFilterable(true).build())
    .putFields("year", MetadataFieldProperties.newBuilder().setFilterable(true).build())
    .build();

NamespaceDescription namespaceWithSchema = index.createNamespace("movies-namespace", schema);
assertNotNull(namespaceWithSchema);
assertEquals("movies-namespace", namespaceWithSchema.getName());

Prefix Filtering: Filter namespaces by prefix to retrieve only namespaces starting with a specific prefix:

// List namespaces with prefix filtering
ListNamespacesResponse response = index.listNamespaces("test-", null, 100);
int totalCount = response.getTotalCount(); // Total namespaces matching "test-" prefix
List<NamespaceDescription> namespaces = response.getNamespacesList();

// Verify all returned namespaces match the prefix
for (NamespaceDescription ns : namespaces) {
    assert ns.getName().startsWith("test-");
}

Total Count: The response includes a totalCount field indicating the total number of namespaces matching the prefix (useful for pagination):

// Get total count even when results are paginated
ListNamespacesResponse response = index.listNamespaces("prod-", null, 10);
int totalCount = response.getTotalCount(); // Total matching namespaces
int returnedCount = response.getNamespacesCount(); // Namespaces in this page (≤ 10)

// Use totalCount to determine if more pages are available
if (totalCount > returnedCount) {
    // More namespaces available via pagination
}

Async Support: Same functionality available for AsyncIndex:

// Create namespace asynchronously
ListenableFuture<NamespaceDescription> future = asyncIndex.createNamespace("async-namespace");
NamespaceDescription createdNamespace = future.get();

// Create namespace with schema asynchronously
ListenableFuture<NamespaceDescription> futureWithSchema = 
    asyncIndex.createNamespace("async-movies", schema);
NamespaceDescription namespace = futureWithSchema.get();

// List namespaces with prefix filtering asynchronously
ListenableFuture<ListNamespacesResponse> listFuture = asyncIndex.listNamespaces("dev-", null, 50);
ListNamespacesResponse response = listFuture.get();
int totalCount = response.getTotalCount();

Note:

  • Null or empty prefix values are ignored (no filtering applied)
  • The method signature is: listNamespaces(String prefix, String paginationToken, int limit)
  • Both synchronous (Index) and asynchronous (AsyncIndex) implementations are included
  • Fully backward compatible - existing listNamespaces() methods remain unchanged

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

Updated NamespacesTests.java to include:

  • createNamespace() call
  • prefix and totalCount

@rohanshah18 rohanshah18 changed the base branch from main to rshah/release-candidate/2025-10 November 12, 2025 19:42
@rohanshah18 rohanshah18 marked this pull request as ready for review November 12, 2025 20:59
@rohanshah18 rohanshah18 merged commit 6a3cf70 into rshah/release-candidate/2025-10 Nov 12, 2025
9 checks passed
@rohanshah18 rohanshah18 deleted the rshah/namespaces branch November 12, 2025 20:59
rohanshah18 added a commit that referenced this pull request Nov 12, 2025
)

## Problem

Add support for `createNamespace()` endpoint, and add `prefix` +
`totalCount` to `listNamespaces()`.

## Solution

This PR adds the `createNamespace` method and enhances `listNamespaces`
with prefix filtering and total count support for both `Index` and
`AsyncIndex` clients.

**Create Namespace**: 
1. Basic Namespace Creation: Create a namespace explicitly by name:
```java
// Create a namespace explicitly
NamespaceDescription createdNamespace = index.createNamespace("my-namespace");
assertNotNull(createdNamespace);
assertEquals("my-namespace", createdNamespace.getName());

// Verify the namespace was created
ListNamespacesResponse response = index.listNamespaces();
assertTrue(response.getNamespacesList().stream()
    .anyMatch(ns -> ns.getName().equals("my-namespace")));
```

2. Metadata Schema Support: Create a namespace with a metadata schema to
define filterable fields:
```java
// Create a namespace with metadata schema
MetadataSchema schema = MetadataSchema.newBuilder()
    .putFields("genre", MetadataFieldProperties.newBuilder().setFilterable(true).build())
    .putFields("year", MetadataFieldProperties.newBuilder().setFilterable(true).build())
    .build();

NamespaceDescription namespaceWithSchema = index.createNamespace("movies-namespace", schema);
assertNotNull(namespaceWithSchema);
assertEquals("movies-namespace", namespaceWithSchema.getName());
```

**Prefix Filtering**: Filter namespaces by prefix to retrieve only
namespaces starting with a specific prefix:

```java
// List namespaces with prefix filtering
ListNamespacesResponse response = index.listNamespaces("test-", null, 100);
int totalCount = response.getTotalCount(); // Total namespaces matching "test-" prefix
List<NamespaceDescription> namespaces = response.getNamespacesList();

// Verify all returned namespaces match the prefix
for (NamespaceDescription ns : namespaces) {
    assert ns.getName().startsWith("test-");
}
```

**Total Count**: The response includes a `totalCount` field indicating
the total number of namespaces matching the prefix (useful for
pagination):

```
// Get total count even when results are paginated
ListNamespacesResponse response = index.listNamespaces("prod-", null, 10);
int totalCount = response.getTotalCount(); // Total matching namespaces
int returnedCount = response.getNamespacesCount(); // Namespaces in this page (≤ 10)

// Use totalCount to determine if more pages are available
if (totalCount > returnedCount) {
    // More namespaces available via pagination
}
```

**Async Support**: Same functionality available for `AsyncIndex`:

```
// Create namespace asynchronously
ListenableFuture<NamespaceDescription> future = asyncIndex.createNamespace("async-namespace");
NamespaceDescription createdNamespace = future.get();

// Create namespace with schema asynchronously
ListenableFuture<NamespaceDescription> futureWithSchema = 
    asyncIndex.createNamespace("async-movies", schema);
NamespaceDescription namespace = futureWithSchema.get();

// List namespaces with prefix filtering asynchronously
ListenableFuture<ListNamespacesResponse> listFuture = asyncIndex.listNamespaces("dev-", null, 50);
ListNamespacesResponse response = listFuture.get();
int totalCount = response.getTotalCount();
```

**Note**: 
- Null or empty prefix values are ignored (no filtering applied)
- The method signature is: `listNamespaces(String prefix, String
paginationToken, int limit)`
- Both synchronous (`Index`) and asynchronous (`AsyncIndex`)
implementations are included
- Fully backward compatible - existing `listNamespaces()` methods remain
unchanged


## 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

Updated NamespacesTests.java to include:
- `createNamespace()` call
- `prefix` and `totalCount`
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