chromadb 3.0.10 โ†’ 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,15 +11,28 @@ This package gives you a JS/TS interface to talk to a backend Chroma DB over RES
11
11
  - [๐Ÿ’ก Colab Example](https://colab.research.google.com/drive/1QEzFyqnoFxq7LUGyP1vzR4iLt9PpCDXv?usp=sharing)
12
12
  - [๐Ÿ  Homepage](https://www.trychroma.com/)
13
13
 
14
+ ## Chroma Cloud
15
+
16
+ Our hosted service, Chroma Cloud, powers serverless vector and full-text search. It's extremely fast, cost-effective, scalable and painless. Create a DB and try it out in under 30 seconds with $5 of free credits.
17
+
18
+ [Get started with Chroma Cloud](https://trychroma.com/signup)
19
+
14
20
  ## Getting started
15
21
 
16
- Chroma needs to be running in order for this client to talk to it. Please see the [๐Ÿงช Usage Guide](https://docs.trychroma.com/guides) to learn how to quickly stand this up.
22
+ First, start a Chroma server using the Chroma CLI:
23
+
24
+ ```bash
25
+ chroma run
26
+ ```
27
+
28
+ See more examples on our [docs](https://docs.trychroma.com/docs/overview/getting-started)
17
29
 
18
30
  ## Small example
19
31
 
20
32
  ```js
21
33
  import { ChromaClient } from "chromadb";
22
- const chroma = new ChromaClient({ path: "http://localhost:8000" });
34
+
35
+ const chroma = new ChromaClient();
23
36
  const collection = await chroma.createCollection({ name: "test-from-js" });
24
37
  for (let i = 0; i < 20; i++) {
25
38
  await collection.add({
@@ -8,9 +8,9 @@ type Database = {
8
8
  tenant: string;
9
9
  };
10
10
  type EmbeddingFunctionConfiguration = {
11
- type: "legacy";
11
+ type: 'legacy';
12
12
  } | (EmbeddingFunctionNewConfiguration & {
13
- type: "known";
13
+ type: 'known';
14
14
  });
15
15
  type EmbeddingFunctionNewConfiguration = {
16
16
  config: unknown;
@@ -29,8 +29,8 @@ type HnswConfiguration = {
29
29
  space?: null | HnswSpace;
30
30
  sync_threshold?: number | null;
31
31
  };
32
- type HnswSpace = "l2" | "cosine" | "ip";
33
- type Include = "distances" | "documents" | "embeddings" | "metadatas" | "uris";
32
+ type HnswSpace = 'l2' | 'cosine' | 'ip';
33
+ type Include = 'distances' | 'documents' | 'embeddings' | 'metadatas' | 'uris';
34
34
  type SpannConfiguration = {
35
35
  ef_construction?: number | null;
36
36
  ef_search?: number | null;
@@ -95,6 +95,12 @@ interface RecordSet extends BaseRecordSet {
95
95
  /** Array of unique record identifiers */
96
96
  ids: string[];
97
97
  }
98
+ interface PreparedRecordSet extends Omit<RecordSet, "embeddings"> {
99
+ embeddings?: number[][] | string[];
100
+ }
101
+ interface PreparedInsertRecordSet extends PreparedRecordSet {
102
+ embeddings: number[][] | string[];
103
+ }
98
104
  declare const recordSetFields: string[];
99
105
  /**
100
106
  * Record set for query operations with required embeddings.
@@ -928,4 +934,4 @@ declare class ChromaRateLimitError extends Error {
928
934
  }
929
935
  declare function createErrorByType(type: string, message: string): InvalidCollectionError | InvalidArgumentError | undefined;
930
936
 
931
- export { AdminClient, type AdminClientArgs, AdminCloudClient, type BaseRecordSet, ChromaClient, type ChromaClientArgs, ChromaClientError, ChromaConnectionError, ChromaError, ChromaForbiddenError, ChromaNotFoundError, ChromaQuotaExceededError, ChromaRateLimitError, ChromaServerError, ChromaUnauthorizedError, ChromaUniqueError, ChromaValueError, CloudClient, type Collection, type CollectionConfiguration, type CollectionMetadata, type CreateCollectionConfiguration, type EmbeddingFunction, type EmbeddingFunctionClass, type EmbeddingFunctionSpace, GetResult, type HNSWConfiguration, IncludeEnum, InvalidArgumentError, InvalidCollectionError, type ListDatabasesArgs, type Metadata, type QueryRecordSet, QueryResult, type QueryRowResult, type RecordSet, type UpdateCollectionConfiguration, type UpdateHNSWConfiguration, type UpdateSPANNConfiguration, type UserIdentity, type Where, type WhereDocument, baseRecordSetFields, createErrorByType, getDefaultEFConfig, getEmbeddingFunction, knownEmbeddingFunctions, processCreateCollectionConfig, processUpdateCollectionConfig, recordSetFields, registerEmbeddingFunction, serializeEmbeddingFunction, withChroma };
937
+ export { AdminClient, type AdminClientArgs, AdminCloudClient, type BaseRecordSet, ChromaClient, type ChromaClientArgs, ChromaClientError, ChromaConnectionError, ChromaError, ChromaForbiddenError, ChromaNotFoundError, ChromaQuotaExceededError, ChromaRateLimitError, ChromaServerError, ChromaUnauthorizedError, ChromaUniqueError, ChromaValueError, CloudClient, type Collection, type CollectionConfiguration, type CollectionMetadata, type CreateCollectionConfiguration, type EmbeddingFunction, type EmbeddingFunctionClass, type EmbeddingFunctionSpace, GetResult, type HNSWConfiguration, IncludeEnum, InvalidArgumentError, InvalidCollectionError, type ListDatabasesArgs, type Metadata, type PreparedInsertRecordSet, type PreparedRecordSet, type QueryRecordSet, QueryResult, type QueryRowResult, type RecordSet, type UpdateCollectionConfiguration, type UpdateHNSWConfiguration, type UpdateSPANNConfiguration, type UserIdentity, type Where, type WhereDocument, baseRecordSetFields, createErrorByType, getDefaultEFConfig, getEmbeddingFunction, knownEmbeddingFunctions, processCreateCollectionConfig, processUpdateCollectionConfig, recordSetFields, registerEmbeddingFunction, serializeEmbeddingFunction, withChroma };
@@ -355,12 +355,10 @@ var J = (t = {}) => {
355
355
  };
356
356
 
357
357
  // src/api/client.gen.ts
358
- var client = J(
359
- w({
360
- baseUrl: "http://localhost:8000",
361
- throwOnError: true
362
- })
363
- );
358
+ var client = J(w({
359
+ baseUrl: "http://localhost:8000",
360
+ throwOnError: true
361
+ }));
364
362
 
365
363
  // src/api/sdk.gen.ts
366
364
  var DefaultService = class {
@@ -1110,10 +1108,7 @@ var packEmbedding = (embedding) => {
1110
1108
  }
1111
1109
  return buffer;
1112
1110
  };
1113
- var optionalEmbeddingsToBase64Bytes = (embeddings) => {
1114
- if (!embeddings) {
1115
- return void 0;
1116
- }
1111
+ var embeddingsToBase64Bytes = (embeddings) => {
1117
1112
  return embeddings.map((embedding) => {
1118
1113
  const buffer = packEmbedding(embedding);
1119
1114
  const uint8Array = new Uint8Array(buffer);
@@ -1334,9 +1329,9 @@ var CollectionImpl = class _CollectionImpl {
1334
1329
  }
1335
1330
  async prepareRecords({
1336
1331
  recordSet,
1337
- maxBatchSize,
1338
1332
  update = false
1339
1333
  }) {
1334
+ const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1340
1335
  validateRecordSetLengthConsistency(recordSet);
1341
1336
  validateIDs(recordSet.ids);
1342
1337
  validateBaseRecordSet({ recordSet, update });
@@ -1344,6 +1339,14 @@ var CollectionImpl = class _CollectionImpl {
1344
1339
  if (!recordSet.embeddings && recordSet.documents) {
1345
1340
  recordSet.embeddings = await this.embed(recordSet.documents);
1346
1341
  }
1342
+ const preparedRecordSet = { ...recordSet };
1343
+ const base64Supported = await this.chromaClient.supportsBase64Encoding();
1344
+ if (base64Supported && recordSet.embeddings) {
1345
+ preparedRecordSet.embeddings = embeddingsToBase64Bytes(
1346
+ recordSet.embeddings
1347
+ );
1348
+ }
1349
+ return preparedRecordSet;
1347
1350
  }
1348
1351
  validateGet(include, ids, where, whereDocument) {
1349
1352
  validateInclude({ include, exclude: ["distances"] });
@@ -1400,19 +1403,16 @@ var CollectionImpl = class _CollectionImpl {
1400
1403
  metadatas,
1401
1404
  uris
1402
1405
  };
1403
- const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1404
- await this.prepareRecords({ recordSet, maxBatchSize });
1405
- const supportsBase64Encoding = await this.chromaClient.supportsBase64Encoding();
1406
- const embeddingsBase64 = supportsBase64Encoding ? optionalEmbeddingsToBase64Bytes(recordSet.embeddings) : recordSet.embeddings;
1406
+ const preparedRecordSet = await this.prepareRecords({ recordSet });
1407
1407
  await DefaultService.collectionAdd({
1408
1408
  client: this.apiClient,
1409
1409
  path: await this.path(),
1410
1410
  body: {
1411
- ids: recordSet.ids,
1412
- embeddings: embeddingsBase64,
1413
- documents: recordSet.documents,
1414
- metadatas: recordSet.metadatas,
1415
- uris: recordSet.uris
1411
+ ids: preparedRecordSet.ids,
1412
+ embeddings: preparedRecordSet.embeddings,
1413
+ documents: preparedRecordSet.documents,
1414
+ metadatas: preparedRecordSet.metadatas,
1415
+ uris: preparedRecordSet.uris
1416
1416
  }
1417
1417
  });
1418
1418
  }
@@ -1561,19 +1561,19 @@ var CollectionImpl = class _CollectionImpl {
1561
1561
  metadatas,
1562
1562
  uris
1563
1563
  };
1564
- const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1565
- await this.prepareRecords({ recordSet, maxBatchSize, update: true });
1566
- const supportsBase64Encoding = await this.chromaClient.supportsBase64Encoding();
1567
- const embeddingsBase64 = supportsBase64Encoding ? optionalEmbeddingsToBase64Bytes(recordSet.embeddings) : recordSet.embeddings;
1564
+ const preparedRecordSet = await this.prepareRecords({
1565
+ recordSet,
1566
+ update: true
1567
+ });
1568
1568
  await DefaultService.collectionUpdate({
1569
1569
  client: this.apiClient,
1570
1570
  path: await this.path(),
1571
1571
  body: {
1572
- ids: recordSet.ids,
1573
- embeddings: embeddingsBase64,
1574
- metadatas: recordSet.metadatas,
1575
- uris: recordSet.uris,
1576
- documents: recordSet.documents
1572
+ ids: preparedRecordSet.ids,
1573
+ embeddings: preparedRecordSet.embeddings,
1574
+ metadatas: preparedRecordSet.metadatas,
1575
+ uris: preparedRecordSet.uris,
1576
+ documents: preparedRecordSet.documents
1577
1577
  }
1578
1578
  });
1579
1579
  }
@@ -1591,19 +1591,18 @@ var CollectionImpl = class _CollectionImpl {
1591
1591
  metadatas,
1592
1592
  uris
1593
1593
  };
1594
- const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1595
- await this.prepareRecords({ recordSet, maxBatchSize, update: true });
1596
- const supportsBase64Encoding = await this.chromaClient.supportsBase64Encoding();
1597
- const embeddingsBase64 = supportsBase64Encoding ? optionalEmbeddingsToBase64Bytes(recordSet.embeddings) : recordSet.embeddings;
1594
+ const preparedRecordSet = await this.prepareRecords({
1595
+ recordSet
1596
+ });
1598
1597
  await DefaultService.collectionUpsert({
1599
1598
  client: this.apiClient,
1600
1599
  path: await this.path(),
1601
1600
  body: {
1602
- ids: recordSet.ids,
1603
- embeddings: embeddingsBase64,
1604
- metadatas: recordSet.metadatas,
1605
- uris: recordSet.uris,
1606
- documents: recordSet.documents
1601
+ ids: preparedRecordSet.ids,
1602
+ embeddings: preparedRecordSet.embeddings,
1603
+ metadatas: preparedRecordSet.metadatas,
1604
+ uris: preparedRecordSet.uris,
1605
+ documents: preparedRecordSet.documents
1607
1606
  }
1608
1607
  });
1609
1608
  }
package/dist/chromadb.mjs CHANGED
@@ -355,12 +355,10 @@ var J = (t = {}) => {
355
355
  };
356
356
 
357
357
  // src/api/client.gen.ts
358
- var client = J(
359
- w({
360
- baseUrl: "http://localhost:8000",
361
- throwOnError: true
362
- })
363
- );
358
+ var client = J(w({
359
+ baseUrl: "http://localhost:8000",
360
+ throwOnError: true
361
+ }));
364
362
 
365
363
  // src/api/sdk.gen.ts
366
364
  var DefaultService = class {
@@ -1110,10 +1108,7 @@ var packEmbedding = (embedding) => {
1110
1108
  }
1111
1109
  return buffer;
1112
1110
  };
1113
- var optionalEmbeddingsToBase64Bytes = (embeddings) => {
1114
- if (!embeddings) {
1115
- return void 0;
1116
- }
1111
+ var embeddingsToBase64Bytes = (embeddings) => {
1117
1112
  return embeddings.map((embedding) => {
1118
1113
  const buffer = packEmbedding(embedding);
1119
1114
  const uint8Array = new Uint8Array(buffer);
@@ -1334,9 +1329,9 @@ var CollectionImpl = class _CollectionImpl {
1334
1329
  }
1335
1330
  async prepareRecords({
1336
1331
  recordSet,
1337
- maxBatchSize,
1338
1332
  update = false
1339
1333
  }) {
1334
+ const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1340
1335
  validateRecordSetLengthConsistency(recordSet);
1341
1336
  validateIDs(recordSet.ids);
1342
1337
  validateBaseRecordSet({ recordSet, update });
@@ -1344,6 +1339,14 @@ var CollectionImpl = class _CollectionImpl {
1344
1339
  if (!recordSet.embeddings && recordSet.documents) {
1345
1340
  recordSet.embeddings = await this.embed(recordSet.documents);
1346
1341
  }
1342
+ const preparedRecordSet = { ...recordSet };
1343
+ const base64Supported = await this.chromaClient.supportsBase64Encoding();
1344
+ if (base64Supported && recordSet.embeddings) {
1345
+ preparedRecordSet.embeddings = embeddingsToBase64Bytes(
1346
+ recordSet.embeddings
1347
+ );
1348
+ }
1349
+ return preparedRecordSet;
1347
1350
  }
1348
1351
  validateGet(include, ids, where, whereDocument) {
1349
1352
  validateInclude({ include, exclude: ["distances"] });
@@ -1400,19 +1403,16 @@ var CollectionImpl = class _CollectionImpl {
1400
1403
  metadatas,
1401
1404
  uris
1402
1405
  };
1403
- const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1404
- await this.prepareRecords({ recordSet, maxBatchSize });
1405
- const supportsBase64Encoding = await this.chromaClient.supportsBase64Encoding();
1406
- const embeddingsBase64 = supportsBase64Encoding ? optionalEmbeddingsToBase64Bytes(recordSet.embeddings) : recordSet.embeddings;
1406
+ const preparedRecordSet = await this.prepareRecords({ recordSet });
1407
1407
  await DefaultService.collectionAdd({
1408
1408
  client: this.apiClient,
1409
1409
  path: await this.path(),
1410
1410
  body: {
1411
- ids: recordSet.ids,
1412
- embeddings: embeddingsBase64,
1413
- documents: recordSet.documents,
1414
- metadatas: recordSet.metadatas,
1415
- uris: recordSet.uris
1411
+ ids: preparedRecordSet.ids,
1412
+ embeddings: preparedRecordSet.embeddings,
1413
+ documents: preparedRecordSet.documents,
1414
+ metadatas: preparedRecordSet.metadatas,
1415
+ uris: preparedRecordSet.uris
1416
1416
  }
1417
1417
  });
1418
1418
  }
@@ -1561,19 +1561,19 @@ var CollectionImpl = class _CollectionImpl {
1561
1561
  metadatas,
1562
1562
  uris
1563
1563
  };
1564
- const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1565
- await this.prepareRecords({ recordSet, maxBatchSize, update: true });
1566
- const supportsBase64Encoding = await this.chromaClient.supportsBase64Encoding();
1567
- const embeddingsBase64 = supportsBase64Encoding ? optionalEmbeddingsToBase64Bytes(recordSet.embeddings) : recordSet.embeddings;
1564
+ const preparedRecordSet = await this.prepareRecords({
1565
+ recordSet,
1566
+ update: true
1567
+ });
1568
1568
  await DefaultService.collectionUpdate({
1569
1569
  client: this.apiClient,
1570
1570
  path: await this.path(),
1571
1571
  body: {
1572
- ids: recordSet.ids,
1573
- embeddings: embeddingsBase64,
1574
- metadatas: recordSet.metadatas,
1575
- uris: recordSet.uris,
1576
- documents: recordSet.documents
1572
+ ids: preparedRecordSet.ids,
1573
+ embeddings: preparedRecordSet.embeddings,
1574
+ metadatas: preparedRecordSet.metadatas,
1575
+ uris: preparedRecordSet.uris,
1576
+ documents: preparedRecordSet.documents
1577
1577
  }
1578
1578
  });
1579
1579
  }
@@ -1591,19 +1591,18 @@ var CollectionImpl = class _CollectionImpl {
1591
1591
  metadatas,
1592
1592
  uris
1593
1593
  };
1594
- const maxBatchSize = await this.chromaClient.getMaxBatchSize();
1595
- await this.prepareRecords({ recordSet, maxBatchSize, update: true });
1596
- const supportsBase64Encoding = await this.chromaClient.supportsBase64Encoding();
1597
- const embeddingsBase64 = supportsBase64Encoding ? optionalEmbeddingsToBase64Bytes(recordSet.embeddings) : recordSet.embeddings;
1594
+ const preparedRecordSet = await this.prepareRecords({
1595
+ recordSet
1596
+ });
1598
1597
  await DefaultService.collectionUpsert({
1599
1598
  client: this.apiClient,
1600
1599
  path: await this.path(),
1601
1600
  body: {
1602
- ids: recordSet.ids,
1603
- embeddings: embeddingsBase64,
1604
- metadatas: recordSet.metadatas,
1605
- uris: recordSet.uris,
1606
- documents: recordSet.documents
1601
+ ids: preparedRecordSet.ids,
1602
+ embeddings: preparedRecordSet.embeddings,
1603
+ metadatas: preparedRecordSet.metadatas,
1604
+ uris: preparedRecordSet.uris,
1605
+ documents: preparedRecordSet.documents
1607
1606
  }
1608
1607
  });
1609
1608
  }