Skip to content

Commit

Permalink
Merge pull request #33 from upstash/DX-1331
Browse files Browse the repository at this point in the history
Fix: Handle None Namespace Case Properly
  • Loading branch information
fahreddinozcan authored Oct 11, 2024
2 parents 0800e7c + b0a859d commit 4bb79df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/core/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,24 @@ def test_upsert_data(embedding_index: Index, ns: str):
assert res[1].data == v2_data


def test_upsert_to_none_namespace(embedding_index: Index):
v_id = "none_namespace_vector_id"
v1_data = "Hello-World"

embedding_index.upsert(
vectors=[
Data(id=v_id, data=v1_data),
],
namespace=None, # type: ignore[arg-type]
)

# test if the data is indeed inserted to default namespace with namespace=None config
res = embedding_index.fetch(ids=[v_id], include_data=True, namespace="")

assert res[0] is not None
assert res[0].id == v_id


@pytest.mark.asyncio
@pytest.mark.parametrize("ns", NAMESPACES)
async def test_upsert_data_async(async_embedding_index: AsyncIndex, ns: str):
Expand Down
2 changes: 1 addition & 1 deletion upstash_vector/core/index_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


def _path_for(namespace: str, path: str) -> str:
if namespace == DEFAULT_NAMESPACE:
if namespace == DEFAULT_NAMESPACE or not namespace:
return path

return f"{path}/{namespace}"
Expand Down

0 comments on commit 4bb79df

Please sign in to comment.