Skip to content

Commit

Permalink
rename size -> dimension, function -> metric
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 8, 2023
1 parent ed2a34f commit 9f77976
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/collections/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export const updateOneInternalOptionsKeys: Set<string> = new Set(

class _CreateCollectionOptions {
vector?: {
size: number,
function?: 'cosine' | 'euclidean' | 'dot_product'
dimension: number,
metric?: 'cosine' | 'euclidean' | 'dot_product'
} = undefined;
}

Expand Down
32 changes: 24 additions & 8 deletions tests/driver/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -86,15 +86,15 @@ 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);

await astraMongoose.connect(dbUri, {isAstra: true, logSkippedOptions: true});
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 = {
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 9f77976

Please sign in to comment.