From ceefc44cfea8eb2fc5e702678fa6f20a8213d94d Mon Sep 17 00:00:00 2001 From: Madhavan Sridharan Date: Thu, 10 Oct 2024 16:34:36 -0400 Subject: [PATCH] MongoDB: Upgrade driver version and adapt to server 8.0.x --- nb-adapters/adapter-mongodb/pom.xml | 2 +- .../adapter/mongodb/core/MongoSpace.java | 8 +++---- .../baselinesv2/mongodb_vector_search.yaml | 23 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/nb-adapters/adapter-mongodb/pom.xml b/nb-adapters/adapter-mongodb/pom.xml index 9ec9723bd..15f976eb3 100644 --- a/nb-adapters/adapter-mongodb/pom.xml +++ b/nb-adapters/adapter-mongodb/pom.xml @@ -42,7 +42,7 @@ org.mongodb mongodb-driver-sync - 4.11.1 + 5.2.0 diff --git a/nb-adapters/adapter-mongodb/src/main/java/io/nosqlbench/adapter/mongodb/core/MongoSpace.java b/nb-adapters/adapter-mongodb/src/main/java/io/nosqlbench/adapter/mongodb/core/MongoSpace.java index 2c66c76e9..42cf60c79 100644 --- a/nb-adapters/adapter-mongodb/src/main/java/io/nosqlbench/adapter/mongodb/core/MongoSpace.java +++ b/nb-adapters/adapter-mongodb/src/main/java/io/nosqlbench/adapter/mongodb/core/MongoSpace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 nosqlbench + * Copyright (c) 2022-2024 nosqlbench * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import com.mongodb.ServerApi; import com.mongodb.ServerApiVersion; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; -import io.nosqlbench.nb.api.components.core.NBNamedElement; import com.mongodb.client.MongoDatabase; +import io.nosqlbench.nb.api.components.core.NBNamedElement; import io.nosqlbench.nb.api.config.standard.ConfigModel; import io.nosqlbench.nb.api.config.standard.NBConfigModel; import io.nosqlbench.nb.api.config.standard.NBConfiguration; @@ -84,11 +84,11 @@ public class MongoSpace implements NBNamedElement, AutoCloseable { MongoClientSettings.getDefaultCodecRegistry() ); - // https://www.mongodb.com/docs/v7.0/reference/stable-api + // https://www.mongodb.com/docs/manual/reference/stable-api ServerApi serverApi = ServerApi.builder() .version(ServerApiVersion.V1) .deprecationErrors(false) - .strict(false)//Needed because createSearchIndexes is not in stable API + .strict(false) // Needed because createSearchIndexes is not in stable API (yet) .build(); MongoClientSettings settings = MongoClientSettings.builder() diff --git a/nb-adapters/adapter-mongodb/src/main/resources/activities/baselinesv2/mongodb_vector_search.yaml b/nb-adapters/adapter-mongodb/src/main/resources/activities/baselinesv2/mongodb_vector_search.yaml index 4cc0cd753..5f13743ca 100644 --- a/nb-adapters/adapter-mongodb/src/main/resources/activities/baselinesv2/mongodb_vector_search.yaml +++ b/nb-adapters/adapter-mongodb/src/main/resources/activities/baselinesv2/mongodb_vector_search.yaml @@ -92,17 +92,16 @@ blocks: indexes: [ { name: "kv_value_vector_search_idx", + type: "vectorSearch", definition: { - mappings: { - dynamic: true, - fields: { - value: { - type: "knnVector", - dimensions: TEMPLATE(dimensions,1536), - similarity: "TEMPLATE(similarity_function,cosine)" - } + fields: [ + { + type: "vector", + path: "value", + numDimensions: TEMPLATE(dimensions,1536), + similarity: "TEMPLATE(similarity_function,cosine)" } - } + ] } } ] @@ -134,6 +133,7 @@ blocks: "pipeline": [ { "$vectorSearch": { + "exact": false, "index": "kv_value_vector_search_idx", "path": "value", "queryVector": {test_floatlist}, @@ -157,15 +157,18 @@ blocks: - io.nosqlbench.adapter.mongodb.MongoDbUtils verifier-init: | k=TEMPLATE(top_k,100) - relevancy=scriptingmetrics.newRelevancyMeasures(_parsed_op); + relevancy=new io.nosqlbench.nb.api.engine.metrics.wrappers.RelevancyMeasures(_parsed_op) relevancy.addFunction(io.nosqlbench.engine.extensions.computefunctions.RelevancyFunctions.recall("recall",k)); relevancy.addFunction(io.nosqlbench.engine.extensions.computefunctions.RelevancyFunctions.precision("precision",k)); relevancy.addFunction(io.nosqlbench.engine.extensions.computefunctions.RelevancyFunctions.F1("F1",k)); relevancy.addFunction(io.nosqlbench.engine.extensions.computefunctions.RelevancyFunctions.reciprocal_rank("RR",k)); relevancy.addFunction(io.nosqlbench.engine.extensions.computefunctions.RelevancyFunctions.average_precision("AP",k)); + windowed_relevancy = new io.nosqlbench.nb.api.engine.metrics.wrappers.WindowedRelevancyMeasures(_parsed_op,10); + windowed_relevancy.addFunction(io.nosqlbench.engine.extensions.computefunctions.RelevancyFunctions.recall("recall",k)); verifier: | actual_indices=MongoDbUtils.getFieldFromResults("key",result); relevancy.accept({relevant_indices},actual_indices); + windowed_relevancy.accept({relevant_indices}, actual_indices); return true; main_write: params: