Commit c01528e
committed
Add createNamespace(), and prefix + totalCount to listNamespaces() (#205)
## 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`1 parent 3e3c086 commit c01528e
File tree
5 files changed
+261
-9
lines changed- src
- integration/java/io/pinecone/integration/dataPlane
- main/java/io/pinecone
- clients
- commons
5 files changed
+261
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
700 | 730 | | |
701 | 731 | | |
702 | 732 | | |
| |||
722 | 752 | | |
723 | 753 | | |
724 | 754 | | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
725 | 768 | | |
726 | 769 | | |
727 | 770 | | |
| |||
Lines changed: 62 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | | - | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
36 | 46 | | |
37 | 47 | | |
38 | 48 | | |
39 | 49 | | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
43 | | - | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
50 | 60 | | |
51 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
52 | 80 | | |
53 | 81 | | |
54 | 82 | | |
55 | 83 | | |
56 | | - | |
| 84 | + | |
57 | 85 | | |
58 | 86 | | |
59 | 87 | | |
60 | 88 | | |
61 | 89 | | |
62 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
63 | 98 | | |
64 | 99 | | |
65 | 100 | | |
66 | 101 | | |
67 | 102 | | |
68 | 103 | | |
69 | 104 | | |
70 | | - | |
| 105 | + | |
71 | 106 | | |
72 | 107 | | |
73 | 108 | | |
74 | 109 | | |
75 | 110 | | |
76 | 111 | | |
77 | 112 | | |
78 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
79 | 132 | | |
80 | | - | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
1124 | 1126 | | |
1125 | 1127 | | |
1126 | 1128 | | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1127 | 1189 | | |
1128 | 1190 | | |
1129 | 1191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
1034 | 1036 | | |
1035 | 1037 | | |
1036 | 1038 | | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
1037 | 1099 | | |
1038 | 1100 | | |
1039 | 1101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
854 | 854 | | |
855 | 855 | | |
856 | 856 | | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
857 | 889 | | |
858 | 890 | | |
859 | 891 | | |
| |||
0 commit comments