Skip to content

Commit c120ab4

Browse files
authored
DX-1794: Do not make further requests for resumable query when for non-existing namespaces (#47)
When the server sends an empty uuid as response to the resumable query start, for example when no such namespace exists, we should not make further fetch next or stop calls, as no resumable query has started.
1 parent c354216 commit c120ab4

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "upstash-vector"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
description = "Serverless Vector SDK from Upstash"
55
license = "MIT"
66
authors = ["Upstash <[email protected]>"]

tests/core/test_resumable_query.py

+25
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,28 @@ async def assertion():
451451
assert next_result[0].id == "id1"
452452

453453
await assert_eventually_async(assertion)
454+
455+
456+
def test_resumable_query_non_existing_namespace(index: Index):
457+
result, handle = index.resumable_query(
458+
vector=[0.1, 0.2],
459+
namespace="non-existing-namespace",
460+
)
461+
462+
with handle:
463+
assert len(result) == 0
464+
next_result = handle.fetch_next(5)
465+
assert len(next_result) == 0
466+
467+
468+
@pytest.mark.asyncio
469+
async def test_resumable_query_non_existing_namespace_async(async_index: AsyncIndex):
470+
result, handle = await async_index.resumable_query(
471+
vector=[0.1, 0.2],
472+
namespace="non-existing-namespace",
473+
)
474+
475+
async with handle:
476+
assert len(result) == 0
477+
next_result = await handle.fetch_next(5)
478+
assert len(next_result) == 0

upstash_vector/core/index_operations.py

+12
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ def fetch_next(self, additional_k: int) -> List[QueryResult]:
12951295
Returns:
12961296
List[QueryResult]: The next batch of query results.
12971297
"""
1298+
if self._uid == "":
1299+
return []
1300+
12981301
payload = {"uuid": self._uid, "additionalK": additional_k}
12991302
result = self._exec_fn(payload, RESUMABLE_QUERY_NEXT_PATH)
13001303
return [QueryResult._from_json(obj) for obj in result]
@@ -1303,6 +1306,9 @@ def stop(self) -> None:
13031306
"""
13041307
Stops the resumable query.
13051308
"""
1309+
if self._uid == "":
1310+
return
1311+
13061312
payload = {"uuid": self._uid}
13071313
self._exec_fn(payload, RESUMABLE_QUERY_END_PATH)
13081314

@@ -1338,6 +1344,9 @@ async def fetch_next(self, additional_k: int) -> List[QueryResult]:
13381344
Returns:
13391345
List[QueryResult]: The next batch of query results.
13401346
"""
1347+
if self._uid == "":
1348+
return []
1349+
13411350
payload = {"uuid": self._uid, "additionalK": additional_k}
13421351
result = await self._exec_fn(payload, RESUMABLE_QUERY_NEXT_PATH)
13431352
return [QueryResult._from_json(obj) for obj in result]
@@ -1346,5 +1355,8 @@ async def stop(self) -> None:
13461355
"""
13471356
Stops the resumable query.
13481357
"""
1358+
if self._uid == "":
1359+
return
1360+
13491361
payload = {"uuid": self._uid}
13501362
await self._exec_fn(payload, RESUMABLE_QUERY_END_PATH)

0 commit comments

Comments
 (0)