Skip to content

Commit e899a42

Browse files
committed
[ENH] add regeneration script for js library
1 parent ebe65f6 commit e899a42

File tree

14 files changed

+2834
-3004
lines changed

14 files changed

+2834
-3004
lines changed

clients/js/genapi.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env sh
22
set -e
33

4-
curl -s http://localhost:8000/openapi.json | jq > openapi.json
4+
# Run the transformation script instead of copying the file
5+
echo "Fetching and transforming OpenAPI specification..."
6+
python3 transform-openapi.py
57

8+
# Run the OpenAPI generator
9+
echo "Running OpenAPI generator..."
610
openapi-generator-plus -c config.yml
711

812
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -16,4 +20,4 @@ echo "import 'isomorphic-fetch';" > temp.txt
1620
cat packages/chromadb-core/src/generated/runtime.ts >> temp.txt
1721
mv temp.txt packages/chromadb-core/src/generated/runtime.ts
1822

19-
rm openapi.json
23+
rm openapi.json

clients/js/packages/chromadb-core/src/AdminClient.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class AdminClient {
150150
* ```
151151
*/
152152
public async createTenant({ name }: { name: string }): Promise<Tenant> {
153-
await this.api.createTenantV2({ name }, this.api.options);
153+
await this.api.createTenant({ name }, this.api.options);
154154

155155
return { name };
156156
}
@@ -172,7 +172,7 @@ export class AdminClient {
172172
* ```
173173
*/
174174
public async getTenant({ name }: { name: string }): Promise<Tenant> {
175-
const getTenant = (await this.api.getTenantV2(
175+
const getTenant = (await this.api.getTenant(
176176
name,
177177
this.api.options,
178178
)) as Tenant;
@@ -205,7 +205,7 @@ export class AdminClient {
205205
name: string;
206206
tenantName: string;
207207
}): Promise<{ name: string }> {
208-
await this.api.createDatabaseV2(tenantName, { name }, this.api.options);
208+
await this.api.createDatabase(tenantName, { name }, this.api.options);
209209

210210
return { name };
211211
}
@@ -235,9 +235,9 @@ export class AdminClient {
235235
name: string;
236236
tenantName: string;
237237
}): Promise<Database> {
238-
const result = (await this.api.getDatabaseV2(
239-
name,
238+
const result = (await this.api.getDatabase(
240239
tenantName,
240+
name,
241241
this.api.options,
242242
)) as Database;
243243

@@ -261,7 +261,7 @@ export class AdminClient {
261261
name: string;
262262
tenantName: string;
263263
}): Promise<void> {
264-
await this.api.deleteDatabaseV2(name, tenantName, this.api.options);
264+
await this.api.deleteDatabase(tenantName, name, this.api.options);
265265
return;
266266
}
267267

@@ -284,7 +284,7 @@ export class AdminClient {
284284
offset?: number;
285285
tenantName: string;
286286
}): Promise<Database[]> {
287-
const response = await this.api.listDatabasesV2(
287+
const response = await this.api.listDatabases(
288288
tenantName,
289289
limit,
290290
offset,

clients/js/packages/chromadb-core/src/ChromaClient.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class ChromaClient {
126126
*
127127
*/
128128
async getUserIdentity(): Promise<void> {
129-
const user_identity = (await this.api.getUserIdentityV2(
129+
const user_identity = (await this.api.getUserIdentity(
130130
this.api.options,
131131
)) as UserIdentity;
132132
const user_tenant = user_identity.tenant;
@@ -166,7 +166,7 @@ export class ChromaClient {
166166
*/
167167
async reset(): Promise<boolean> {
168168
await this.init();
169-
return await this.api.resetV2(this.api.options);
169+
return await this.api.reset(this.api.options);
170170
}
171171

172172
/**
@@ -180,7 +180,7 @@ export class ChromaClient {
180180
* ```
181181
*/
182182
async version(): Promise<string> {
183-
return await this.api.versionV2(this.api.options);
183+
return await this.api.version(this.api.options);
184184
}
185185

186186
/**
@@ -194,7 +194,8 @@ export class ChromaClient {
194194
* ```
195195
*/
196196
async heartbeat(): Promise<number> {
197-
const response = await this.api.heartbeatV2(this.api.options);
197+
const response = await this.api.heartbeat(this.api.options);
198+
console.log("[Heartbeat]", response);
198199
return response["nanosecond heartbeat"];
199200
}
200201

@@ -226,22 +227,22 @@ export class ChromaClient {
226227
embeddingFunction = new DefaultEmbeddingFunction(),
227228
}: CreateCollectionParams): Promise<Collection> {
228229
await this.init();
229-
const newCollection = (await this.api.createCollectionV2(
230+
const newCollection = await this.api.createCollection(
230231
this.tenant,
231232
this.database,
232233
{
233234
name,
234235
// @ts-ignore: we need to generate the client libraries again
235236
configuration: null, //TODO: Configuration type in JavaScript
236-
metadata,
237+
metadata: metadata as any,
237238
},
238239
this.api.options,
239-
)) as CollectionParams;
240+
);
240241

241242
return wrapCollection(this, {
242243
name: newCollection.name,
243244
id: newCollection.id,
244-
metadata: newCollection.metadata,
245+
metadata: newCollection.metadata as CollectionMetadata | undefined,
245246
embeddingFunction,
246247
});
247248
}
@@ -273,23 +274,23 @@ export class ChromaClient {
273274
embeddingFunction = new DefaultEmbeddingFunction(),
274275
}: GetOrCreateCollectionParams): Promise<Collection> {
275276
await this.init();
276-
const newCollection = (await this.api.createCollectionV2(
277+
const newCollection = await this.api.createCollection(
277278
this.tenant,
278279
this.database,
279280
{
280281
name,
281282
// @ts-ignore: we need to generate the client libraries again
282283
configuration: null, //TODO: Configuration type in JavaScript
283-
metadata,
284+
metadata: metadata as any,
284285
get_or_create: true,
285286
},
286287
this.api.options,
287-
)) as CollectionParams;
288+
);
288289

289290
return wrapCollection(this, {
290291
name: newCollection.name,
291292
id: newCollection.id,
292-
metadata: newCollection.metadata,
293+
metadata: newCollection.metadata as CollectionMetadata | undefined,
293294
embeddingFunction,
294295
});
295296
}
@@ -315,7 +316,7 @@ export class ChromaClient {
315316
> {
316317
await this.init();
317318

318-
const response = (await this.api.listCollectionsV2(
319+
const response = (await this.api.listCollections(
319320
this.tenant,
320321
this.database,
321322
limit,
@@ -352,7 +353,7 @@ export class ChromaClient {
352353
}[]
353354
> {
354355
await this.init();
355-
const results = (await this.api.listCollectionsV2(
356+
const results = (await this.api.listCollections(
356357
this.tenant,
357358
this.database,
358359
limit,
@@ -376,7 +377,7 @@ export class ChromaClient {
376377
*/
377378
async countCollections(): Promise<number> {
378379
await this.init();
379-
const response = (await this.api.countCollectionsV2(
380+
const response = (await this.api.countCollections(
380381
this.tenant,
381382
this.database,
382383
this.api.options,
@@ -405,17 +406,17 @@ export class ChromaClient {
405406
embeddingFunction,
406407
}: GetCollectionParams): Promise<Collection> {
407408
await this.init();
408-
const response = (await this.api.getCollectionV2(
409+
const response = await this.api.getCollection(
409410
this.tenant,
410411
this.database,
411412
name,
412413
this.api.options,
413-
)) as CollectionParams;
414+
);
414415

415416
return wrapCollection(this, {
416417
id: response.id,
417418
name: response.name,
418-
metadata: response.metadata,
419+
metadata: response.metadata as CollectionMetadata | undefined,
419420
embeddingFunction:
420421
embeddingFunction !== undefined
421422
? embeddingFunction
@@ -440,10 +441,10 @@ export class ChromaClient {
440441
async deleteCollection({ name }: DeleteCollectionParams): Promise<void> {
441442
await this.init();
442443

443-
await this.api.deleteCollectionV2(
444-
name,
444+
await this.api.deleteCollection(
445445
this.tenant,
446446
this.database,
447+
name,
447448
this.api.options,
448449
);
449450
}

clients/js/packages/chromadb-core/src/Collection.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ export class Collection {
7070
async add(params: AddRecordsParams): Promise<void> {
7171
await this.client.init();
7272

73-
await this.client.api.addV2(
73+
await this.client.api.collectionAdd(
7474
this.client.tenant,
7575
this.client.database,
7676
this.id,
7777
// TODO: For some reason the auto generated code requires metadata to be defined here.
7878
(await prepareRecordRequest(
7979
params,
8080
this.embeddingFunction,
81-
)) as GeneratedApi.AddV2Request,
81+
)) as GeneratedApi.AddCollectionRecordsPayload,
8282
this.client.api.options,
8383
);
8484
}
@@ -105,15 +105,15 @@ export class Collection {
105105
async upsert(params: UpsertRecordsParams): Promise<void> {
106106
await this.client.init();
107107

108-
await this.client.api.upsertV2(
108+
await this.client.api.collectionUpsert(
109109
this.client.tenant,
110110
this.client.database,
111111
this.id,
112112
// TODO: For some reason the auto generated code requires metadata to be defined here.
113113
(await prepareRecordRequest(
114114
params,
115115
this.embeddingFunction,
116-
)) as GeneratedApi.AddV2Request,
116+
)) as GeneratedApi.UpsertCollectionRecordsPayload,
117117
this.client.api.options,
118118
);
119119
}
@@ -129,7 +129,7 @@ export class Collection {
129129
*/
130130
async count(): Promise<number> {
131131
await this.client.init();
132-
return (await this.client.api.countV2(
132+
return (await this.client.api.collectionCount(
133133
this.client.tenant,
134134
this.client.database,
135135
this.id,
@@ -172,20 +172,20 @@ export class Collection {
172172

173173
const idsArray = ids ? toArray(ids) : undefined;
174174

175-
const resp = (await this.client.api.getV2(
176-
this.id,
175+
const resp = (await this.client.api.collectionGet(
177176
this.client.tenant,
178177
this.client.database,
178+
this.id,
179179
{
180180
ids: idsArray,
181181
where,
182182
limit,
183183
offset,
184-
include,
184+
include: include as unknown as GeneratedApi.Include[] | undefined,
185185
where_document: whereDocument,
186186
},
187187
this.client.api.options,
188-
)) as MultiGetResponse;
188+
)) as unknown as GetResponse;
189189

190190
return resp;
191191
}
@@ -212,7 +212,7 @@ export class Collection {
212212
async update(params: UpdateRecordsParams): Promise<void> {
213213
await this.client.init();
214214

215-
await this.client.api.updateV2(
215+
await this.client.api.collectionUpdate(
216216
this.client.tenant,
217217
this.client.database,
218218
this.id,
@@ -264,7 +264,7 @@ export class Collection {
264264
}: QueryRecordsParams): Promise<MultiQueryResponse> {
265265
await this.client.init();
266266

267-
let embeddings: unknown[] = [];
267+
let embeddings: number[][] = [];
268268

269269
// If queryEmbeddings is provided, use it
270270
if (queryEmbeddings) {
@@ -281,19 +281,21 @@ export class Collection {
281281
);
282282
}
283283

284-
const resp = (await this.client.api.getNearestNeighborsV2(
284+
const resp = (await this.client.api.collectionQuery(
285285
this.client.tenant,
286286
this.client.database,
287287
this.id,
288+
nResults,
289+
undefined,
288290
{
289291
query_embeddings: embeddings,
290292
n_results: nResults,
291293
where,
292294
where_document: whereDocument,
293-
include,
295+
include: include as unknown as GeneratedApi.Include[] | undefined,
294296
},
295297
this.client.api.options,
296-
)) as MultiQueryResponse;
298+
)) as unknown as MultiQueryResponse;
297299

298300
return resp;
299301
}
@@ -322,13 +324,13 @@ export class Collection {
322324
}): Promise<CollectionParams> {
323325
await this.client.init();
324326

325-
const resp = (await this.client.api.updateCollectionV2(
327+
const resp = (await this.client.api.updateCollection(
326328
this.client.tenant,
327329
this.client.database,
328330
this.id,
329331
{
330332
new_name: name,
331-
new_metadata: metadata,
333+
new_metadata: metadata as any,
332334
},
333335
this.client.api.options,
334336
)) as CollectionParams;
@@ -360,15 +362,15 @@ export class Collection {
360362
*/
361363
async peek({ limit = 10 }: PeekParams = {}): Promise<MultiGetResponse> {
362364
await this.client.init();
363-
return (await this.client.api.getV2(
364-
this.id,
365+
return (await this.client.api.collectionGet(
365366
this.client.tenant,
366367
this.client.database,
368+
this.id,
367369
{
368370
limit,
369371
},
370372
this.client.api.options,
371-
)) as MultiGetResponse;
373+
)) as unknown as MultiGetResponse;
372374
}
373375

374376
/**
@@ -398,10 +400,10 @@ export class Collection {
398400

399401
const idsArray = ids ? toArray(ids) : undefined;
400402

401-
await this.client.api.deleteV2(
402-
this.id,
403+
await this.client.api.collectionDelete(
403404
this.client.tenant,
404405
this.client.database,
406+
this.id,
405407
{
406408
ids: idsArray,
407409
where: where,

0 commit comments

Comments
 (0)