chromadb 3.3.0 → 3.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chromadb",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "A JavaScript interface for chroma",
5
5
  "keywords": [
6
6
  "chroma",
@@ -60,11 +60,11 @@
60
60
  "@chroma-core/default-embed": "^0.1.9"
61
61
  },
62
62
  "optionalDependencies": {
63
- "chromadb-js-bindings-darwin-arm64": "^1.3.0",
64
- "chromadb-js-bindings-darwin-x64": "^1.3.0",
65
- "chromadb-js-bindings-linux-arm64-gnu": "^1.3.0",
66
- "chromadb-js-bindings-linux-x64-gnu": "^1.3.0",
67
- "chromadb-js-bindings-win32-x64-msvc": "^1.3.0"
63
+ "chromadb-js-bindings-darwin-arm64": "^1.3.1",
64
+ "chromadb-js-bindings-darwin-x64": "^1.3.1",
65
+ "chromadb-js-bindings-linux-arm64-gnu": "^1.3.1",
66
+ "chromadb-js-bindings-linux-x64-gnu": "^1.3.1",
67
+ "chromadb-js-bindings-win32-x64-msvc": "^1.3.1"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=20"
@@ -436,6 +436,11 @@ export type Key = 'Document' | 'Embedding' | 'Metadata' | 'Score' | {
436
436
  MetadataField: string;
437
437
  };
438
438
 
439
+ /**
440
+ * Quantization implementation for SPANN vector index.
441
+ */
442
+ export type Quantization = 'none' | 'four_bit_rabit_q_with_u_search';
443
+
439
444
  export type QueryRequestPayload = RawWhereFields & {
440
445
  ids?: Array<string> | null;
441
446
  include?: IncludeList;
@@ -559,9 +564,9 @@ export type SpannIndexConfig = {
559
564
  num_centers_to_merge_to?: number | null;
560
565
  num_samples_kmeans?: number | null;
561
566
  /**
562
- * Enable quantization for vector search (cloud-only feature)
567
+ * Quantization implementation for vector search (cloud-only feature)
563
568
  */
564
- quantize?: boolean;
569
+ quantize?: Quantization;
565
570
  reassign_neighbor_count?: number | null;
566
571
  search_nprobe?: number | null;
567
572
  search_rng_epsilon?: number | null;
package/src/schema.ts CHANGED
@@ -251,72 +251,72 @@ export class SparseVectorIndexConfig {
251
251
  }
252
252
 
253
253
  export class FtsIndexType {
254
- constructor(public enabled: boolean, public config: FtsIndexConfig) {}
254
+ constructor(public enabled: boolean, public config: FtsIndexConfig) { }
255
255
  }
256
256
 
257
257
  export class StringInvertedIndexType {
258
258
  constructor(
259
259
  public enabled: boolean,
260
260
  public config: StringInvertedIndexConfig,
261
- ) {}
261
+ ) { }
262
262
  }
263
263
 
264
264
  export class VectorIndexType {
265
- constructor(public enabled: boolean, public config: VectorIndexConfig) {}
265
+ constructor(public enabled: boolean, public config: VectorIndexConfig) { }
266
266
  }
267
267
 
268
268
  export class SparseVectorIndexType {
269
269
  constructor(
270
270
  public enabled: boolean,
271
271
  public config: SparseVectorIndexConfig,
272
- ) {}
272
+ ) { }
273
273
  }
274
274
 
275
275
  export class IntInvertedIndexType {
276
- constructor(public enabled: boolean, public config: IntInvertedIndexConfig) {}
276
+ constructor(public enabled: boolean, public config: IntInvertedIndexConfig) { }
277
277
  }
278
278
 
279
279
  export class FloatInvertedIndexType {
280
280
  constructor(
281
281
  public enabled: boolean,
282
282
  public config: FloatInvertedIndexConfig,
283
- ) {}
283
+ ) { }
284
284
  }
