-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
248 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import NamedTuple, Optional, List | ||
|
||
class Pagination(NamedTuple): | ||
next: str | ||
|
||
class ListResponse(NamedTuple): | ||
namespace: str | ||
vectors: List | ||
pagination: Optional[Pagination] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
class TestListPaginated: | ||
def test_list_when_no_results(self, idx): | ||
results = idx.list_paginated(namespace='no-results') | ||
assert results != None | ||
assert results.namespace == 'no-results' | ||
assert len(results.vectors) == 0 | ||
# assert results.pagination == None | ||
|
||
def test_list_no_args(self, idx): | ||
results = idx.list_paginated() | ||
|
||
assert results != None | ||
assert len(results.vectors) == 9 | ||
assert results.namespace == '' | ||
# assert results.pagination == None | ||
|
||
def test_list_when_limit(self, idx, list_namespace): | ||
results = idx.list_paginated(limit=10, namespace=list_namespace) | ||
|
||
assert results != None | ||
assert len(results.vectors) == 10 | ||
assert results.namespace == list_namespace | ||
assert results.pagination != None | ||
assert results.pagination.next != None | ||
assert isinstance(results.pagination.next, str) | ||
assert results.pagination.next != '' | ||
|
||
def test_list_when_using_pagination(self, idx, list_namespace): | ||
results = idx.list_paginated( | ||
prefix='99', limit=5, namespace=list_namespace | ||
) | ||
next_results = idx.list_paginated( | ||
prefix='99', limit=5, namespace=list_namespace, pagination_token=results.pagination.next | ||
) | ||
next_next_results = idx.list_paginated( | ||
prefix='99', limit=5, namespace=list_namespace, pagination_token=next_results.pagination.next | ||
) | ||
|
||
assert results.namespace == list_namespace | ||
assert len(results.vectors) == 5 | ||
assert [v.id for v in results.vectors] == ['99', '990', '991', '992', '993'] | ||
assert len(next_results.vectors) == 5 | ||
assert [v.id for v in next_results.vectors] == ['994', '995', '996', '997', '998'] | ||
assert len(next_next_results.vectors) == 1 | ||
assert [v.id for v in next_next_results.vectors] == ['999'] | ||
# assert next_next_results.pagination == None | ||
|
||
class TestList: | ||
def test_list_with_defaults(self, idx): | ||
pages = [] | ||
page_sizes = [] | ||
page_count = 0 | ||
for ids in idx.list(): | ||
page_count += 1 | ||
assert ids != None | ||
page_sizes.append(len(ids)) | ||
pages.append(ids) | ||
|
||
assert page_count == 1 | ||
assert page_sizes == [9] | ||
|
||
def test_list(self, idx, list_namespace): | ||
results = idx.list(prefix='99', limit=20, namespace=list_namespace) | ||
|
||
page_count = 0 | ||
for ids in results: | ||
page_count += 1 | ||
assert ids != None | ||
assert len(ids) == 11 | ||
assert ids == ['99', '990', '991', '992', '993', '994', '995', '996', '997', '998', '999'] | ||
assert page_count == 1 | ||
|
||
def test_list_when_no_results_for_prefix(self, idx, list_namespace): | ||
page_count = 0 | ||
for ids in idx.list(prefix='no-results', namespace=list_namespace): | ||
page_count += 1 | ||
assert page_count == 0 | ||
|
||
def test_list_when_no_results_for_namespace(self, idx): | ||
page_count = 0 | ||
for ids in idx.list(prefix='99', namespace='no-results'): | ||
page_count += 1 | ||
assert page_count == 0 | ||
|
||
def test_list_when_multiple_pages(self, idx, list_namespace): | ||
pages = [] | ||
page_sizes = [] | ||
page_count = 0 | ||
|
||
for ids in idx.list(prefix='99', limit=5, namespace=list_namespace): | ||
page_count += 1 | ||
assert ids != None | ||
page_sizes.append(len(ids)) | ||
pages.append(ids) | ||
|
||
assert page_count == 3 | ||
assert page_sizes == [5, 5, 1] | ||
assert pages[0] == ['99', '990', '991', '992', '993'] | ||
assert pages[1] == ['994', '995', '996', '997', '998'] | ||
assert pages[2] == ['999'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pinecone import PineconeException | ||
import pytest | ||
|
||
class TestListErrors: | ||
def test_list_change_prefix_while_fetching_next_page(self, idx, list_namespace): | ||
results = idx.list_paginated(prefix='99', limit=5, namespace=list_namespace) | ||
with pytest.raises(PineconeException) as e: | ||
idx.list_paginated(prefix='98', limit=5, pagination_token=results.pagination.next) | ||
assert 'prefix' in str(e.value) | ||
|
||
@pytest.mark.skip(reason='Bug filed') | ||
def test_list_change_namespace_while_fetching_next_page(self, idx, namespace): | ||
results = idx.list_paginated(limit=5, namespace=namespace) | ||
with pytest.raises(PineconeException) as e: | ||
idx.list_paginated(limit=5, namespace='new-namespace', pagination_token=results.pagination.next) | ||
assert 'namespace' in str(e.value) |