Skip to content

Commit bf9384f

Browse files
committed
fix(storage): fix some more issues
1 parent 3a0f26f commit bf9384f

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/storage/src/storage3/_async/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def from_(self, id: str) -> AsyncBucketProxy:
8484

8585
def vectors(self) -> AsyncStorageVectorsClient:
8686
return AsyncStorageVectorsClient(
87-
url=self._base_url,
87+
url=self._base_url.joinpath("v1", "vector"),
8888
headers=self._headers,
8989
session=self.session,
9090
)

src/storage/src/storage3/_async/request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ async def send(
1919
body: JSON = None,
2020
query_params: Optional[QueryParams] = None,
2121
) -> Response:
22-
return await self._session.request(
22+
data = await self._session.request(
2323
method=http_method,
2424
json=body,
2525
url=str(self._base_url.joinpath(*path)),
2626
headers=self.headers,
2727
params=query_params or QueryParams(),
2828
)
29+
data.raise_for_status()
30+
return data

src/storage/src/storage3/_async/vectors.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ def with_metadata(self, **data: JSON) -> JSON:
3232

3333
async def create_index(
3434
self,
35+
index_name: str,
3536
dimension: int,
3637
distance_metric: DistanceMetric,
3738
data_type: str,
3839
metadata: Optional[MetadataConfiguration] = None,
3940
) -> None:
4041
body = self.with_metadata(
42+
indexName=index_name,
4143
dimension=dimension,
4244
distanceMetric=distance_metric,
4345
dataType=data_type,
@@ -90,7 +92,7 @@ def with_metadata(self, **data: JSON) -> JSON:
9092
}
9193

9294
async def put(self, vectors: List[VectorObject]) -> None:
93-
body = self.with_metadata(vectors=list(dict(v) for v in vectors))
95+
body = self.with_metadata(vectors=[v.as_json() for v in vectors])
9496
await self._request.send(http_method="POST", path=["PutVectors"], body=body)
9597

9698
async def get(
@@ -159,3 +161,14 @@ def __init__(self, url: URL, headers: Headers, session: AsyncClient) -> None:
159161

160162
def from_(self, bucket_name: str) -> AsyncVectorBucketScope:
161163
return AsyncVectorBucketScope(self._request, bucket_name)
164+
165+
async def create_bucket(self, bucket_name: str) -> None:
166+
body = {"vectorBucketName": bucket_name}
167+
await self._request.send(
168+
http_method="POST", path=["CreateVectorBucket"], body=body
169+
)
170+
171+
# async def get_bucket(self, bucket_name: str) -> GetBucketResponse:
172+
# body = { 'vectorBucketName': bucket_name }
173+
# data = await self._request.send(http_method='POST', path=['GetVectorBucket'], body=body)
174+
# return GetVectorsResponse.model_validate(data.content)

src/storage/src/storage3/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ class VectorObject(BaseModel):
207207
data: VectorData
208208
metadata: Optional[dict[str, Any]] = None
209209

210+
def as_json(self) -> JSON:
211+
return {"key": self.key, "data": dict(self.data), "metadata": self.metadata}
212+
210213

211214
class VectorMatch(BaseModel):
212215
key: str

0 commit comments

Comments
 (0)