chromadb 3.1.4 → 3.1.6
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/dist/chromadb.d.ts +27 -12
- package/dist/chromadb.legacy-esm.js +172 -63
- package/dist/chromadb.mjs +172 -63
- package/dist/chromadb.mjs.map +1 -1
- package/dist/cjs/chromadb.cjs +172 -63
- package/dist/cjs/chromadb.cjs.map +1 -1
- package/dist/cjs/chromadb.d.cts +27 -12
- package/package.json +6 -6
- package/src/chroma-client.ts +78 -20
- package/src/chroma-fetch.ts +32 -16
- package/src/collection-configuration.ts +16 -8
- package/src/collection.ts +66 -30
- package/src/embedding-function.ts +33 -15
- package/src/schema.ts +54 -12
package/dist/chromadb.d.ts
CHANGED
|
@@ -579,7 +579,7 @@ interface EmbeddingFunction {
|
|
|
579
579
|
/** Returns all supported vector spaces for this embedding function */
|
|
580
580
|
supportedSpaces?(): EmbeddingFunctionSpace[];
|
|
581
581
|
/** Creates an instance from configuration object */
|
|
582
|
-
buildFromConfig?(config: Record<string, any
|
|
582
|
+
buildFromConfig?(config: Record<string, any>, client?: ChromaClient): EmbeddingFunction;
|
|
583
583
|
/** Returns the current configuration as an object */
|
|
584
584
|
getConfig?(): Record<string, any>;
|
|
585
585
|
/**
|
|
@@ -616,7 +616,7 @@ interface SparseEmbeddingFunction {
|
|
|
616
616
|
/** Optional name identifier for the embedding function */
|
|
617
617
|
name?: string;
|
|
618
618
|
/** Creates an instance from configuration object */
|
|
619
|
-
buildFromConfig?(config: Record<string, any
|
|
619
|
+
buildFromConfig?(config: Record<string, any>, client?: ChromaClient): SparseEmbeddingFunction;
|
|
620
620
|
/** Returns the current configuration as an object */
|
|
621
621
|
getConfig?(): Record<string, any>;
|
|
622
622
|
/**
|
|
@@ -640,7 +640,7 @@ interface EmbeddingFunctionClass {
|
|
|
640
640
|
/** Name identifier for the embedding function */
|
|
641
641
|
name: string;
|
|
642
642
|
/** Static method to build instance from configuration */
|
|
643
|
-
buildFromConfig(config: Record<string, any
|
|
643
|
+
buildFromConfig(config: Record<string, any>, client?: ChromaClient): EmbeddingFunction;
|
|
644
644
|
}
|
|
645
645
|
/**
|
|
646
646
|
* Interface for sparse embedding function constructor classes.
|
|
@@ -652,7 +652,7 @@ interface SparseEmbeddingFunctionClass {
|
|
|
652
652
|
/** Name identifier for the embedding function */
|
|
653
653
|
name: string;
|
|
654
654
|
/** Static method to build instance from configuration */
|
|
655
|
-
buildFromConfig(config: Record<string, any
|
|
655
|
+
buildFromConfig(config: Record<string, any>, client?: ChromaClient): SparseEmbeddingFunction;
|
|
656
656
|
}
|
|
657
657
|
/**
|
|
658
658
|
* Registry of available embedding functions.
|
|
@@ -684,18 +684,18 @@ declare const registerEmbeddingFunction: (name: string, fn: EmbeddingFunctionCla
|
|
|
684
684
|
declare const registerSparseEmbeddingFunction: (name: string, fn: SparseEmbeddingFunctionClass) => void;
|
|
685
685
|
/**
|
|
686
686
|
* Retrieves and instantiates an embedding function from configuration.
|
|
687
|
-
* @param collectionName - Name of the collection (for error messages)
|
|
688
|
-
* @param efConfig - Configuration for the embedding function
|
|
689
687
|
* @returns EmbeddingFunction instance or undefined if it cannot be constructed
|
|
690
688
|
*/
|
|
691
|
-
declare const getEmbeddingFunction: (
|
|
689
|
+
declare const getEmbeddingFunction: (args: {
|
|
690
|
+
collectionName: string;
|
|
691
|
+
client: ChromaClient;
|
|
692
|
+
efConfig?: EmbeddingFunctionConfiguration;
|
|
693
|
+
}) => Promise<EmbeddingFunction | undefined>;
|
|
692
694
|
/**
|
|
693
695
|
* Retrieves and instantiates a sparse embedding function from configuration.
|
|
694
|
-
* @param collectionName - Name of the collection (for error messages)
|
|
695
|
-
* @param efConfig - Configuration for the sparse embedding function
|
|
696
696
|
* @returns SparseEmbeddingFunction instance or undefined if it cannot be constructed
|
|
697
697
|
*/
|
|
698
|
-
declare const getSparseEmbeddingFunction: (collectionName: string, efConfig?: EmbeddingFunctionConfiguration) => Promise<SparseEmbeddingFunction | undefined>;
|
|
698
|
+
declare const getSparseEmbeddingFunction: (collectionName: string, client: ChromaClient, efConfig?: EmbeddingFunctionConfiguration) => Promise<SparseEmbeddingFunction | undefined>;
|
|
699
699
|
/**
|
|
700
700
|
* Serializes an embedding function to configuration format.
|
|
701
701
|
* @param embeddingFunction - User provided embedding function
|
|
@@ -1001,7 +1001,7 @@ declare class Schema {
|
|
|
1001
1001
|
createIndex(config?: IndexConfig, key?: string): this;
|
|
1002
1002
|
deleteIndex(config?: IndexConfig, key?: string): this;
|
|
1003
1003
|
serializeToJSON(): Schema$1;
|
|
1004
|
-
static deserializeFromJSON(json
|
|
1004
|
+
static deserializeFromJSON(json: Schema$1 | JsonDict | null, client: ChromaClient): Promise<Schema | undefined>;
|
|
1005
1005
|
private setVectorIndexConfig;
|
|
1006
1006
|
private setFtsIndexConfig;
|
|
1007
1007
|
private setIndexInDefaults;
|
|
@@ -1009,6 +1009,7 @@ declare class Schema {
|
|
|
1009
1009
|
private enableAllIndexesForKey;
|
|
1010
1010
|
private disableAllIndexesForKey;
|
|
1011
1011
|
private validateSingleSparseVectorIndex;
|
|
1012
|
+
private validateSparseVectorConfig;
|
|
1012
1013
|
private initializeDefaults;
|
|
1013
1014
|
private initializeKeys;
|
|
1014
1015
|
private serializeValueTypes;
|
|
@@ -1074,11 +1075,12 @@ declare const processCreateCollectionConfig: ({ configuration, embeddingFunction
|
|
|
1074
1075
|
/**
|
|
1075
1076
|
*
|
|
1076
1077
|
*/
|
|
1077
|
-
declare const processUpdateCollectionConfig: ({ collectionName, currentConfiguration, currentEmbeddingFunction, newConfiguration, }: {
|
|
1078
|
+
declare const processUpdateCollectionConfig: ({ collectionName, currentConfiguration, currentEmbeddingFunction, newConfiguration, client, }: {
|
|
1078
1079
|
collectionName: string;
|
|
1079
1080
|
currentConfiguration: CollectionConfiguration;
|
|
1080
1081
|
currentEmbeddingFunction?: EmbeddingFunction;
|
|
1081
1082
|
newConfiguration: UpdateCollectionConfiguration;
|
|
1083
|
+
client: ChromaClient;
|
|
1082
1084
|
}) => Promise<{
|
|
1083
1085
|
updateConfiguration?: UpdateCollectionConfiguration$1;
|
|
1084
1086
|
updateEmbeddingFunction?: EmbeddingFunction;
|
|
@@ -1115,6 +1117,7 @@ declare class ChromaClient {
|
|
|
1115
1117
|
private _tenant;
|
|
1116
1118
|
private _database;
|
|
1117
1119
|
private _preflightChecks;
|
|
1120
|
+
private _headers;
|
|
1118
1121
|
private readonly apiClient;
|
|
1119
1122
|
/**
|
|
1120
1123
|
* Creates a new ChromaClient instance.
|
|
@@ -1139,6 +1142,7 @@ declare class ChromaClient {
|
|
|
1139
1142
|
*/
|
|
1140
1143
|
get preflightChecks(): ChecklistResponse | undefined;
|
|
1141
1144
|
protected set preflightChecks(preflightChecks: ChecklistResponse | undefined);
|
|
1145
|
+
get headers(): Record<string, string> | undefined;
|
|
1142
1146
|
/** @ignore */
|
|
1143
1147
|
_path(): Promise<{
|
|
1144
1148
|
tenant: string;
|
|
@@ -1199,6 +1203,13 @@ declare class ChromaClient {
|
|
|
1199
1203
|
name: string;
|
|
1200
1204
|
embeddingFunction?: EmbeddingFunction;
|
|
1201
1205
|
}): Promise<Collection>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Retrieves an existing collection by its Chroma Resource Name (CRN).
|
|
1208
|
+
* @param crn - The Chroma Resource Name of the collection to retrieve
|
|
1209
|
+
* @returns Promise resolving to the Collection instance
|
|
1210
|
+
* @throws Error if the collection does not exist
|
|
1211
|
+
*/
|
|
1212
|
+
getCollectionByCrn(crn: string): Promise<Collection>;
|
|
1202
1213
|
/**
|
|
1203
1214
|
* Retrieves multiple collections by name.
|
|
1204
1215
|
* @param items - Array of collection names or objects with name and optional embedding function (should match the ones used to create the collections)
|
|
@@ -1265,6 +1276,10 @@ declare class ChromaClient {
|
|
|
1265
1276
|
* Provides methods for adding, querying, updating, and deleting records.
|
|
1266
1277
|
*/
|
|
1267
1278
|
interface Collection {
|
|
1279
|
+
/** Tenant name */
|
|
1280
|
+
tenant: string;
|
|
1281
|
+
/** Database name */
|
|
1282
|
+
database: string;
|
|
1268
1283
|
/** Unique identifier for the collection */
|
|
1269
1284
|
id: string;
|
|
1270
1285
|
/** Name of the collection */
|
|
@@ -1286,7 +1286,8 @@ var knownEmbeddingFunctions = /* @__PURE__ */ new Map();
|
|
|
1286
1286
|
var pythonEmbeddingFunctions = {
|
|
1287
1287
|
onnx_mini_lm_l6_v2: "default-embed",
|
|
1288
1288
|
default: "default-embed",
|
|
1289
|
-
together_ai: "together-ai"
|
|
1289
|
+
together_ai: "together-ai",
|
|
1290
|
+
sentence_transformer: "sentence-transformer"
|
|
1290
1291
|
};
|
|
1291
1292
|
var unsupportedEmbeddingFunctions = /* @__PURE__ */ new Set([
|
|
1292
1293
|
"amazon_bedrock",
|
|
@@ -1297,7 +1298,6 @@ var unsupportedEmbeddingFunctions = /* @__PURE__ */ new Set([
|
|
|
1297
1298
|
"instructor",
|
|
1298
1299
|
"open_clip",
|
|
1299
1300
|
"roboflow",
|
|
1300
|
-
"sentence_transformer",
|
|
1301
1301
|
"text2vec"
|
|
1302
1302
|
]);
|
|
1303
1303
|
var knownSparseEmbeddingFunctions = /* @__PURE__ */ new Map();
|
|
@@ -1325,7 +1325,8 @@ var registerSparseEmbeddingFunction = (name, fn) => {
|
|
|
1325
1325
|
}
|
|
1326
1326
|
knownSparseEmbeddingFunctions.set(name, fn);
|
|
1327
1327
|
};
|
|
1328
|
-
var getEmbeddingFunction = async (
|
|
1328
|
+
var getEmbeddingFunction = async (args) => {
|
|
1329
|
+
const { collectionName, client: client2, efConfig } = args;
|
|
1329
1330
|
if (!efConfig) {
|
|
1330
1331
|
console.warn(
|
|
1331
1332
|
`No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
@@ -1375,7 +1376,7 @@ var getEmbeddingFunction = async (collectionName, efConfig) => {
|
|
|
1375
1376
|
let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
|
|
1376
1377
|
try {
|
|
1377
1378
|
if (embeddingFunction.buildFromConfig) {
|
|
1378
|
-
return embeddingFunction.buildFromConfig(constructorConfig);
|
|
1379
|
+
return embeddingFunction.buildFromConfig(constructorConfig, client2);
|
|
1379
1380
|
}
|
|
1380
1381
|
console.warn(
|
|
1381
1382
|
`Embedding function ${packageName} does not define a 'buildFromConfig' function. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
@@ -1388,7 +1389,7 @@ var getEmbeddingFunction = async (collectionName, efConfig) => {
|
|
|
1388
1389
|
return void 0;
|
|
1389
1390
|
}
|
|
1390
1391
|
};
|
|
1391
|
-
var getSparseEmbeddingFunction = async (collectionName, efConfig) => {
|
|
1392
|
+
var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
|
|
1392
1393
|
if (!efConfig) {
|
|
1393
1394
|
return void 0;
|
|
1394
1395
|
}
|
|
@@ -1423,7 +1424,7 @@ var getSparseEmbeddingFunction = async (collectionName, efConfig) => {
|
|
|
1423
1424
|
let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
|
|
1424
1425
|
try {
|
|
1425
1426
|
if (sparseEmbeddingFunction.buildFromConfig) {
|
|
1426
|
-
return sparseEmbeddingFunction.buildFromConfig(constructorConfig);
|
|
1427
|
+
return sparseEmbeddingFunction.buildFromConfig(constructorConfig, client2);
|
|
1427
1428
|
}
|
|
1428
1429
|
console.warn(
|
|
1429
1430
|
`Sparse embedding function ${packageName} does not define a 'buildFromConfig' function.`
|
|
@@ -1544,7 +1545,8 @@ var processUpdateCollectionConfig = async ({
|
|
|
1544
1545
|
collectionName,
|
|
1545
1546
|
currentConfiguration,
|
|
1546
1547
|
currentEmbeddingFunction,
|
|
1547
|
-
newConfiguration
|
|
1548
|
+
newConfiguration,
|
|
1549
|
+
client: client2
|
|
1548
1550
|
}) => {
|
|
1549
1551
|
if (newConfiguration.hnsw && typeof newConfiguration.hnsw !== "object") {
|
|
1550
1552
|
throw new ChromaValueError(
|
|
@@ -1556,10 +1558,11 @@ var processUpdateCollectionConfig = async ({
|
|
|
1556
1558
|
"Invalid SPANN config provided in UpdateCollectionConfiguration"
|
|
1557
1559
|
);
|
|
1558
1560
|
}
|
|
1559
|
-
const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction(
|
|
1561
|
+
const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction({
|
|
1560
1562
|
collectionName,
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
+
client: client2,
|
|
1564
|
+
efConfig: currentConfiguration.embeddingFunction ?? void 0
|
|
1565
|
+
});
|
|
1563
1566
|
const newEmbeddingFunction = newConfiguration.embeddingFunction;
|
|
1564
1567
|
if (embeddingFunction && embeddingFunction.validateConfigUpdate && newEmbeddingFunction && newEmbeddingFunction.getConfig) {
|
|
1565
1568
|
embeddingFunction.validateConfigUpdate(newEmbeddingFunction.getConfig());
|
|
@@ -2754,8 +2757,9 @@ var Schema = class _Schema {
|
|
|
2754
2757
|
);
|
|
2755
2758
|
}
|
|
2756
2759
|
if (!configProvided && keyProvided && key) {
|
|
2757
|
-
|
|
2758
|
-
|
|
2760
|
+
throw new Error(
|
|
2761
|
+
`Cannot enable all index types for key '${key}'. Please specify a specific index configuration.`
|
|
2762
|
+
);
|
|
2759
2763
|
}
|
|
2760
2764
|
if (configProvided && !keyProvided) {
|
|
2761
2765
|
this.setIndexInDefaults(config, true);
|
|
@@ -2789,8 +2793,9 @@ var Schema = class _Schema {
|
|
|
2789
2793
|
);
|
|
2790
2794
|
}
|
|
2791
2795
|
if (keyProvided && !configProvided && key) {
|
|
2792
|
-
|
|
2793
|
-
|
|
2796
|
+
throw new Error(
|
|
2797
|
+
`Cannot disable all index types for key '${key}'. Please specify a specific index configuration.`
|
|
2798
|
+
);
|
|
2794
2799
|
}
|
|
2795
2800
|
if (keyProvided && configProvided && key) {
|
|
2796
2801
|
this.setIndexForKey(key, config, false);
|
|
@@ -2810,19 +2815,23 @@ var Schema = class _Schema {
|
|
|
2810
2815
|
keys
|
|
2811
2816
|
};
|
|
2812
2817
|
}
|
|
2813
|
-
static async deserializeFromJSON(json) {
|
|
2818
|
+
static async deserializeFromJSON(json, client2) {
|
|
2814
2819
|
if (json == null) {
|
|
2815
2820
|
return void 0;
|
|
2816
2821
|
}
|
|
2817
2822
|
const data = json;
|
|
2818
2823
|
const instance = Object.create(_Schema.prototype);
|
|
2819
2824
|
instance.defaults = await _Schema.deserializeValueTypes(
|
|
2820
|
-
data.defaults ?? {}
|
|
2825
|
+
data.defaults ?? {},
|
|
2826
|
+
client2
|
|
2821
2827
|
);
|
|
2822
2828
|
instance.keys = {};
|
|
2823
2829
|
const keys = data.keys ?? {};
|
|
2824
2830
|
for (const [keyName, value] of Object.entries(keys)) {
|
|
2825
|
-
instance.keys[keyName] = await _Schema.deserializeValueTypes(
|
|
2831
|
+
instance.keys[keyName] = await _Schema.deserializeValueTypes(
|
|
2832
|
+
value,
|
|
2833
|
+
client2
|
|
2834
|
+
);
|
|
2826
2835
|
}
|
|
2827
2836
|
return instance;
|
|
2828
2837
|
}
|
|
@@ -2907,6 +2916,7 @@ var Schema = class _Schema {
|
|
|
2907
2916
|
setIndexForKey(key, config, enabled) {
|
|
2908
2917
|
if (config instanceof SparseVectorIndexConfig && enabled) {
|
|
2909
2918
|
this.validateSingleSparseVectorIndex(key);
|
|
2919
|
+
this.validateSparseVectorConfig(config);
|
|
2910
2920
|
}
|
|
2911
2921
|
const current = this.keys[key] = ensureValueTypes(this.keys[key]);
|
|
2912
2922
|
if (config instanceof StringInvertedIndexConfig) {
|
|
@@ -2953,7 +2963,7 @@ var Schema = class _Schema {
|
|
|
2953
2963
|
new VectorIndexType(true, new VectorIndexConfig())
|
|
2954
2964
|
);
|
|
2955
2965
|
current.sparseVector = new SparseVectorValueType(
|
|
2956
|
-
new SparseVectorIndexType(
|
|
2966
|
+
new SparseVectorIndexType(false, new SparseVectorIndexConfig())
|
|
2957
2967
|
);
|
|
2958
2968
|
current.intValue = new IntValueType(
|
|
2959
2969
|
new IntInvertedIndexType(true, new IntInvertedIndexConfig())
|
|
@@ -3003,6 +3013,13 @@ var Schema = class _Schema {
|
|
|
3003
3013
|
}
|
|
3004
3014
|
}
|
|
3005
3015
|
}
|
|
3016
|
+
validateSparseVectorConfig(config) {
|
|
3017
|
+
if (config.sourceKey !== null && config.sourceKey !== void 0 && !config.embeddingFunction) {
|
|
3018
|
+
throw new Error(
|
|
3019
|
+
`If sourceKey is provided then embeddingFunction must also be provided since there is no default embedding function. Config: ${JSON.stringify(config)}`
|
|
3020
|
+
);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3006
3023
|
initializeDefaults() {
|
|
3007
3024
|
this.defaults.string = new StringValueType(
|
|
3008
3025
|
new FtsIndexType(false, new FtsIndexConfig()),
|
|
@@ -3195,7 +3212,7 @@ var Schema = class _Schema {
|
|
|
3195
3212
|
}
|
|
3196
3213
|
return serialized;
|
|
3197
3214
|
}
|
|
3198
|
-
static async deserializeValueTypes(json) {
|
|
3215
|
+
static async deserializeValueTypes(json, client2) {
|
|
3199
3216
|
const result = new ValueTypes();
|
|
3200
3217
|
if (json[STRING_VALUE_NAME]) {
|
|
3201
3218
|
result.string = _Schema.deserializeStringValueType(
|
|
@@ -3204,12 +3221,14 @@ var Schema = class _Schema {
|
|
|
3204
3221
|
}
|
|
3205
3222
|
if (json[FLOAT_LIST_VALUE_NAME]) {
|
|
3206
3223
|
result.floatList = await _Schema.deserializeFloatListValueType(
|
|
3207
|
-
json[FLOAT_LIST_VALUE_NAME]
|
|
3224
|
+
json[FLOAT_LIST_VALUE_NAME],
|
|
3225
|
+
client2
|
|
3208
3226
|
);
|
|
3209
3227
|
}
|
|
3210
3228
|
if (json[SPARSE_VECTOR_VALUE_NAME]) {
|
|
3211
3229
|
result.sparseVector = await _Schema.deserializeSparseVectorValueType(
|
|
3212
|
-
json[SPARSE_VECTOR_VALUE_NAME]
|
|
3230
|
+
json[SPARSE_VECTOR_VALUE_NAME],
|
|
3231
|
+
client2
|
|
3213
3232
|
);
|
|
3214
3233
|
}
|
|
3215
3234
|
if (json[INT_VALUE_NAME]) {
|
|
@@ -3241,23 +3260,27 @@ var Schema = class _Schema {
|
|
|
3241
3260
|
}
|
|
3242
3261
|
return new StringValueType(ftsIndex, stringIndex);
|
|
3243
3262
|
}
|
|
3244
|
-
static async deserializeFloatListValueType(json) {
|
|
3263
|
+
static async deserializeFloatListValueType(json, client2) {
|
|
3245
3264
|
let vectorIndex = null;
|
|
3246
3265
|
if (json[VECTOR_INDEX_NAME]) {
|
|
3247
3266
|
const data = json[VECTOR_INDEX_NAME];
|
|
3248
3267
|
const enabled = Boolean(data.enabled);
|
|
3249
|
-
const config = await _Schema.deserializeVectorConfig(
|
|
3268
|
+
const config = await _Schema.deserializeVectorConfig(
|
|
3269
|
+
data.config ?? {},
|
|
3270
|
+
client2
|
|
3271
|
+
);
|
|
3250
3272
|
vectorIndex = new VectorIndexType(enabled, config);
|
|
3251
3273
|
}
|
|
3252
3274
|
return new FloatListValueType(vectorIndex);
|
|
3253
3275
|
}
|
|
3254
|
-
static async deserializeSparseVectorValueType(json) {
|
|
3276
|
+
static async deserializeSparseVectorValueType(json, client2) {
|
|
3255
3277
|
let sparseIndex = null;
|
|
3256
3278
|
if (json[SPARSE_VECTOR_INDEX_NAME]) {
|
|
3257
3279
|
const data = json[SPARSE_VECTOR_INDEX_NAME];
|
|
3258
3280
|
const enabled = Boolean(data.enabled);
|
|
3259
3281
|
const config = await _Schema.deserializeSparseVectorConfig(
|
|
3260
|
-
data.config ?? {}
|
|
3282
|
+
data.config ?? {},
|
|
3283
|
+
client2
|
|
3261
3284
|
);
|
|
3262
3285
|
sparseIndex = new SparseVectorIndexType(enabled, config);
|
|
3263
3286
|
}
|
|
@@ -3296,29 +3319,31 @@ var Schema = class _Schema {
|
|
|
3296
3319
|
}
|
|
3297
3320
|
return new BoolValueType(index);
|
|
3298
3321
|
}
|
|
3299
|
-
static async deserializeVectorConfig(json) {
|
|
3322
|
+
static async deserializeVectorConfig(json, client2) {
|
|
3300
3323
|
const config = new VectorIndexConfig({
|
|
3301
3324
|
space: json.space ?? null,
|
|
3302
3325
|
sourceKey: json.source_key ?? null,
|
|
3303
3326
|
hnsw: json.hnsw ? cloneObject(json.hnsw) : null,
|
|
3304
3327
|
spann: json.spann ? cloneObject(json.spann) : null
|
|
3305
3328
|
});
|
|
3306
|
-
config.embeddingFunction = await getEmbeddingFunction(
|
|
3307
|
-
"schema deserialization",
|
|
3308
|
-
|
|
3309
|
-
|
|
3329
|
+
config.embeddingFunction = await getEmbeddingFunction({
|
|
3330
|
+
collectionName: "schema deserialization",
|
|
3331
|
+
client: client2,
|
|
3332
|
+
efConfig: json.embedding_function
|
|
3333
|
+
});
|
|
3310
3334
|
if (!config.space && config.embeddingFunction?.defaultSpace) {
|
|
3311
3335
|
config.space = config.embeddingFunction.defaultSpace();
|
|
3312
3336
|
}
|
|
3313
3337
|
return config;
|
|
3314
3338
|
}
|
|
3315
|
-
static async deserializeSparseVectorConfig(json) {
|
|
3339
|
+
static async deserializeSparseVectorConfig(json, client2) {
|
|
3316
3340
|
const config = new SparseVectorIndexConfig({
|
|
3317
3341
|
sourceKey: json.source_key ?? null,
|
|
3318
3342
|
bm25: typeof json.bm25 === "boolean" ? json.bm25 : null
|
|
3319
3343
|
});
|
|
3320
3344
|
const embeddingFunction = await getSparseEmbeddingFunction(
|
|
3321
3345
|
"schema deserialization",
|
|
3346
|
+
client2,
|
|
3322
3347
|
json.embedding_function
|
|
3323
3348
|
) ?? config.embeddingFunction ?? void 0;
|
|
3324
3349
|
config.embeddingFunction = embeddingFunction ?? null;
|
|
@@ -3343,6 +3368,8 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3343
3368
|
chromaClient,
|
|
3344
3369
|
apiClient,
|
|
3345
3370
|
id,
|
|
3371
|
+
tenant,
|
|
3372
|
+
database,
|
|
3346
3373
|
name,
|
|
3347
3374
|
metadata,
|
|
3348
3375
|
configuration,
|
|
@@ -3352,6 +3379,8 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3352
3379
|
this.chromaClient = chromaClient;
|
|
3353
3380
|
this.apiClient = apiClient;
|
|
3354
3381
|
this.id = id;
|
|
3382
|
+
this.tenant = tenant;
|
|
3383
|
+
this.database = database;
|
|
3355
3384
|
this._name = name;
|
|
3356
3385
|
this._metadata = metadata;
|
|
3357
3386
|
this._configuration = configuration;
|
|
@@ -3389,9 +3418,9 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3389
3418
|
this._schema = schema;
|
|
3390
3419
|
}
|
|
3391
3420
|
async path() {
|
|
3392
|
-
const clientPath = await this.chromaClient._path();
|
|
3393
3421
|
return {
|
|
3394
|
-
|
|
3422
|
+
tenant: this.tenant,
|
|
3423
|
+
database: this.database,
|
|
3395
3424
|
collection_id: this.id
|
|
3396
3425
|
};
|
|
3397
3426
|
}
|
|
@@ -3469,7 +3498,11 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3469
3498
|
if (inputs.length === 0) {
|
|
3470
3499
|
continue;
|
|
3471
3500
|
}
|
|
3472
|
-
const sparseEmbeddings2 = await this.sparseEmbed(
|
|
3501
|
+
const sparseEmbeddings2 = await this.sparseEmbed(
|
|
3502
|
+
embeddingFunction,
|
|
3503
|
+
inputs,
|
|
3504
|
+
false
|
|
3505
|
+
);
|
|
3473
3506
|
if (sparseEmbeddings2.length !== positions.length) {
|
|
3474
3507
|
throw new ChromaValueError(
|
|
3475
3508
|
"Sparse embedding function returned unexpected number of embeddings."
|
|
@@ -3494,7 +3527,11 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3494
3527
|
if (inputs.length === 0) {
|
|
3495
3528
|
continue;
|
|
3496
3529
|
}
|
|
3497
|
-
const sparseEmbeddings = await this.sparseEmbed(
|
|
3530
|
+
const sparseEmbeddings = await this.sparseEmbed(
|
|
3531
|
+
embeddingFunction,
|
|
3532
|
+
inputs,
|
|
3533
|
+
false
|
|
3534
|
+
);
|
|
3498
3535
|
if (sparseEmbeddings.length !== positions.length) {
|
|
3499
3536
|
throw new ChromaValueError(
|
|
3500
3537
|
"Sparse embedding function returned unexpected number of embeddings."
|
|
@@ -3791,7 +3828,9 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3791
3828
|
async search(searches) {
|
|
3792
3829
|
const items = Array.isArray(searches) ? searches : [searches];
|
|
3793
3830
|
if (items.length === 0) {
|
|
3794
|
-
throw new ChromaValueError(
|
|
3831
|
+
throw new ChromaValueError(
|
|
3832
|
+
"At least one search payload must be provided."
|
|
3833
|
+
);
|
|
3795
3834
|
}
|
|
3796
3835
|
const payloads = await Promise.all(
|
|
3797
3836
|
items.map(async (search) => {
|
|
@@ -3820,7 +3859,8 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3820
3859
|
collectionName: this.name,
|
|
3821
3860
|
currentConfiguration: this.configuration,
|
|
3822
3861
|
newConfiguration: configuration,
|
|
3823
|
-
currentEmbeddingFunction: this.embeddingFunction
|
|
3862
|
+
currentEmbeddingFunction: this.embeddingFunction,
|
|
3863
|
+
client: this.chromaClient
|
|
3824
3864
|
}) : {};
|
|
3825
3865
|
if (updateEmbeddingFunction) {
|
|
3826
3866
|
this.embeddingFunction = updateEmbeddingFunction;
|
|
@@ -3852,6 +3892,8 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3852
3892
|
chromaClient: this.chromaClient,
|
|
3853
3893
|
apiClient: this.apiClient,
|
|
3854
3894
|
name: data.name,
|
|
3895
|
+
tenant: this.tenant,
|
|
3896
|
+
database: this.database,
|
|
3855
3897
|
id: data.id,
|
|
3856
3898
|
embeddingFunction: this._embeddingFunction,
|
|
3857
3899
|
metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
|
|
@@ -3965,6 +4007,14 @@ var offlineError = (error) => {
|
|
|
3965
4007
|
(error?.name === "TypeError" || error?.name === "FetchError") && (error.message?.includes("fetch failed") || error.message?.includes("Failed to fetch") || error.message?.includes("ENOTFOUND"))
|
|
3966
4008
|
);
|
|
3967
4009
|
};
|
|
4010
|
+
var getErrorMessage = async (response) => {
|
|
4011
|
+
try {
|
|
4012
|
+
const body = await response.clone().json();
|
|
4013
|
+
return body.message || body.error || `${response.status}: ${response.statusText}`;
|
|
4014
|
+
} catch {
|
|
4015
|
+
return `${response.status}: ${response.statusText}`;
|
|
4016
|
+
}
|
|
4017
|
+
};
|
|
3968
4018
|
var chromaFetch = async (input, init) => {
|
|
3969
4019
|
let response;
|
|
3970
4020
|
try {
|
|
@@ -4004,15 +4054,23 @@ var chromaFetch = async (input, init) => {
|
|
|
4004
4054
|
case 409:
|
|
4005
4055
|
throw new ChromaUniqueError("The resource already exists");
|
|
4006
4056
|
case 422:
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4057
|
+
try {
|
|
4058
|
+
const body = await response.json();
|
|
4059
|
+
if (body && body.message && (body.message.startsWith("Quota exceeded") || body.message.startsWith("Billing limit exceeded"))) {
|
|
4060
|
+
throw new ChromaQuotaExceededError(body?.message);
|
|
4061
|
+
}
|
|
4062
|
+
throw new ChromaClientError(body?.message || "Unprocessable Entity");
|
|
4063
|
+
} catch (error) {
|
|
4064
|
+
if (error instanceof ChromaQuotaExceededError || error instanceof ChromaClientError) {
|
|
4065
|
+
throw error;
|
|
4066
|
+
}
|
|
4067
|
+
throw new ChromaClientError(`Unprocessable Entity: ${response.statusText}`);
|
|
4010
4068
|
}
|
|
4011
|
-
break;
|
|
4012
4069
|
case 429:
|
|
4013
4070
|
throw new ChromaRateLimitError("Rate limit exceeded");
|
|
4014
4071
|
}
|
|
4015
|
-
|
|
4072
|
+
const errorMessage = await getErrorMessage(response);
|
|
4073
|
+
throw new ChromaServerError(errorMessage);
|
|
4016
4074
|
};
|
|
4017
4075
|
|
|
4018
4076
|
// src/admin-client.ts
|
|
@@ -4172,6 +4230,7 @@ var ChromaClient = class {
|
|
|
4172
4230
|
const baseUrl = `${ssl ? "https" : "http"}://${host}:${port}`;
|
|
4173
4231
|
this._tenant = tenant || process.env.CHROMA_TENANT;
|
|
4174
4232
|
this._database = database || process.env.CHROMA_DATABASE;
|
|
4233
|
+
this._headers = headers;
|
|
4175
4234
|
const configOptions = {
|
|
4176
4235
|
...fetchOptions,
|
|
4177
4236
|
method: normalizeMethod(fetchOptions?.method),
|
|
@@ -4211,6 +4270,9 @@ var ChromaClient = class {
|
|
|
4211
4270
|
set preflightChecks(preflightChecks) {
|
|
4212
4271
|
this._preflightChecks = preflightChecks;
|
|
4213
4272
|
}
|
|
4273
|
+
get headers() {
|
|
4274
|
+
return this._headers;
|
|
4275
|
+
}
|
|
4214
4276
|
/** @ignore */
|
|
4215
4277
|
async _path() {
|
|
4216
4278
|
if (!this._tenant || !this._database) {
|
|
@@ -4268,16 +4330,20 @@ var ChromaClient = class {
|
|
|
4268
4330
|
return Promise.all(
|
|
4269
4331
|
data.map(async (collection) => {
|
|
4270
4332
|
const schema = await Schema.deserializeFromJSON(
|
|
4271
|
-
collection.schema ??
|
|
4333
|
+
collection.schema ?? null,
|
|
4334
|
+
this
|
|
4272
4335
|
);
|
|
4273
4336
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
|
|
4274
|
-
const resolvedEmbeddingFunction = await getEmbeddingFunction(
|
|
4275
|
-
collection.name,
|
|
4276
|
-
|
|
4277
|
-
|
|
4337
|
+
const resolvedEmbeddingFunction = await getEmbeddingFunction({
|
|
4338
|
+
collectionName: collection.name,
|
|
4339
|
+
client: this,
|
|
4340
|
+
efConfig: collection.configuration_json.embedding_function ?? void 0
|
|
4341
|
+
}) ?? schemaEmbeddingFunction;
|
|
4278
4342
|
return new CollectionImpl({
|
|
4279
4343
|
chromaClient: this,
|
|
4280
4344
|
apiClient: this.apiClient,
|
|
4345
|
+
tenant: collection.tenant,
|
|
4346
|
+
database: collection.database,
|
|
4281
4347
|
name: collection.name,
|
|
4282
4348
|
id: collection.id,
|
|
4283
4349
|
embeddingFunction: resolvedEmbeddingFunction,
|
|
@@ -4334,17 +4400,21 @@ var ChromaClient = class {
|
|
|
4334
4400
|
}
|
|
4335
4401
|
});
|
|
4336
4402
|
const serverSchema = await Schema.deserializeFromJSON(
|
|
4337
|
-
data.schema ??
|
|
4403
|
+
data.schema ?? null,
|
|
4404
|
+
this
|
|
4338
4405
|
);
|
|
4339
4406
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
|
|
4340
|
-
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction(
|
|
4341
|
-
data.name,
|
|
4342
|
-
|
|
4343
|
-
|
|
4407
|
+
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
|
|
4408
|
+
collectionName: data.name,
|
|
4409
|
+
client: this,
|
|
4410
|
+
efConfig: data.configuration_json.embedding_function ?? void 0
|
|
4411
|
+
}) ?? schemaEmbeddingFunction;
|
|
4344
4412
|
return new CollectionImpl({
|
|
4345
4413
|
chromaClient: this,
|
|
4346
4414
|
apiClient: this.apiClient,
|
|
4347
4415
|
name,
|
|
4416
|
+
tenant: data.tenant,
|
|
4417
|
+
database: data.database,
|
|
4348
4418
|
configuration: data.configuration_json,
|
|
4349
4419
|
metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
|
|
4350
4420
|
embeddingFunction: resolvedEmbeddingFunction,
|
|
@@ -4368,16 +4438,50 @@ var ChromaClient = class {
|
|
|
4368
4438
|
client: this.apiClient,
|
|
4369
4439
|
path: { ...await this._path(), collection_id: name }
|
|
4370
4440
|
});
|
|
4371
|
-
const schema = await Schema.deserializeFromJSON(data.schema ??
|
|
4441
|
+
const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
|
|
4372
4442
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
|
|
4373
|
-
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction(
|
|
4374
|
-
data.name,
|
|
4375
|
-
|
|
4376
|
-
|
|
4443
|
+
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
|
|
4444
|
+
collectionName: data.name,
|
|
4445
|
+
client: this,
|
|
4446
|
+
efConfig: data.configuration_json.embedding_function ?? void 0
|
|
4447
|
+
}) ?? schemaEmbeddingFunction;
|
|
4377
4448
|
return new CollectionImpl({
|
|
4378
4449
|
chromaClient: this,
|
|
4379
4450
|
apiClient: this.apiClient,
|
|
4380
4451
|
name,
|
|
4452
|
+
tenant: data.tenant,
|
|
4453
|
+
database: data.database,
|
|
4454
|
+
configuration: data.configuration_json,
|
|
4455
|
+
metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
|
|
4456
|
+
embeddingFunction: resolvedEmbeddingFunction,
|
|
4457
|
+
id: data.id,
|
|
4458
|
+
schema
|
|
4459
|
+
});
|
|
4460
|
+
}
|
|
4461
|
+
/**
|
|
4462
|
+
* Retrieves an existing collection by its Chroma Resource Name (CRN).
|
|
4463
|
+
* @param crn - The Chroma Resource Name of the collection to retrieve
|
|
4464
|
+
* @returns Promise resolving to the Collection instance
|
|
4465
|
+
* @throws Error if the collection does not exist
|
|
4466
|
+
*/
|
|
4467
|
+
async getCollectionByCrn(crn) {
|
|
4468
|
+
const { data } = await DefaultService.getCollectionByCrn({
|
|
4469
|
+
client: this.apiClient,
|
|
4470
|
+
path: { crn }
|
|
4471
|
+
});
|
|
4472
|
+
const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
|
|
4473
|
+
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
|
|
4474
|
+
const resolvedEmbeddingFunction = await getEmbeddingFunction({
|
|
4475
|
+
collectionName: data.name,
|
|
4476
|
+
efConfig: data.configuration_json.embedding_function ?? void 0,
|
|
4477
|
+
client: this
|
|
4478
|
+
}) ?? schemaEmbeddingFunction;
|
|
4479
|
+
return new CollectionImpl({
|
|
4480
|
+
chromaClient: this,
|
|
4481
|
+
apiClient: this.apiClient,
|
|
4482
|
+
name: data.name,
|
|
4483
|
+
tenant: data.tenant,
|
|
4484
|
+
database: data.database,
|
|
4381
4485
|
configuration: data.configuration_json,
|
|
4382
4486
|
metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
|
|
4383
4487
|
embeddingFunction: resolvedEmbeddingFunction,
|
|
@@ -4424,7 +4528,8 @@ var ChromaClient = class {
|
|
|
4424
4528
|
const collectionConfig = await processCreateCollectionConfig({
|
|
4425
4529
|
configuration,
|
|
4426
4530
|
embeddingFunction,
|
|
4427
|
-
metadata
|
|
4531
|
+
metadata,
|
|
4532
|
+
schema
|
|
4428
4533
|
});
|
|
4429
4534
|
const { data } = await DefaultService.createCollection({
|
|
4430
4535
|
client: this.apiClient,
|
|
@@ -4438,17 +4543,21 @@ var ChromaClient = class {
|
|
|
4438
4543
|
}
|
|
4439
4544
|
});
|
|
4440
4545
|
const serverSchema = await Schema.deserializeFromJSON(
|
|
4441
|
-
data.schema ??
|
|
4546
|
+
data.schema ?? null,
|
|
4547
|
+
this
|
|
4442
4548
|
);
|
|
4443
4549
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
|
|
4444
|
-
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction(
|
|
4445
|
-
name,
|
|
4446
|
-
data.configuration_json.embedding_function ?? void 0
|
|
4447
|
-
|
|
4550
|
+
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
|
|
4551
|
+
collectionName: name,
|
|
4552
|
+
efConfig: data.configuration_json.embedding_function ?? void 0,
|
|
4553
|
+
client: this
|
|
4554
|
+
}) ?? schemaEmbeddingFunction;
|
|
4448
4555
|
return new CollectionImpl({
|
|
4449
4556
|
chromaClient: this,
|
|
4450
4557
|
apiClient: this.apiClient,
|
|
4451
4558
|
name,
|
|
4559
|
+
tenant: data.tenant,
|
|
4560
|
+
database: data.database,
|
|
4452
4561
|
configuration: data.configuration_json,
|
|
4453
4562
|
metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
|
|
4454
4563
|
embeddingFunction: resolvedEmbeddingFunction,
|