Skip to content

Commit de854b8

Browse files
committed
Make further fixes to BC checks and alter tightly coupled tests
1 parent daadc96 commit de854b8

File tree

5 files changed

+71
-132
lines changed

5 files changed

+71
-132
lines changed

src/collections/query/check.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
BaseNearOptions,
1111
FetchObjectByIdOptions,
1212
FetchObjectsOptions,
13+
HybridNearTextSubSearch,
14+
HybridNearVectorSubSearch,
1315
HybridOptions,
1416
NearVectorInputType,
1517
SearchOptions,
@@ -66,8 +68,11 @@ export class Check<T> {
6668
return check.supports;
6769
};
6870

69-
private checkSupportForMultiVectorSearch = async (vec?: NearVectorInputType) => {
70-
if (!Serialize.isMultiVector(vec)) return false;
71+
private checkSupportForMultiVectorSearch = async (
72+
vec?: NearVectorInputType | HybridNearVectorSubSearch | HybridNearTextSubSearch
73+
) => {
74+
if (Serialize.isHybridNearVectorSearch(vec) && !Serialize.isMultiVector(vec.vector)) return false;
75+
if (Serialize.isHybridVectorSearch(vec) && !Serialize.isMultiVector(vec)) return false;
7176
const check = await this.dbVersionSupport.supportsMultiVectorSearch();
7277
if (!check.supports) throw new WeaviateUnsupportedFeatureError(check.message);
7378
return check.supports;
@@ -80,8 +85,13 @@ export class Check<T> {
8085
return check.supports;
8186
};
8287

83-
private checkSupportForMultiVectorPerTargetSearch = async (vec?: NearVectorInputType) => {
84-
if (!Serialize.isMultiVectorPerTarget(vec)) return false;
88+
private checkSupportForMultiVectorPerTargetSearch = async (
89+
vec?: NearVectorInputType | HybridNearVectorSubSearch | HybridNearTextSubSearch
90+
) => {
91+
if (vec === undefined || Serialize.isHybridNearTextSearch(vec)) return false;
92+
if (Serialize.isHybridNearVectorSearch(vec) && !Serialize.isMultiVectorPerTarget(vec.vector))
93+
return false;
94+
if (Serialize.isHybridVectorSearch(vec) && !Serialize.isMultiVectorPerTarget(vec)) return false;
8595
const check = await this.dbVersionSupport.supportsMultiVectorPerTargetSearch();
8696
if (!check.supports) throw new WeaviateUnsupportedFeatureError(check.message);
8797
return check.supports;
@@ -94,7 +104,9 @@ export class Check<T> {
94104
this.checkSupportForMultiWeightPerTargetSearch(opts),
95105
this.checkSupportForNamedVectors(opts),
96106
]).then(([search, supportsTargets, supportsWeightsForTargets]) => {
97-
return { search, supportsTargets, supportsWeightsForTargets };
107+
const is126 = supportsTargets;
108+
const is127 = supportsWeightsForTargets;
109+
return { search, supportsTargets: is126 || is127, supportsWeightsForTargets: is127 };
98110
});
99111
};
100112

@@ -110,15 +122,17 @@ export class Check<T> {
110122
([
111123
search,
112124
supportsMultiTarget,
113-
supportMultiVector,
125+
supportsMultiVector,
114126
supportsVectorsForTargets,
115127
supportsWeightsForTargets,
116128
]) => {
129+
const is126 = supportsMultiTarget || supportsMultiVector;
130+
const is127 = supportsVectorsForTargets || supportsWeightsForTargets;
117131
return {
118132
search,
119-
supportsTargets: supportsMultiTarget || supportMultiVector,
120-
supportsVectorsForTargets,
121-
supportsWeightsForTargets,
133+
supportsTargets: is126 || is127,
134+
supportsVectorsForTargets: is127,
135+
supportsWeightsForTargets: is127,
122136
};
123137
}
124138
);
@@ -128,12 +142,8 @@ export class Check<T> {
128142
return Promise.all([
129143
this.getSearcher(),
130144
this.checkSupportForMultiTargetSearch(opts),
131-
this.checkSupportForMultiVectorSearch(
132-
Serialize.isHybridVectorSearch(opts?.vector) ? opts?.vector : undefined
133-
),
134-
this.checkSupportForMultiVectorPerTargetSearch(
135-
Serialize.isHybridVectorSearch(opts?.vector) ? opts?.vector : undefined
136-
),
145+
this.checkSupportForMultiVectorSearch(opts?.vector),
146+
this.checkSupportForMultiVectorPerTargetSearch(opts?.vector),
137147
this.checkSupportForMultiWeightPerTargetSearch(opts),
138148
this.checkSupportForNamedVectors(opts),
139149
this.checkSupportForBm25AndHybridGroupByQueries('Hybrid', opts),
@@ -142,15 +152,17 @@ export class Check<T> {
142152
([
143153
search,
144154
supportsMultiTarget,
145-
supportMultiVector,
155+
supportsMultiVector,
146156
supportsWeightsForTargets,
147157
supportsVectorsForTargets,
148158
]) => {
159+
const is126 = supportsMultiTarget || supportsMultiVector;
160+
const is127 = supportsVectorsForTargets || supportsWeightsForTargets;
149161
return {
150162
search,
151-
supportsTargets: supportsMultiTarget || supportMultiVector,
152-
supportsWeightsForTargets,
153-
supportsVectorsForTargets,
163+
supportsTargets: is126 || is127,
164+
supportsWeightsForTargets: is127,
165+
supportsVectorsForTargets: is127,
154166
};
155167
}
156168
);

src/collections/query/integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('Testing of the collection.query methods with a simple collection', ()
186186
expect(ret.objects[0].properties.testProp).toEqual('carrot');
187187
});
188188

189-
it.skip('should query with nearObject', async () => {
189+
it('should query with nearObject', async () => {
190190
const ret = await collection.query.nearObject(id, { limit: 1 });
191191
expect(ret.objects.length).toEqual(1);
192192
expect(ret.objects[0].properties.testProp).toEqual('carrot');
@@ -365,7 +365,7 @@ describe('Testing of the collection.query methods with a collection with a refer
365365
).toEqual('test');
366366
});
367367

368-
it.skip('should query with nearObject returning the referenced object', async () => {
368+
it('should query with nearObject returning the referenced object', async () => {
369369
const ret = await collection.query.nearObject(id2, {
370370
returnProperties: ['testProp'],
371371
returnReferences: [
@@ -1076,7 +1076,7 @@ describe('Testing of the groupBy collection.query methods with a simple collecti
10761076
expect(ret.objects[0].belongsToGroup).toEqual('test');
10771077
});
10781078

1079-
it.skip('should groupBy with nearObject', async () => {
1079+
it('should groupBy with nearObject', async () => {
10801080
const ret = await collection.query.nearObject(id, {
10811081
groupBy: groupByArgs,
10821082
});

src/collections/serialize/index.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ export class Serialize {
338338
};
339339

340340
public static isMultiVector = (vec?: NearVectorInputType): boolean => {
341-
return vec !== undefined && !Array.isArray(vec) && Object.values(vec).every(ArrayInputGuards.is1DArray);
341+
return (
342+
vec !== undefined &&
343+
!Array.isArray(vec) &&
344+
Object.values(vec).some(ArrayInputGuards.is1DArray || ArrayInputGuards.is2DArray)
345+
);
342346
};
343347

344348
public static isMultiVectorPerTarget = (vec?: NearVectorInputType): boolean => {
@@ -415,13 +419,13 @@ export class Serialize {
415419
);
416420
};
417421

418-
private static isHybridNearTextSearch = <T>(
422+
public static isHybridNearTextSearch = <T>(
419423
vector: BaseHybridOptions<T>['vector']
420424
): vector is HybridNearTextSubSearch => {
421425
return (vector as HybridNearTextSubSearch)?.query !== undefined;
422426
};
423427

424-
private static isHybridNearVectorSearch = <T>(
428+
public static isHybridNearVectorSearch = <T>(
425429
vector: BaseHybridOptions<T>['vector']
426430
): vector is HybridNearVectorSubSearch => {
427431
return (vector as HybridNearVectorSubSearch)?.vector !== undefined;
@@ -451,11 +455,7 @@ export class Serialize {
451455
}),
452456
};
453457
} else if (Serialize.isHybridNearTextSearch(vector)) {
454-
const { targetVectors, targets } = Serialize.vectors({
455-
...args,
456-
argumentName: 'vector',
457-
vector: undefined,
458-
});
458+
const { targetVectors, targets } = Serialize.targetVector(args);
459459
return {
460460
targets,
461461
targetVectors,
@@ -785,17 +785,10 @@ export class Serialize {
785785
vectorForTargets,
786786
};
787787
} else {
788-
if (!args.supportsTargets) {
789-
throw new WeaviateUnsupportedFeatureError(
790-
'Multi-vector search is not supported in this Weaviate version. Please upgrade to at least Weaviate 1.26.0'
791-
);
792-
}
793788
const vectorPerTarget: Record<string, Uint8Array> = {};
794789
Object.entries(args.vector).forEach(([k, v]) => {
795790
if (ArrayInputGuards.is2DArray(v)) {
796-
throw new WeaviateUnsupportedFeatureError(
797-
'Multiple vectors per target are not supported in this Weaviate version. Please upgrade to at least Weaviate 1.27.0.'
798-
);
791+
return;
799792
}
800793
vectorPerTarget[k] = Serialize.vectorToBytes(v);
801794
});

src/collections/serialize/unit.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { WeaviateUnsupportedFeatureError } from '../../errors.js';
21
import {
32
SearchBm25Args,
43
SearchFetchArgs,
@@ -387,23 +386,6 @@ describe('Unit testing of Serialize', () => {
387386
});
388387
});
389388

390-
it('should throw error for nearVector with two named vectors and supportsTargets (<1.27.0)', () => {
391-
expect(() =>
392-
Serialize.nearVector({
393-
vector: {
394-
a: [
395-
[1, 2, 3],
396-
[4, 5, 6],
397-
],
398-
b: [7, 8, 9],
399-
},
400-
supportsTargets: true,
401-
supportsVectorsForTargets: false,
402-
supportsWeightsForTargets: false,
403-
})
404-
).toThrow(WeaviateUnsupportedFeatureError);
405-
});
406-
407389
it('should parse args for nearVector with two named vectors and all supports (==1.27.x)', () => {
408390
const args = Serialize.nearVector({
409391
vector: {

0 commit comments

Comments
 (0)