Skip to content

Commit

Permalink
/v1/namespaces (#49)
Browse files Browse the repository at this point in the history
* /v1/namespaces

* bump
  • Loading branch information
fw42 authored Dec 17, 2024
1 parent 50d3745 commit 53a3bd9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "turbopuffer"
version = "0.1.23"
version = "0.1.24"
description = "Python Client for accessing the turbopuffer API"
authors = ["turbopuffer Inc. <[email protected]>"]
homepage = "https://turbopuffer.com"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_500_retried():

with mock.patch.object(time, 'sleep', return_value=None) as sleep:
with pytest.raises(tpuf.error.APIError):
backend.make_api_request('vectors', payload={})
backend.make_api_request('namespaces', payload={})
assert sleep.call_count == tpuf.max_retries - 1


Expand All @@ -38,5 +38,5 @@ def test_429_retried():

with mock.patch.object(time, 'sleep', return_value=None) as sleep:
with pytest.raises(tpuf.error.APIError):
backend.make_api_request('vectors', payload={})
backend.make_api_request('namespaces', payload={})
assert sleep.call_count == tpuf.max_retries - 1
26 changes: 13 additions & 13 deletions turbopuffer/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __eq__(self, other):
return False

def refresh_metadata(self):
response = self.backend.make_api_request('vectors', self.name, method='HEAD')
response = self.backend.make_api_request('namespaces', self.name, method='HEAD')
status_code = response.get('status_code')
if status_code == 200:
headers = response.get('headers', dict())
Expand Down Expand Up @@ -170,7 +170,7 @@ def schema(self) -> NamespaceSchema:
"""
Returns the current schema for the namespace.
"""
response = self.backend.make_api_request('vectors', self.name, 'schema', method='GET')
response = self.backend.make_api_request('namespaces', self.name, 'schema', method='GET')
return parse_namespace_schema(response["content"])

def update_schema(self, schema_updates: NamespaceSchema):
Expand All @@ -181,7 +181,7 @@ def update_schema(self, schema_updates: NamespaceSchema):
See https://turbopuffer.com/docs/schema for specifics on allowed updates.
"""
request_payload = json.dumps({key: value.as_dict() for key, value in schema_updates.items()}).encode()
response = self.backend.make_api_request('vectors', self.name, 'schema', method='POST', payload=request_payload)
response = self.backend.make_api_request('namespaces', self.name, 'schema', method='POST', payload=request_payload)
return parse_namespace_schema(response["content"])

@overload
Expand Down Expand Up @@ -255,7 +255,7 @@ def upsert(self, data=None, ids=None, vectors=None, attributes=None, schema=None
if schema is not None:
payload["schema"] = schema

response = self.backend.make_api_request('vectors', self.name, payload=payload)
response = self.backend.make_api_request('namespaces', self.name, payload=payload)

assert response.get('content', dict()).get('status', '') == 'OK', f'Invalid upsert() response: {response}'
self.metadata = None # Invalidate cached metadata
Expand Down Expand Up @@ -325,12 +325,12 @@ def delete(self, ids: Union[int, str, List[int], List[str]]) -> None:
"""

if isinstance(ids, int) or isinstance(ids, str):
response = self.backend.make_api_request('vectors', self.name, payload={
response = self.backend.make_api_request('namespaces', self.name, payload={
'ids': [ids],
'vectors': [None],
})
elif isinstance(ids, list):
response = self.backend.make_api_request('vectors', self.name, payload={
response = self.backend.make_api_request('namespaces', self.name, payload={
'ids': ids,
'vectors': [None] * len(ids),
})
Expand Down Expand Up @@ -391,7 +391,7 @@ def query(self,
else:
raise ValueError(f'query() input type must be compatible with turbopuffer.VectorQuery: {type(query_data)}')

response = self.backend.make_api_request('vectors', self.name, 'query', payload=query_data.__dict__)
response = self.backend.make_api_request('namespaces', self.name, 'query', payload=query_data.__dict__)
result = VectorResult(response.get('content', dict()), namespace=self)
result.performance = response.get('performance')
return result
Expand All @@ -404,7 +404,7 @@ def vectors(self, cursor: Optional[Cursor] = None) -> VectorResult:
If you want to look up vectors by ID, use the query function with an id filter.
"""

response = self.backend.make_api_request('vectors', self.name, query={'cursor': cursor})
response = self.backend.make_api_request('namespaces', self.name, query={'cursor': cursor})
content = response.get('content', dict())
next_cursor = content.pop('next_cursor', None)
result = VectorResult(content, namespace=self, next_cursor=next_cursor)
Expand All @@ -416,15 +416,15 @@ def delete_all_indexes(self) -> None:
Deletes all indexes in a namespace.
"""

response = self.backend.make_api_request('vectors', self.name, 'index', method='DELETE')
response = self.backend.make_api_request('namespaces', self.name, 'index', method='DELETE')
assert response.get('content', dict()).get('status', '') == 'ok', f'Invalid delete_all_indexes() response: {response}'

def delete_all(self) -> None:
"""
Deletes all data as well as all indexes.
"""

response = self.backend.make_api_request('vectors', self.name, method='DELETE')
response = self.backend.make_api_request('namespaces', self.name, method='DELETE')
assert response.get('content', dict()).get('status', '') == 'ok', f'Invalid delete_all() response: {response}'
self.metadata = None # Invalidate cached metadata

Expand All @@ -438,7 +438,7 @@ def recall(self, num=20, top_k=10) -> float:
Recall is calculated as the ratio of matching vectors between the two search results.
"""

response = self.backend.make_api_request('vectors', self.name, '_debug', 'recall', query={'num': num, 'top_k': top_k})
response = self.backend.make_api_request('namespaces', self.name, '_debug', 'recall', query={'num': num, 'top_k': top_k})
content = response.get('content', dict())
assert 'avg_recall' in content, f'Invalid recall() response: {response}'
return float(content.get('avg_recall'))
Expand Down Expand Up @@ -525,7 +525,7 @@ def __next__(self):
raise StopIteration
else:
response = self.backend.make_api_request(
'vectors',
'namespaces',
query={'cursor': self.next_cursor}
)
content = response.get('content', dict())
Expand All @@ -542,7 +542,7 @@ def namespaces(api_key: Optional[str] = None) -> Iterable[Namespace]:
If no api_key is provided, the globally configured API key will be used.
"""
backend = Backend(api_key)
response = backend.make_api_request('vectors')
response = backend.make_api_request('namespaces')
content = response.get('content', dict())
next_cursor = content.pop('next_cursor', None)
return NamespaceIterator(backend, content.pop('namespaces', list()), next_cursor)
2 changes: 1 addition & 1 deletion turbopuffer/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.1.23'
VERSION = '0.1.24'

0 comments on commit 53a3bd9

Please sign in to comment.