285
285
 
286
286
  export class BoolInvertedIndexType {
287
287
  constructor(
288
288
  public enabled: boolean,
289
289
  public config: BoolInvertedIndexConfig,
290
- ) {}
290
+ ) { }
291
291
  }
292
292
 
293
293
  export class StringValueType {
294
294
  constructor(
295
295
  public ftsIndex: FtsIndexType | null = null,
296
296
  public stringInvertedIndex: StringInvertedIndexType | null = null,
297
- ) {}
297
+ ) { }
298
298
  }
299
299
 
300
300
  export class FloatListValueType {
301
- constructor(public vectorIndex: VectorIndexType | null = null) {}
301
+ constructor(public vectorIndex: VectorIndexType | null = null) { }
302
302
  }
303
303
 
304
304
  export class SparseVectorValueType {
305
- constructor(public sparseVectorIndex: SparseVectorIndexType | null = null) {}
305
+ constructor(public sparseVectorIndex: SparseVectorIndexType | null = null) { }
306
306
  }
307
307
 
308
308
  export class IntValueType {
309
- constructor(public intInvertedIndex: IntInvertedIndexType | null = null) {}
309
+ constructor(public intInvertedIndex: IntInvertedIndexType | null = null) { }
310
310
  }
311
311
 
312
312
  export class FloatValueType {
313
313
  constructor(
314
314
  public floatInvertedIndex: FloatInvertedIndexType | null = null,
315
- ) {}
315
+ ) { }
316
316
  }
317
317
 
318
318
  export class BoolValueType {
319
- constructor(public boolInvertedIndex: BoolInvertedIndexType | null = null) {}
319
+ constructor(public boolInvertedIndex: BoolInvertedIndexType | null = null) { }
320
320
  }
321
321
 
322
322
  export class ValueTypes {
@@ -351,11 +351,11 @@ const cloneObject = <T>(value: T): T => {
351
351
  return Array.isArray(value)
352
352
  ? (value.map((item) => cloneObject(item)) as T)
353
353
  : (Object.fromEntries(
354
- Object.entries(value as Record<string, unknown>).map(([k, v]) => [
355
- k,
356
- cloneObject(v),
357
- ]),
358
- ) as T);
354
+ Object.entries(value as Record<string, unknown>).map(([k, v]) => [
355
+ k,
356
+ cloneObject(v),
357
+ ]),
358
+ ) as T);
359
359
  };
360
360
 
