Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

chore: clean it

Zohaib Hassnainb8299b1427a5
diff --git a/semantica/vector_store/pinecone_store.py b/semantica/vector_store/pinecone_store.py
index c9ff2475..131e3dd0 100644
--- a/semantica/vector_store/pinecone_store.py
+++ b/semantica/vector_store/pinecone_store.py
@@ -302,9 +302,8 @@ class PineconeSearch:
def _pinecone_listed_ids(response: Any) -> List[str]:
"""Extract vector IDs from a list_paginated() response.
- What listing returns has changed across pinecone SDK major versions, so
- this accepts record objects, plain id strings and dicts rather than
- committing to one shape.
+ Accepts record objects, bare id strings and dicts, since what listing
+ returns has changed across pinecone SDK major versions.
"""
records = getattr(response, "vectors", None)
if records is None and isinstance(response, dict):
@@ -778,16 +777,13 @@ class PineconeStore:
"""
Iterate over every stored vector by listing IDs then fetching them.
- Pinecone paginates with an opaque continuation token, so this is
- exposed instead of scan_vectors(offset, limit): there is no way to
- construct the token for logical page N without walking there.
- VectorStore.iter_vectors() prefers this method when it is present.
+ Paginates with an opaque continuation token, which is why this exists
+ instead of scan_vectors(offset, limit): the token for page N cannot be
+ constructed without walking there.
- Unlike the other backends this needs two calls per page. Listing
- returns IDs only, so each page is hydrated with a fetch(). Both calls
- are namespace scoped and must agree, and listing covers one namespace
- rather than the whole index, so a store whose data lives outside the
- default namespace has to pass it explicitly.
+ Needs two calls per page, unlike the other backends, because listing
+ returns IDs only. Both calls are namespace scoped and must agree, and
+ listing covers one namespace rather than the whole index.
Args:
batch_size: IDs to request per list_paginated() call
@@ -797,22 +793,18 @@ class PineconeStore:
Result dicts with 'id', 'metadata', and 'vector', in listing order
Raises:
- ProcessingError: If the index is not initialized, or the installed
- SDK does not expose list_paginated(). Errors are raised rather
- than swallowed because a scan that silently yields nothing is
- indistinguishable from an empty source, which would let a
- caller such as `store migrate` report success having copied
- nothing (issue #1083).
+ ProcessingError: If the index is not initialized, if the installed
+ SDK does not expose list_paginated(), or if the listing stops
+ advancing.
"""
if self.index is None or not PINECONE_AVAILABLE:
raise ProcessingError(
"Index not initialized. Call create_index() or get_index() first."
)
- # list_paginated() is used rather than list(): in current SDKs list()
- # is an auto-paging iterator over response objects, while older
- # examples read as though it yields plain id lists. Threading the
- # token explicitly is unambiguous across versions.
+ # list_paginated() rather than list(): list() is an auto-paging
+ # iterator in current SDKs but reads as plain id lists in older
+ # examples. Threading the token explicitly is version-agnostic.
list_paginated = getattr(self.index.index, "list_paginated", None)
if not callable(list_paginated):
raise ProcessingError(
@@ -837,8 +829,7 @@ class PineconeStore:
for vector_id in vector_ids:
entry = vectors.get(vector_id)
if entry is None:
- # Fetch omits ids it cannot find, so this one was deleted
- # between the list call and the fetch call.
+ # fetch() omits ids it cannot find: deleted since listing.
continue
values = entry.get("values")
yield {
@@ -851,10 +842,8 @@ class PineconeStore:
if not next_token:
return
if next_token == token:
- # Distinct from exhaustion above: the listing is not advancing.
- # Returning here would yield a partial scan that a caller cannot
- # tell apart from a complete one, and `store migrate` would flush
- # it and report success having copied only part of the index.
+ # Distinct from exhaustion above: a partial scan here would be
+ # indistinguishable from a complete one.
raise ProcessingError(
"Pinecone returned the same pagination token twice, so the "
"listing is not advancing. Refusing to return a truncated "
diff --git a/tests/vector_store/test_pinecone_store.py b/tests/vector_store/test_pinecone_store.py
index b5bcfcd0..04e990a7 100644
--- a/tests/vector_store/test_pinecone_store.py
+++ b/tests/vector_store/test_pinecone_store.py
@@ -253,7 +253,7 @@ class TestPineconeIterAll(unittest.TestCase):
"""PineconeStore.iter_all() list-then-fetch enumeration."""
def _page(self, ids, next_token):
- """Stand-in for a list_paginated() ListResponse."""
+ """Stand-in for a list_paginated() response."""
response = MagicMock()
response.vectors = [MagicMock(id=vector_id) for vector_id in ids]
response.pagination = MagicMock(next=next_token)
@@ -289,7 +289,7 @@ class TestPineconeIterAll(unittest.TestCase):
@patch('semantica.vector_store.pinecone_store.PINECONE_AVAILABLE', True)
def test_hydrates_listed_ids_with_a_fetch(self):
- """Listing returns ids only, so each page needs a second call."""
+ """Listing returns ids only, so each page needs a fetch()."""
store, wrapper, _ = self._store(
[self._page(["a"], None)],
[{"vectors": {"a": {"values": [0.1, 0.2], "metadata": {"tag": "x"}}}}],
@@ -316,7 +316,7 @@ class TestPineconeIterAll(unittest.TestCase):
@patch('semantica.vector_store.pinecone_store.PINECONE_AVAILABLE', True)
def test_skips_ids_deleted_between_list_and_fetch(self):
- """Fetch omits ids it cannot find rather than returning empty entries."""
+ """fetch() omits ids it cannot find rather than returning blanks."""
store, _, _ = self._store(
[self._page(["a", "gone"], None)],
[{"vectors": {"a": {"values": [0.1], "metadata": {}}}}],
@@ -328,13 +328,8 @@ class TestPineconeIterAll(unittest.TestCase):
@patch('semantica.vector_store.pinecone_store.PINECONE_AVAILABLE', True)
def test_raises_when_pagination_token_repeats(self):
- """A token that stops advancing must not loop forever, and must not
- quietly return a partial scan either.
-
- Truncating silently is indistinguishable from a complete enumeration,
- which would let store migrate copy part of an index and report success
- (issue #1083).
- """
+ """A stalled token must not loop forever, nor quietly return a partial
+ scan that reads as a complete one."""
store, _, raw_index = self._store(
[self._page(["a"], "same"), self._page(["b"], "same")],
[
@@ -357,7 +352,7 @@ class TestPineconeIterAll(unittest.TestCase):
@patch('semantica.vector_store.pinecone_store.PINECONE_AVAILABLE', True)
def test_accepts_plain_string_ids_from_listing(self):
- """SDK generations differ on what listing yields, so bare ids work too."""
+ """SDK generations differ on what listing yields."""
store, _, _ = self._store(
[self._page([], None)],
[{"vectors": {"a": {"values": [0.1], "metadata": {}}}}],
@@ -393,8 +388,7 @@ class TestPineconeIterAll(unittest.TestCase):
@patch('semantica.vector_store.pinecone_store.PINECONE_AVAILABLE', True)
def test_raises_when_index_not_initialized(self):
- """Must fail loudly, not yield nothing: an empty scan is
- indistinguishable from an empty source (issue #1083)."""
+ """Must fail loudly: an empty scan reads the same as an empty source."""
with self.assertRaises(ProcessingError):
list(PineconeStore().iter_all())