Skip to content

Commit

Permalink
Send vectors optimistically to handle legacy vectorizers in >1.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmith023 committed Jul 10, 2024
1 parent 6d4fb8b commit 9945226
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/collections/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const data = <T>(
if (Array.isArray(object.vectors)) {
const supportsNamedVectors = await dbVersionSupport.supportsNamedVectors();
if (supportsNamedVectors.supports) {
obj.vector = object.vectors;
obj.vectors = { default: object.vectors };
} else {
obj.vector = object.vectors;
Expand Down
37 changes: 36 additions & 1 deletion src/collections/data/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
import { v4 } from 'uuid';
import { WeaviateUnsupportedFeatureError } from '../../errors.js';
import weaviate, { WeaviateClient } from '../../index.js';
import weaviate, { WeaviateClient, weaviateV2 } from '../../index.js';
import { GeoCoordinate, PhoneNumber } from '../../proto/v1/properties.js';
import { Collection } from '../collection/index.js';
import { CrossReference, CrossReferences, Reference } from '../references/index.js';
Expand Down Expand Up @@ -1000,3 +1000,38 @@ describe('Testing of the collection.data methods with a vector index', () => {
expect(obj2?.vectors.default).toEqual([5, 6, 7, 8]);
});
});

describe('Testing of BYOV insertion with legacy vectorizer', () => {
const collectionName = 'TestBYOVEdgeCase';
const oldClient = weaviateV2.client({ scheme: 'http', host: 'localhost:8080' });

beforeAll(() =>
oldClient.schema
.classCreator()
.withClass({
class: collectionName,
vectorizer: 'none',
})
.do()
);

afterAll(() => oldClient.schema.classDeleter().withClassName(collectionName).do());

it('should insert and retrieve many vectors using the new client', async () => {
const client = await weaviate.connectToLocal();
const collection = client.collections.get(collectionName);
await collection.data.insertMany([{ vectors: [1, 2, 3] }, { vectors: [4, 5, 6] }]);
const objects = await collection.query.fetchObjects({ includeVector: true }).then((res) => res.objects);
expect(objects.length).toEqual(2);
expect(objects[0].vectors.default).toEqual([1, 2, 3]);
expect(objects[1].vectors.default).toEqual([4, 5, 6]);
});

it('should insert and retrieve single vectors using the new client', async () => {
const client = await weaviate.connectToLocal();
const collection = client.collections.get(collectionName);
const id = await collection.data.insert({ vectors: [7, 8, 9] });
const object = await collection.query.fetchObjectById(id, { includeVector: true });
expect(object?.vectors.default).toEqual([7, 8, 9]);
});
});
2 changes: 2 additions & 0 deletions src/collections/serialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,8 @@ export class Serialize {
name: 'default',
}),
];
vectorBytes = Serialize.vectorToBytes(obj.vectors);
// required in case collection was made with <1.24.0 and has since been migrated to >=1.24.0
} else if (obj.vectors !== undefined) {
vectorBytes = Serialize.vectorToBytes(obj.vectors);
}
Expand Down

0 comments on commit 9945226

Please sign in to comment.