If you’re encountering this TypeScript error after upgrading from weaviate-client v3.6.0
and above:
Type 'PrimitiveVectorType' is not assignable to type 'number[]'.
Type 'MultiVectorType' is not assignable to type 'number[]'.
Type 'number[]' is not assignable to type 'number'
New Type Definitions
In the upcoming release, items.vectors.default
now returns PrimitiveVectorType
which is essentially a union type number[] | number[][]
instead of just number[]
. This change introduces support for multi-vector scenarios while maintaining backward compatibility for single vectors.
export interface Vectors {
[k: string]: PrimitiveVectorType;
}
export type PrimitiveVectorType = SingleVectorType | MultiVectorType;
export type SingleVectorType = number[];
export type MultiVectorType = number[][];
Problem Code Example
This code will now cause a TypeScript error:
const searchResults = await wikipediaCollection.query.nearText('women in the olympics', {
autoLimit: 1,
includeVector: true,
returnMetadata: ['distance'],
})
let myVec: number[];
for (const item of searchResults.objects) {
myVec = item.vectors.default; // ❌ Type error here
console.log(myVec)
}
Solutions
Use Type Assertions
If you know your data will always be a single vector:
let myVec: number[];
for (const item of searchResults.objects) {
myVec = item.vectors.default as number[]; // ✅ Type assertion
console.log(myVec)
}
If you know your data will always be a multi-vector:
let myVec: number[][];
for (const item of searchResults.objects) {
myVec = item.vectors.default as number[][]; // ✅ Type assertion
console.log(myVec)
}
Optionally you can update your Type Annotations or use Type Guards.
Why This Change?
This breaking change enables support for multi-vector use cases while maintaining the existing API structure. The union type ensures type safety when working with both single vectors and multi-vector scenarios.
If you have questions about this change or need help with migration, please reply to this thread.