From 9f7797670eb11f8c462b303c44ebbd968526af47 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 8 Nov 2023 16:24:13 -0500 Subject: [PATCH] rename size -> dimension, function -> metric --- src/collections/options.ts | 4 ++-- tests/driver/api.test.ts | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/collections/options.ts b/src/collections/options.ts index 50181bed..83153f37 100644 --- a/src/collections/options.ts +++ b/src/collections/options.ts @@ -117,8 +117,8 @@ export const updateOneInternalOptionsKeys: Set = new Set( class _CreateCollectionOptions { vector?: { - size: number, - function?: 'cosine' | 'euclidean' | 'dot_product' + dimension: number, + metric?: 'cosine' | 'euclidean' | 'dot_product' } = undefined; } diff --git a/tests/driver/api.test.ts b/tests/driver/api.test.ts index 15a61126..9239ef75 100644 --- a/tests/driver/api.test.ts +++ b/tests/driver/api.test.ts @@ -63,7 +63,7 @@ describe('Mongoose Model API level tests', async () => { await dropCollections(isAstra, astraMongoose, jsonAPIMongoose, 'carts'); }); - async function getInstance() { + function getInstance() { const mongooseInstance = new mongoose.Mongoose(); mongooseInstance.setDriver(StargateMongooseDriver); mongooseInstance.set('autoCreate', true); @@ -86,7 +86,7 @@ describe('Mongoose Model API level tests', async () => { products: [{ type: Schema.Types.ObjectId, ref: 'Product' }] }); if (isAstra) { - astraMongoose = await getInstance(); + astraMongoose = getInstance(); Product = astraMongoose.model('Product', productSchema); Cart = astraMongoose.model('Cart', cartSchema); @@ -94,7 +94,7 @@ describe('Mongoose Model API level tests', async () => { await Promise.all(Object.values(astraMongoose.connection.models).map(Model => Model.init())); } else { // @ts-ignore - jsonAPIMongoose = await getInstance(); + jsonAPIMongoose = getInstance(); Product = jsonAPIMongoose.model('Product', productSchema); Cart = jsonAPIMongoose.model('Cart', cartSchema); const options = { @@ -771,20 +771,36 @@ describe('Mongoose Model API level tests', async () => { name: 'String' }, { - collectionOptions: { vector: { size: 2, function: 'cosine' } }, + collectionOptions: { vector: { dimension: 2, metric: 'cosine' } }, autoCreate: true } ); - const Vector = mongooseInstance!.model( + const mongooseInstance = getInstance(); + const Vector = mongooseInstance.model( 'Vector', vectorSchema, 'vector' ); - this.beforeEach(async function() { - await mongooseInstance!.connection.dropCollection('vector'); + before(async function() { + if (isAstra) { + await mongooseInstance.connect(dbUri, {isAstra: true, logSkippedOptions: true}); + } else { + const options = { + username: process.env.STARGATE_USERNAME, + password: process.env.STARGATE_PASSWORD, + authUrl: process.env.STARGATE_AUTH_URL, + logSkippedOptions: true + }; + // @ts-ignore - these are config options supported by stargate-mongoose but not mongoose + await mongooseInstance.connect(dbUri, options); + } + }); - await Vector.init(); + + beforeEach(async function() { + await mongooseInstance!.connection.dropCollection('vector'); + await Vector.createCollection(); await Vector.create([ { name: 'Test vector 1',