Skip to content

Commit 9945226

Browse files
committed
Send vectors optimistically to handle legacy vectorizers in >1.24.0
1 parent 6d4fb8b commit 9945226

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/collections/data/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ const data = <T>(
193193
if (Array.isArray(object.vectors)) {
194194
const supportsNamedVectors = await dbVersionSupport.supportsNamedVectors();
195195
if (supportsNamedVectors.supports) {
196+
obj.vector = object.vectors;
196197
obj.vectors = { default: object.vectors };
197198
} else {
198199
obj.vector = object.vectors;

src/collections/data/integration.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
33
import { v4 } from 'uuid';
44
import { WeaviateUnsupportedFeatureError } from '../../errors.js';
5-
import weaviate, { WeaviateClient } from '../../index.js';
5+
import weaviate, { WeaviateClient, weaviateV2 } from '../../index.js';
66
import { GeoCoordinate, PhoneNumber } from '../../proto/v1/properties.js';
77
import { Collection } from '../collection/index.js';
88
import { CrossReference, CrossReferences, Reference } from '../references/index.js';
@@ -1000,3 +1000,38 @@ describe('Testing of the collection.data methods with a vector index', () => {
10001000
expect(obj2?.vectors.default).toEqual([5, 6, 7, 8]);
10011001
});
10021002
});
1003+
1004+
describe('Testing of BYOV insertion with legacy vectorizer', () => {
1005+
const collectionName = 'TestBYOVEdgeCase';
1006+
const oldClient = weaviateV2.client({ scheme: 'http', host: 'localhost:8080' });
1007+
1008+
beforeAll(() =>
1009+
oldClient.schema
1010+
.classCreator()
1011+
.withClass({
1012+
class: collectionName,
1013+
vectorizer: 'none',
1014+
})
1015+
.do()
1016+
);
1017+
1018+
afterAll(() => oldClient.schema.classDeleter().withClassName(collectionName).do());
1019+
1020+
it('should insert and retrieve many vectors using the new client', async () => {
1021+
const client = await weaviate.connectToLocal();
1022+
const collection = client.collections.get(collectionName);
1023+
await collection.data.insertMany([{ vectors: [1, 2, 3] }, { vectors: [4, 5, 6] }]);
1024+
const objects = await collection.query.fetchObjects({ includeVector: true }).then((res) => res.objects);
1025+
expect(objects.length).toEqual(2);
1026+
expect(objects[0].vectors.default).toEqual([1, 2, 3]);
1027+
expect(objects[1].vectors.default).toEqual([4, 5, 6]);
1028+
});
1029+
1030+
it('should insert and retrieve single vectors using the new client', async () => {
1031+
const client = await weaviate.connectToLocal();
1032+
const collection = client.collections.get(collectionName);
1033+
const id = await collection.data.insert({ vectors: [7, 8, 9] });
1034+
const object = await collection.query.fetchObjectById(id, { includeVector: true });
1035+
expect(object?.vectors.default).toEqual([7, 8, 9]);
1036+
});
1037+
});

src/collections/serialize/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,8 @@ export class Serialize {
10961096
name: 'default',
10971097
}),
10981098
];
1099+
vectorBytes = Serialize.vectorToBytes(obj.vectors);
1100+
// required in case collection was made with <1.24.0 and has since been migrated to >=1.24.0
10991101
} else if (obj.vectors !== undefined) {
11001102
vectorBytes = Serialize.vectorToBytes(obj.vectors);
11011103
}

0 commit comments

Comments
 (0)