361
361
  const resolveEmbeddingFunctionName = (
@@ -471,6 +471,7 @@ export class Schema {
471
471
  defaults: ValueTypes;
472
472
  keys: Record<string, ValueTypes>;
473
473
  cmek: Cmek | null;
474
+ private _rawJSON: Record<string, unknown> | null = null;
474
475
 
475
476
  constructor() {
476
477
  this.defaults = new ValueTypes();
@@ -480,6 +481,18 @@ export class Schema {
480
481
  this.initializeKeys();
481
482
  }
482
483
 
484
+ /**
485
+ * Returns the raw JSON schema as received from the server, or null if the
486
+ * schema was constructed client-side rather than deserialized from a server
487
+ * response.
488
+ */
489
+ get rawJSON(): Record<string, unknown> | null {
490
+ if (this._rawJSON === null) {
491
+ return null;
492
+ }
493
+ return structuredClone(this._rawJSON);
494
+ }
495
+
483
496
  /**
484
497
  * Set the customer-managed encryption key for this collection.
485
498
  *
@@ -512,35 +525,48 @@ export class Schema {
512
525
  );
513
526
  }
514
527
 
515
- if (keyProvided && key && (key === EMBEDDING_KEY || key === DOCUMENT_KEY)) {
528
+ // Disallow using special internal key #embedding
529
+ if (keyProvided && key && key === EMBEDDING_KEY) {
530
+ throw new Error(
531
+ `Cannot create index on special key '${key}'. This key is managed automatically by the system. Invoke createIndex(new VectorIndexConfig(...)) without specifying a key to configure the vector index globally.`,
532
+ );
533
+ }
534
+
535
+ // Only allow #document with FtsIndexConfig
536
+ if (keyProvided && key === DOCUMENT_KEY && !(config instanceof FtsIndexConfig)) {
516
537
  throw new Error(
517
- `Cannot create index on special key '${key}'. These keys are managed automatically by the system.`,
538
+ `Cannot create index on special key '${key}' with this config. Only FtsIndexConfig is allowed for #document.`,
518
539
  );
519
540
  }
520
541
 
542
+ // Disallow any key starting with # (except #document which allows FTS)
543
+ if (keyProvided && key && key.startsWith("#") && key !== DOCUMENT_KEY) {
544
+ throw new Error(
545
+ "key cannot begin with '#'. Keys starting with '#' are reserved for system use.",
546
+ );
547
+ }
548
+
549
+ // Special handling for vector index
521
550
  if (config instanceof VectorIndexConfig) {
522
551
  if (!keyProvided) {
523
552
  this.setVectorIndexConfig(config);
524
553
  return this;
525
554
  }
526
555
  throw new Error(
527
- "Vector index cannot be enabled on specific keys. Use createIndex(config=VectorIndexConfig(...)) without specifying a key to configure the vector index globally.",
556
+ "Vector index cannot be enabled on specific keys. Use createIndex(new VectorIndexConfig(...)) without specifying a key to configure the vector index globally.",
528
557
  );
529
558
  }
530
559
 
531
- if (config instanceof FtsIndexConfig) {
532
- if (!keyProvided) {
533
- this.setFtsIndexConfig(config);
534
- return this;
535
- }
560
+ // FTS index is only allowed on #document key
561
+ if (config instanceof FtsIndexConfig && (!keyProvided || key !== DOCUMENT_KEY)) {
536
562
  throw new Error(
537
- "FTS index cannot be enabled on specific keys. Use createIndex(config=FtsIndexConfig(...)) without specifying a key to configure the FTS index globally.",
563
+ "FTS index can only be enabled on #document key. Use createIndex(new FtsIndexConfig(), '#document')",
538
564
  );
539
565
  }
540
566
 
541
567
  if (config instanceof SparseVectorIndexConfig && !keyProvided) {
542
568
  throw new Error(
543
- "Sparse vector index must be created on a specific key. Please specify a key using: createIndex(config=SparseVectorIndexConfig(...), key='your_key')",
569
+ "Sparse vector index must be created on a specific key. Please specify a key using: createIndex(new SparseVectorIndexConfig(...), 'your_key')",
544
570
  );
545
571
  }
546
572
 
@@ -571,26 +597,45 @@ export class Schema {
571
597
  );
572
598
  }
573
599
 
574
- if (keyProvided && key && (key === EMBEDDING_KEY || key === DOCUMENT_KEY)) {
600
+ // Disallow using special internal key #embedding
601
+ if (keyProvided && key && key === EMBEDDING_KEY) {
575
602
  throw new Error(
576
- `Cannot delete index on special key '${key}'. These keys are managed automatically by the system.`,
603
+ "Cannot modify #embedding. Currently not supported",
577
604
  );
578
605
  }
579
606
 
580
- if (config instanceof VectorIndexConfig) {
581
- throw new Error("Deleting vector index is not currently supported.");
607
+ // Only allow #document with FtsIndexConfig (to disable FTS)
608
+ if (keyProvided && key === DOCUMENT_KEY && !(config instanceof FtsIndexConfig)) {
609
+ throw new Error(
610
+ `Cannot delete index on special key '${key}' with this config. Only FtsIndexConfig is allowed for #document.`,
611
+ );
582
612
  }
583
613
 
584
- if (config instanceof FtsIndexConfig) {
585
- throw new Error("Deleting FTS index is not currently supported.");
614
+ // Disallow any key starting with # (except #document which allows FTS deletion)
615
+ if (keyProvided && key && key.startsWith("#") && key !== DOCUMENT_KEY) {
616
+ throw new Error(
617
+ "key cannot begin with '#'. Keys starting with '#' are reserved for system use.",
618
+ );
586
619
  }
587
620
 
621
+ // TODO: Consider removing these checks in the future to allow disabling vector and sparse vector indexes
622
+ // Temporarily disallow deleting vector index (both globally and per-key)
623
+ if (config instanceof VectorIndexConfig) {
624
+ throw new Error("Deleting vector index is not currently supported.");
625
+ }
626
+
627
+ // Temporarily disallow deleting sparse vector index (both globally and per-key)
588
628
  if (config instanceof SparseVectorIndexConfig) {
589
629
  throw new Error(
590
630
  "Deleting sparse vector index is not currently supported.",
591
631
  );
592
632
  }
593
633
 
634
+ // FTS deletion is only allowed on #document key
635
+ if (config instanceof FtsIndexConfig && (!keyProvided || key !== DOCUMENT_KEY)) {
636
+ throw new Error("Deleting FTS index is only supported on #document key.");
637
+ }
638
+
594
639
  // TODO: Consider removing this check in the future to allow disabling all indexes for a key
595
640
  // Disallow disabling all index types for a key (config=undefined, key="some_key")
596
641
  if (keyProvided && !configProvided && key) {
@@ -639,6 +684,7 @@ export class Schema {
639
684
 
640
685
  const data = json as JsonDict;
641
686
  const instance = Object.create(Schema.prototype) as Schema;
687
+ instance._rawJSON = structuredClone(data) as Record<string, unknown>;
642
688
  instance.defaults = await Schema.deserializeValueTypes(
643
689
  (data.defaults ?? {}) as Record<string, any>,
644
690
  client,
@@ -700,26 +746,6 @@ export class Schema {
700
746
  );
701
747
  }
702
748
 
703
- private setFtsIndexConfig(config: FtsIndexConfig): void {
704
- const defaultsString = ensureStringValueType(this.defaults);
705
- const currentDefaultsFts =
706
- defaultsString.ftsIndex ?? new FtsIndexType(false, new FtsIndexConfig());
707
- defaultsString.ftsIndex = new FtsIndexType(
708
- currentDefaultsFts.enabled,
709
- config,
710
- );
711
-
712
- const documentValueTypes = ensureValueTypes(this.keys[DOCUMENT_KEY]);
713
- this.keys[DOCUMENT_KEY] = documentValueTypes;
714
- const overrideString = ensureStringValueType(documentValueTypes);
715
- const currentOverrideFts =
716
- overrideString.ftsIndex ?? new FtsIndexType(true, new FtsIndexConfig());
717
- overrideString.ftsIndex = new FtsIndexType(
718
- currentOverrideFts.enabled,
719
- config,
720
- );
721
- }
722
-
723
749
  private setIndexInDefaults(config: IndexConfig, enabled: boolean): void {
724
750
  if (config instanceof FtsIndexConfig) {
725
751
  const valueType = ensureStringValueType(this.defaults);
@@ -1075,8 +1101,7 @@ export class Schema {
1075
1101
  !embeddingFunction.supportedSpaces().includes(resolvedSpace)
1076
1102
  ) {
1077
1103
  console.warn(
1078
- `Space '${resolvedSpace}' is not supported by embedding function '${
1079
- resolveEmbeddingFunctionName(embeddingFunction) ?? "unknown"
1104
+ `Space '${resolvedSpace}' is not supported by embedding function '${resolveEmbeddingFunctionName(embeddingFunction) ?? "unknown"
1080
1105
  }'. Supported spaces: ${embeddingFunction
1081
1106
  .supportedSpaces()
1082
1107
  .join(", ")}`,