Skip to content

Commit d9d779f

Browse files
authored
[BUG] Allow SparseVector values in metadata for JS (#5456)
Adding validation for `SparseVector` metadata values in the JS client
1 parent 8851e98 commit d9d779f

File tree

1 file changed

+16
-2
lines changed
  • clients/new-js/packages/chromadb/src

1 file changed

+16
-2
lines changed

clients/new-js/packages/chromadb/src/utils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ export const validateIDs = (ids: string[]) => {
227227
}
228228
};
229229

230+
export const validateSparseVector = (v: any) => {
231+
return (
232+
typeof v === "object" &&
233+
v !== null &&
234+
"indices" in v &&
235+
"values" in v &&
236+
Array.isArray(v.indices) &&
237+
v.indices.every((e: any) => typeof e === "number") &&
238+
Array.isArray(v.values) &&
239+
v.values.every((e: any) => typeof e === "number")
240+
);
241+
};
242+
230243
/**
231244
* Validates metadata object for correct types and non-emptiness.
232245
* @param metadata - Metadata object to validate
@@ -248,11 +261,12 @@ export const validateMetadata = (metadata?: Metadata) => {
248261
v === undefined ||
249262
typeof v === "string" ||
250263
typeof v === "number" ||
251-
typeof v === "boolean",
264+
typeof v === "boolean" ||
265+
validateSparseVector(v),
252266
)
253267
) {
254268
throw new ChromaValueError(
255-
"Expected metadata to be a string, number, boolean, or nullable",
269+
"Expected metadata to be a string, number, boolean, SparseVector, or nullable",
256270
);
257271
}
258272
};

0 commit comments

Comments
 (0)