Skip to content

Commit a8aa221

Browse files
authored
Add additional list functions to reach parity with RESTful list requests #130 (#133)
## Problem #126 ## Solution With REST, we are currently able to list vectors without a prefix but with a pagination token. This is not currently available with v1 of the pinecone-java-client. With this PR, we have added a function list with a pagination token and limit but no prefix.
1 parent 641585d commit a8aa221

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

src/integration/java/io/pinecone/integration/dataPlane/ListEndpointTest.java

+38
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void testSyncListEndpoint() throws InterruptedException {
4545

4646
// Confirm all vector IDs from custom namespace are returned when pass customNamespace
4747
ListResponse listResponseCustomNamespace = indexConnection.list(customNamespace);
48+
assertEquals(listResponseCustomNamespace.getVectorsList().size(), 4);
4849
assertTrue(listResponseCustomNamespace.getVectorsList().toString().contains("cus-id1"));
4950
assertTrue(listResponseCustomNamespace.getVectorsList().toString().contains("cus-id2"));
5051
assertTrue(listResponseCustomNamespace.getVectorsList().toString().contains("cus-prefix-id3"));
@@ -59,6 +60,23 @@ public void testSyncListEndpoint() throws InterruptedException {
5960
// Confirm all vector IDs from custom namespace are returned when limit is specified
6061
ListResponse listResponseWithLimit = indexConnection.list(customNamespace, 1);
6162
assertEquals(1, listResponseWithLimit.getVectorsList().size());
63+
64+
// Confirm all vector IDs from custom namespace are returned using pagination
65+
ListResponse listResponseWithPaginationNoPrefix1 = indexConnection.list(customNamespace, 2);
66+
assertEquals(listResponseWithPaginationNoPrefix1.getVectorsList().size(), 2);
67+
ListResponse listResponseWithPaginationNoPrefix2 = indexConnection.list(
68+
customNamespace,
69+
2,
70+
listResponseWithPaginationNoPrefix1.getPagination().getNext()
71+
);
72+
assertEquals(listResponseWithPaginationNoPrefix2.getVectorsList().size(), 2);
73+
ListResponse listResponseWithPaginationNoPrefix3 = indexConnection.list(
74+
customNamespace,
75+
2,
76+
listResponseWithPaginationNoPrefix2.getPagination().getNext()
77+
);
78+
assertEquals(listResponseWithPaginationNoPrefix3.getVectorsList().size(), 0);
79+
assertEquals(listResponseWithPaginationNoPrefix3.getPagination().getNext(), "");
6280
}
6381

6482
@Test
@@ -92,6 +110,26 @@ public void testAsyncListEndpoint() throws InterruptedException {
92110
ListenableFuture<ListResponse> futureResponseWithLimit = asyncIndexConnection.list(customNamespace, 1);
93111
ListResponse asyncListResponseWithLimit = Futures.getUnchecked(futureResponseWithLimit);
94112
assertEquals(1, asyncListResponseWithLimit.getVectorsList().size());
113+
114+
// Confirm all vector IDs from custom namespace are returned using pagination
115+
ListenableFuture<ListResponse> futureResponseWithPaginationNoPrefix1 = asyncIndexConnection.list(customNamespace, 2);
116+
ListResponse asyncListResponseWithPaginationNoPrefix1 = Futures.getUnchecked(futureResponseWithPaginationNoPrefix1);
117+
assertEquals(asyncListResponseWithPaginationNoPrefix1.getVectorsList().size(), 2);
118+
ListenableFuture<ListResponse> futureResponseWithPaginationNoPrefix2 = asyncIndexConnection.list(
119+
customNamespace,
120+
2,
121+
asyncListResponseWithPaginationNoPrefix1.getPagination().getNext()
122+
);
123+
ListResponse asyncListResponseWithPaginationNoPrefix2 = Futures.getUnchecked(futureResponseWithPaginationNoPrefix2);
124+
assertEquals(asyncListResponseWithPaginationNoPrefix2.getVectorsList().size(), 2);
125+
ListenableFuture<ListResponse> futureResponseWithPaginationNoPrefix3 = asyncIndexConnection.list(
126+
customNamespace,
127+
2,
128+
asyncListResponseWithPaginationNoPrefix2.getPagination().getNext()
129+
);
130+
ListResponse asyncListResponseWithPaginationNoPrefix3 = Futures.getUnchecked(futureResponseWithPaginationNoPrefix3);
131+
assertEquals(asyncListResponseWithPaginationNoPrefix3.getVectorsList().size(), 0);
132+
assertEquals(asyncListResponseWithPaginationNoPrefix3.getPagination().getNext(), "");
95133
}
96134

97135
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,25 @@ public ListenableFuture<ListResponse> list(String namespace) {
892892
return asyncStub.list(listRequest);
893893
}
894894

895+
/**
896+
* {@inheritDoc}
897+
* <p>Example:
898+
* <pre>{@code
899+
* import io.pinecone.proto.ListResponse;
900+
*
901+
* ...
902+
*
903+
* ListenableFuture<ListResponse> futureResponse = asyncIndex.list("example-namespace", 10, "some-pagToken");
904+
* ListResponse asyncListResponse = Futures.getUnchecked(futureResponse);
905+
* }</pre>
906+
*/
907+
@Override
908+
public ListenableFuture<ListResponse> list(String namespace, int limit, String paginationToken) {
909+
validateListEndpointParameters(namespace, null, paginationToken, limit, true, false, true, true);
910+
ListRequest listRequest = ListRequest.newBuilder().setNamespace(namespace).setLimit(limit).setPaginationToken(paginationToken).build();
911+
return asyncStub.list(listRequest);
912+
}
913+
895914
/**
896915
* {@inheritDoc}
897916
*

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

+18
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,24 @@ public ListResponse list(String namespace) {
817817
return blockingStub.list(listRequest);
818818
}
819819

820+
/**
821+
* {@inheritDoc}
822+
* <p>Example:
823+
* <pre>{@code
824+
* import io.pinecone.proto.ListResponse;
825+
*
826+
* ...
827+
*
828+
* ListResponse listResponse = index.list("example-namespace", 10, "some-pagToken");
829+
* }</pre>
830+
*/
831+
@Override
832+
public ListResponse list(String namespace, int limit, String paginationToken) {
833+
validateListEndpointParameters(namespace, null, paginationToken, limit, true, false, true, true);
834+
ListRequest listRequest = ListRequest.newBuilder().setNamespace(namespace).setLimit(limit).setPaginationToken(paginationToken).build();
835+
return blockingStub.list(listRequest);
836+
}
837+
820838
/**
821839
* {@inheritDoc}
822840
* <p>Example:

src/main/java/io/pinecone/commons/IndexInterface.java

+11
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,17 @@ default void validateListEndpointParameters(String namespace, String prefix, Str
763763
*/
764764
Z list(String namespace);
765765

766+
/**
767+
* Retrieves up to {@code n} vector IDs from a given namespace, targeted with a specific
768+
* paginationToken, where {@code limit} == {@code n}.
769+
*
770+
* @param namespace The namespace that holds the vector IDs you want to retrieve.
771+
* @param limit The maximum number of vector IDs to retrieve.
772+
* @param paginationToken The token to paginate through the list of vector IDs.
773+
* @return A generic type {@code Y} that contains vector IDs.
774+
*/
775+
Z list(String namespace, int limit, String paginationToken);
776+
766777
/**
767778
* Retrieves up to {@code n} vector IDs from a given namespace, where {@code limit} == {@code n}.
768779
*

0 commit comments

Comments
 (0)