Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void testSyncListEndpoint() throws InterruptedException {

// Confirm all vector IDs from custom namespace are returned when pass customNamespace
ListResponse listResponseCustomNamespace = indexConnection.list(customNamespace);
assertEquals(listResponseCustomNamespace.getVectorsList().size(), 4);
assertTrue(listResponseCustomNamespace.getVectorsList().toString().contains("cus-id1"));
assertTrue(listResponseCustomNamespace.getVectorsList().toString().contains("cus-id2"));
assertTrue(listResponseCustomNamespace.getVectorsList().toString().contains("cus-prefix-id3"));
Expand All @@ -59,6 +60,23 @@ public void testSyncListEndpoint() throws InterruptedException {
// Confirm all vector IDs from custom namespace are returned when limit is specified
ListResponse listResponseWithLimit = indexConnection.list(customNamespace, 1);
assertEquals(1, listResponseWithLimit.getVectorsList().size());

// Confirm all vector IDs from custom namespace are returned using pagination
ListResponse listResponseWithPaginationNoPrefix1 = indexConnection.list(customNamespace, 2);
assertEquals(listResponseWithPaginationNoPrefix1.getVectorsList().size(), 2);
ListResponse listResponseWithPaginationNoPrefix2 = indexConnection.list(
customNamespace,
2,
listResponseWithPaginationNoPrefix1.getPagination().getNext()
);
assertEquals(listResponseWithPaginationNoPrefix2.getVectorsList().size(), 2);
ListResponse listResponseWithPaginationNoPrefix3 = indexConnection.list(
customNamespace,
2,
listResponseWithPaginationNoPrefix2.getPagination().getNext()
);
assertEquals(listResponseWithPaginationNoPrefix3.getVectorsList().size(), 0);
assertEquals(listResponseWithPaginationNoPrefix3.getPagination().getNext(), "");
}

@Test
Expand Down Expand Up @@ -92,6 +110,26 @@ public void testAsyncListEndpoint() throws InterruptedException {
ListenableFuture<ListResponse> futureResponseWithLimit = asyncIndexConnection.list(customNamespace, 1);
ListResponse asyncListResponseWithLimit = Futures.getUnchecked(futureResponseWithLimit);
assertEquals(1, asyncListResponseWithLimit.getVectorsList().size());

// Confirm all vector IDs from custom namespace are returned using pagination
ListenableFuture<ListResponse> futureResponseWithPaginationNoPrefix1 = asyncIndexConnection.list(customNamespace, 2);
ListResponse asyncListResponseWithPaginationNoPrefix1 = Futures.getUnchecked(futureResponseWithPaginationNoPrefix1);
assertEquals(asyncListResponseWithPaginationNoPrefix1.getVectorsList().size(), 2);
ListenableFuture<ListResponse> futureResponseWithPaginationNoPrefix2 = asyncIndexConnection.list(
customNamespace,
2,
asyncListResponseWithPaginationNoPrefix1.getPagination().getNext()
);
ListResponse asyncListResponseWithPaginationNoPrefix2 = Futures.getUnchecked(futureResponseWithPaginationNoPrefix2);
assertEquals(asyncListResponseWithPaginationNoPrefix2.getVectorsList().size(), 2);
ListenableFuture<ListResponse> futureResponseWithPaginationNoPrefix3 = asyncIndexConnection.list(
customNamespace,
2,
asyncListResponseWithPaginationNoPrefix2.getPagination().getNext()
);
ListResponse asyncListResponseWithPaginationNoPrefix3 = Futures.getUnchecked(futureResponseWithPaginationNoPrefix3);
assertEquals(asyncListResponseWithPaginationNoPrefix3.getVectorsList().size(), 0);
assertEquals(asyncListResponseWithPaginationNoPrefix3.getPagination().getNext(), "");
}

}
19 changes: 19 additions & 0 deletions src/main/java/io/pinecone/clients/AsyncIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,25 @@ public ListenableFuture<ListResponse> list(String namespace) {
return asyncStub.list(listRequest);
}

/**
* {@inheritDoc}
* <p>Example:
* <pre>{@code
* import io.pinecone.proto.ListResponse;
*
* ...
*
* ListenableFuture<ListResponse> futureResponse = asyncIndex.list("example-namespace", 10, "some-pagToken");
* ListResponse asyncListResponse = Futures.getUnchecked(futureResponse);
* }</pre>
*/
@Override
public ListenableFuture<ListResponse> list(String namespace, int limit, String paginationToken) {
validateListEndpointParameters(namespace, null, paginationToken, limit, true, false, true, true);
ListRequest listRequest = ListRequest.newBuilder().setNamespace(namespace).setLimit(limit).setPaginationToken(paginationToken).build();
return asyncStub.list(listRequest);
}

/**
* {@inheritDoc}
*
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/pinecone/clients/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,24 @@ public ListResponse list(String namespace) {
return blockingStub.list(listRequest);
}

/**
* {@inheritDoc}
* <p>Example:
* <pre>{@code
* import io.pinecone.proto.ListResponse;
*
* ...
*
* ListResponse listResponse = index.list("example-namespace", 10, "some-pagToken");
* }</pre>
*/
@Override
public ListResponse list(String namespace, int limit, String paginationToken) {
validateListEndpointParameters(namespace, null, paginationToken, limit, true, false, true, true);
ListRequest listRequest = ListRequest.newBuilder().setNamespace(namespace).setLimit(limit).setPaginationToken(paginationToken).build();
return blockingStub.list(listRequest);
}

/**
* {@inheritDoc}
* <p>Example:
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/pinecone/commons/IndexInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,17 @@ default void validateListEndpointParameters(String namespace, String prefix, Str
*/
Z list(String namespace);

/**
* Retrieves up to {@code n} vector IDs from a given namespace, targeted with a specific
* paginationToken, where {@code limit} == {@code n}.
*
* @param namespace The namespace that holds the vector IDs you want to retrieve.
* @param limit The maximum number of vector IDs to retrieve.
* @param paginationToken The token to paginate through the list of vector IDs.
* @return A generic type {@code Y} that contains vector IDs.
*/
Z list(String namespace, int limit, String paginationToken);

/**
* Retrieves up to {@code n} vector IDs from a given namespace, where {@code limit} == {@code n}.
*
Expand Down