mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Initial skeleton draft
This commit is contained in:
parent
2861527ba9
commit
82eef18d5a
38
adapter-milvus/.gitignore
vendored
Normal file
38
adapter-milvus/.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
64
adapter-milvus/pom.xml
Normal file
64
adapter-milvus/pom.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<!--
|
||||
~ Copyright (c) 2022-2023 nosqlbench
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>adapter-milvus</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>mvn-defaults</artifactId>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../mvn-defaults</relativePath>
|
||||
</parent>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
An nosqlbench adapter driver module for the Milvus/Zilliz database.
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>nb-annotations</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>adapters-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.milvus</groupId>
|
||||
<artifactId>milvus-sdk-java</artifactId>
|
||||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>adapters-api</artifactId>
|
||||
<version>5.21.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus;
|
||||
|
||||
import io.nosqlbench.adapter.milvus.ops.MilvusOp;
|
||||
import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.nb.api.components.core.NBComponent;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.nb.api.labels.NBLabels;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service(value = DriverAdapter.class, selector = Utils.DRIVER_TYPE)
|
||||
public class MilvusDriverAdapter extends BaseDriverAdapter<MilvusOp, MilvusSpace> {
|
||||
|
||||
public MilvusDriverAdapter(NBComponent parentComponent, NBLabels labels) {
|
||||
super(parentComponent, labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<MilvusOp> getOpMapper() {
|
||||
return new MilvusOpMapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<String, ? extends MilvusSpace> getSpaceInitializer(NBConfiguration cfg) {
|
||||
return (s) -> new MilvusSpace(s, cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBConfigModel getConfigModel() {
|
||||
return super.getConfigModel().add(MilvusSpace.getConfigModel());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package io.nosqlbench.adapter.milvus;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
import io.nosqlbench.adapter.diag.DriverAdapterLoader;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.nb.api.components.core.NBComponent;
|
||||
import io.nosqlbench.nb.api.labels.NBLabels;
|
||||
|
||||
@Service(value = DriverAdapterLoader.class, selector = Utils.DRIVER_TYPE)
|
||||
public class MilvusDriverAdapterLoader implements DriverAdapterLoader {
|
||||
@Override
|
||||
public MilvusDriverAdapter load(NBComponent parent, NBLabels childLabels) {
|
||||
return new MilvusDriverAdapter(parent, childLabels);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus;
|
||||
|
||||
import io.nosqlbench.adapter.milvus.opdispensers.MilvusDropCollectionOpDispenser;
|
||||
import io.nosqlbench.adapter.milvus.opdispensers.MilvusOpDispenser;
|
||||
import io.nosqlbench.adapter.milvus.opdispensers.MilvusCreateCollectionOpDispenser;
|
||||
import io.nosqlbench.adapter.milvus.ops.MilvusOp;
|
||||
import io.nosqlbench.adapter.milvus.ops.MilvusOpTypes;
|
||||
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
|
||||
import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.engine.api.templating.TypeAndTarget;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class MilvusOpMapper implements OpMapper<MilvusOp> {
|
||||
private static final Logger logger = LogManager.getLogger(MilvusOpMapper.class);
|
||||
private final MilvusDriverAdapter adapter;
|
||||
|
||||
/**
|
||||
* Create a new MilvusOpMapper implementing the {@link OpMapper} interface.
|
||||
*
|
||||
* @param adapter The associated {@link MilvusDriverAdapter}
|
||||
*/
|
||||
public MilvusOpMapper(MilvusDriverAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an instance of a {@link ParsedOp} returns the appropriate {@link MilvusOpDispenser} subclass
|
||||
*
|
||||
* @param op The ParsedOp to be evaluated
|
||||
* @return The correct MilvusOpDispenser subclass based on the op type
|
||||
*/
|
||||
@Override
|
||||
public OpDispenser<? extends MilvusOp> apply(ParsedOp op) {
|
||||
TypeAndTarget<MilvusOpTypes, String> typeAndTarget = op.getTypeAndTarget(MilvusOpTypes.class, String.class, "type", "index");
|
||||
logger.info(() -> "Using " + typeAndTarget.enumId + " statement form for '" + op.getName());
|
||||
|
||||
return switch (typeAndTarget.enumId) {
|
||||
case drop_collection -> new MilvusDropCollectionOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
case create_collection -> new MilvusCreateCollectionOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
default -> throw new RuntimeException("Unrecognized op type '" + typeAndTarget.enumId.name() + "' while " +
|
||||
"mapping parsed op " + op);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.milvus.param.ConnectParam;
|
||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.nb.api.config.standard.Param;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The MilvusSpace class is a context object which stores all stateful contextual information needed to interact
|
||||
* with the Milvus/Zilliz database instance.
|
||||
* https://milvus.io/docs/install-java.md
|
||||
* https://docs.zilliz.com/docs/connect-to-cluster
|
||||
*/
|
||||
public class MilvusSpace implements AutoCloseable {
|
||||
private final static Logger logger = LogManager.getLogger(MilvusSpace.class);
|
||||
private String uri;
|
||||
private String token;
|
||||
private String tokenFile;
|
||||
private String databaseName;
|
||||
private final String name;
|
||||
private final NBConfiguration cfg;
|
||||
|
||||
protected MilvusServiceClient client;
|
||||
private ConnectParam connectParam;
|
||||
|
||||
private final Map<String, ConnectParam> connections = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Create a new MilvusSpace Object which stores all stateful contextual information needed to interact
|
||||
* with the Milvus/Zilliz database instance.
|
||||
*
|
||||
* @param name The name of this space
|
||||
* @param cfg The configuration ({@link NBConfiguration}) for this nb run
|
||||
*/
|
||||
public MilvusSpace(String name, NBConfiguration cfg) {
|
||||
this.name = name;
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
public synchronized MilvusServiceClient getClient() {
|
||||
if (client == null) {
|
||||
client = createClient();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
private MilvusServiceClient createClient() {
|
||||
this.uri = cfg.get("uri");
|
||||
this.databaseName = cfg.get("databaseName");
|
||||
String tokenFromFile = null;
|
||||
this.tokenFile = cfg.get("tokenFile");
|
||||
if(null != this.tokenFile && this.tokenFile.length() > 0) {
|
||||
Optional<String> tokenFileOpt = cfg.getOptional("tokenFile");
|
||||
if(tokenFileOpt.isPresent()) {
|
||||
Path path = Paths.get(tokenFileOpt.get());
|
||||
try {
|
||||
tokenFromFile = Files.readAllLines(path).getFirst();
|
||||
} catch (IOException e) {
|
||||
String error = "Error while reading token from file:" + path;
|
||||
logger.error(error, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.token = (null != tokenFromFile) ? tokenFromFile : cfg.get("token");
|
||||
connectParam = ConnectParam.newBuilder()
|
||||
.withUri(uri)
|
||||
.withToken(token)
|
||||
.withDatabaseName(databaseName)
|
||||
.build();
|
||||
logger.info(this.name + ": Creating new Milvus/Zilliz Client with (masked) token [" + Utils.maskDigits(token) + "], uri/endpoint ["
|
||||
+ uri + "]");
|
||||
this.client = new MilvusServiceClient(connectParam);
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public static NBConfigModel getConfigModel() {
|
||||
|
||||
return ConfigModel.of(MilvusSpace.class)
|
||||
.add(
|
||||
Param.optional("tokenFile", String.class, "the file to load the token from")
|
||||
)
|
||||
.add(
|
||||
Param.defaultTo("token", "root:Milvus")
|
||||
.setDescription("the Milvus/Zilliz token to use to connect to the database")
|
||||
)
|
||||
.add(
|
||||
Param.defaultTo("uri", "localhost:19530")
|
||||
.setDescription("the URI endpoint in which the database is running.")
|
||||
)
|
||||
.add(
|
||||
Param.defaultTo("databaseName", "baselines")
|
||||
.setDescription("the name of the database to use. Defaults to 'baselines'")
|
||||
)
|
||||
.asReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus;
|
||||
|
||||
public class Utils {
|
||||
public static final String DRIVER_TYPE = "milvus";
|
||||
|
||||
/**
|
||||
* Mask the digits in the given string with '*'
|
||||
* @param unmasked The string to mask
|
||||
* @return The masked string
|
||||
*/
|
||||
protected static String maskDigits(String unmasked) {
|
||||
int inputLength = (null == unmasked) ? 0 : unmasked.length();
|
||||
StringBuilder masked = new StringBuilder(inputLength);
|
||||
for(char ch : unmasked.toCharArray()) {
|
||||
if (Character.isDigit(ch)) {
|
||||
masked.append("*");
|
||||
} else {
|
||||
masked.append(ch);
|
||||
}
|
||||
}
|
||||
return masked.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus.opdispensers;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.milvus.param.collection.CreateCollectionParam;
|
||||
import io.nosqlbench.adapter.milvus.MilvusDriverAdapter;
|
||||
import io.nosqlbench.adapter.milvus.ops.MilvusCreateCollectionOp;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public class MilvusCreateCollectionOpDispenser extends MilvusOpDispenser {
|
||||
private static final Logger logger = LogManager.getLogger(MilvusCreateCollectionOpDispenser.class);
|
||||
|
||||
/**
|
||||
* Create a new MilvusCreateCollectionOpDispenser subclassed from {@link MilvusOpDispenser}.
|
||||
*
|
||||
* @param adapter The associated {@link MilvusDriverAdapter}
|
||||
* @param op The {@link ParsedOp} encapsulating the activity for this cycle
|
||||
* @param targetFunction A LongFunction that returns the specified Milvus Index for this Op
|
||||
*/
|
||||
public MilvusCreateCollectionOpDispenser(MilvusDriverAdapter adapter,
|
||||
ParsedOp op,
|
||||
LongFunction<String> targetFunction) {
|
||||
super(adapter, op, targetFunction);
|
||||
}
|
||||
|
||||
// https://milvus.io/docs/create_collection.md
|
||||
@Override
|
||||
public LongFunction<MilvusCreateCollectionOp> createOpFunc(LongFunction<MilvusServiceClient> clientF, ParsedOp op, LongFunction<String> targetF) {
|
||||
CreateCollectionParam.Builder eb = CreateCollectionParam.newBuilder();
|
||||
LongFunction<CreateCollectionParam.Builder> f =
|
||||
l -> CreateCollectionParam.newBuilder().withCollectionName(targetF.apply(l));
|
||||
return l -> new MilvusCreateCollectionOp(clientF.apply(l), f.apply(1).build());
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package io.nosqlbench.adapter.milvus.opdispensers;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.milvus.param.collection.DropCollectionParam;
|
||||
import io.nosqlbench.adapter.milvus.MilvusDriverAdapter;
|
||||
import io.nosqlbench.adapter.milvus.ops.MilvusDropCollectionOp;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public class MilvusDropCollectionOpDispenser extends MilvusOpDispenser {
|
||||
private static final Logger logger = LogManager.getLogger(MilvusDropCollectionOpDispenser.class);
|
||||
|
||||
/**
|
||||
* Create a new MilvusDeleteOpDispenser subclassed from {@link MilvusOpDispenser}.
|
||||
*
|
||||
* @param adapter The associated {@link MilvusDriverAdapter}
|
||||
* @param op The {@link ParsedOp} encapsulating the activity for this cycle
|
||||
* @param targetFunction A LongFunction that returns the specified Milvus Index for this Op
|
||||
*/
|
||||
public MilvusDropCollectionOpDispenser(MilvusDriverAdapter adapter,
|
||||
ParsedOp op,
|
||||
LongFunction<String> targetFunction) {
|
||||
super(adapter, op, targetFunction);
|
||||
}
|
||||
|
||||
// https://milvus.io/docs/drop_collection.md
|
||||
@Override
|
||||
public LongFunction<MilvusDropCollectionOp> createOpFunc(LongFunction<MilvusServiceClient> clientF, ParsedOp op, LongFunction<String> targetF) {
|
||||
DropCollectionParam.Builder eb = DropCollectionParam.newBuilder();
|
||||
LongFunction<DropCollectionParam.Builder> f =
|
||||
l -> DropCollectionParam.newBuilder().withCollectionName(targetF.apply(l));
|
||||
return l -> new MilvusDropCollectionOp(clientF.apply(l), f.apply(1).build());
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus.opdispensers;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.nosqlbench.adapter.milvus.MilvusDriverAdapter;
|
||||
import io.nosqlbench.adapter.milvus.MilvusSpace;
|
||||
import io.nosqlbench.adapter.milvus.ops.MilvusOp;
|
||||
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public abstract class MilvusOpDispenser extends BaseOpDispenser<MilvusOp, MilvusSpace> {
|
||||
|
||||
protected final LongFunction<MilvusSpace> mzSpaceFunction;
|
||||
protected final LongFunction<MilvusServiceClient> clientFunction;
|
||||
private final LongFunction<? extends MilvusOp> opF;
|
||||
|
||||
protected MilvusOpDispenser(MilvusDriverAdapter adapter, ParsedOp op, LongFunction<String> targetF) {
|
||||
super(adapter, op);
|
||||
this.mzSpaceFunction = adapter.getSpaceFunc(op);
|
||||
this.clientFunction = (long l) -> this.mzSpaceFunction.apply(l).getClient();
|
||||
this.opF = createOpFunc(this.clientFunction, op, targetF);
|
||||
}
|
||||
|
||||
public abstract LongFunction<? extends MilvusOp> createOpFunc(
|
||||
LongFunction<MilvusServiceClient> clientF,
|
||||
ParsedOp op,
|
||||
LongFunction<String> targetF
|
||||
);
|
||||
|
||||
@Override
|
||||
public MilvusOp apply(long value) {
|
||||
return opF.apply(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus.ops;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.milvus.param.R;
|
||||
import io.milvus.param.RpcStatus;
|
||||
import io.milvus.param.collection.CreateCollectionParam;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class MilvusCreateCollectionOp extends MilvusOp {
|
||||
private static final Logger logger = LogManager.getLogger(MilvusCreateCollectionOp.class);
|
||||
private final CreateCollectionParam request;
|
||||
|
||||
/**
|
||||
* Create a new {@link ParsedOp} encapsulating a call to the Milvus/Zilliz client delete method
|
||||
*
|
||||
* @param client The associated {@link MilvusServiceClient} used to communicate with the database
|
||||
* @param request The {@link CreateCollectionParam} built for this operation
|
||||
*/
|
||||
public MilvusCreateCollectionOp(MilvusServiceClient client, CreateCollectionParam request) {
|
||||
super(client);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object applyOp(long value) {
|
||||
logger.debug("Milvus/Zilliz create collection request");
|
||||
R<RpcStatus> response = client.createCollection(request);
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus.ops;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.milvus.param.collection.DropCollectionParam;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class MilvusDropCollectionOp extends MilvusOp {
|
||||
private static final Logger logger = LogManager.getLogger(MilvusDropCollectionOp.class);
|
||||
private final DropCollectionParam request;
|
||||
|
||||
/**
|
||||
* Create a new {@link ParsedOp} encapsulating a call to the Milvus/Zilliz client delete method
|
||||
*
|
||||
* @param client The associated {@link MilvusServiceClient} used to communicate with the database
|
||||
* @param request The {@link DropCollectionParam} built for this operation
|
||||
*/
|
||||
public MilvusDropCollectionOp(MilvusServiceClient client, DropCollectionParam request) {
|
||||
super(client);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object applyOp(long value) {
|
||||
logger.debug("Milvus/Zilliz drop collection request");
|
||||
return client.dropCollection(request);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus.ops;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
|
||||
|
||||
public abstract class MilvusOp implements CycleOp<Object> {
|
||||
protected final MilvusServiceClient client;
|
||||
|
||||
public MilvusOp(MilvusServiceClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object apply(long value) {
|
||||
try {
|
||||
Object result = applyOp(value);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
if (e instanceof RuntimeException rte) {
|
||||
throw rte;
|
||||
} else {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public abstract Object applyOp(long value) throws Exception;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.milvus.ops;
|
||||
|
||||
public enum MilvusOpTypes {
|
||||
drop_collection,
|
||||
create_collection,
|
||||
// update,
|
||||
// upsert,
|
||||
// delete,
|
||||
// describeindexstats,
|
||||
// fetch
|
||||
}
|
142
adapter-milvus/src/main/resources/milvus.md
Normal file
142
adapter-milvus/src/main/resources/milvus.md
Normal file
@ -0,0 +1,142 @@
|
||||
# milvus driver adapter
|
||||
The milvus driver adapter is a nb adapter for the milvus driver, an open source Java driver for connecting to and
|
||||
performing operations on an instance of a Milvus/Zilliz Vector database. The driver is hosted on github at
|
||||
https://github.com/milvus-io/milvus-sdk-java
|
||||
|
||||
## activity parameters
|
||||
The following parameters must be supplied to the adapter at runtime in order to successfully connect to an
|
||||
instance of the Milvus/Zilliz database:
|
||||
|
||||
* token - In order to use the pinecone database you must have an account. Once the account is created you can [request
|
||||
an api key](https://docs.pinecone.io/docs/quickstart#2-get-your-api-key). This key will need to be provided any time a database connection is desired.
|
||||
* uri - When an Index is created in the database the uri must be specified as well. The adapter will
|
||||
use the default value of localhost:19530 if none is provided at runtime.
|
||||
|
||||
## Op Templates
|
||||
|
||||
The Milvus adapter supports all operations supported by the Java driver published by Milvus.
|
||||
The official Milvus API reference can be found at
|
||||
https://docs.pinecone.io/reference/describe_index_stats_post
|
||||
|
||||
The operations include:
|
||||
|
||||
* Delete
|
||||
* DescribeIndexStats
|
||||
* Fetch
|
||||
* Query
|
||||
* Update
|
||||
* Upsert
|
||||
|
||||
## Examples
|
||||
```yaml
|
||||
ops:
|
||||
# A pinecone query op
|
||||
query-example:
|
||||
type: query
|
||||
index: query_index
|
||||
# The query vector. Use these fields if only querying a single vector. If querying multiple use the
|
||||
# query_vectors structure below.
|
||||
vector: my_array_of_floats
|
||||
namespace: query_namespace
|
||||
# The number of results to return for each query.
|
||||
top_k: int_query_topk
|
||||
# You can use vector metadata to limit your search. See https://www.pinecone.io/docs/metadata-filtering/
|
||||
filter:
|
||||
filterfield: metadata_field
|
||||
operator: [$lt, $eq, $gt, ...]
|
||||
comparator: value
|
||||
# Indicates whether vector values are included in the response.
|
||||
include_values: boolean
|
||||
# Indicates whether metadata is included in the response as well as the ids.
|
||||
include_metadata: boolean
|
||||
query_vectors:
|
||||
- id: 1
|
||||
values: csv_separated_floats
|
||||
top_k: int_val
|
||||
namespace: string_val
|
||||
filter:
|
||||
filterfield: metadata_field
|
||||
operator: [$lt, $eq, $gt, ...]
|
||||
comparator: value
|
||||
sparse_values:
|
||||
indices: list_of_ints
|
||||
values: list_of_floats
|
||||
- id: 2
|
||||
values: csv_separated_floats
|
||||
top_k: int_val
|
||||
namespace: string_val
|
||||
filter:
|
||||
filterfield: metadata_field
|
||||
operator: [$lt, $eq, $gt, ...]
|
||||
comparator: value
|
||||
sparse_values:
|
||||
indices: list_of_ints
|
||||
values: list_of_floats
|
||||
|
||||
# A delete op
|
||||
# If specified, the metadata filter here will be used to select the vectors to delete. This is mutually exclusive
|
||||
# with specifying ids to delete in the ids param or using delete_all=True. delete_all indicates that all vectors
|
||||
# in the index namespace should be deleted.
|
||||
delete-example:
|
||||
type: delete
|
||||
index: delete_index
|
||||
namespace: delete_namespace
|
||||
ids: csv_list_of_vectors_to_delete
|
||||
deleteall: [true,false]
|
||||
filter:
|
||||
filterfield: metadata_field
|
||||
operator: [$lt, $eq, $gt, ...]
|
||||
comparator: value
|
||||
|
||||
# A describe index stats op. Specify metadata filters to narrow the range of indices described.
|
||||
describe-index-stats-example:
|
||||
type: describe-index-stats
|
||||
index: describe_index
|
||||
filter:
|
||||
filterfield: metadata_field
|
||||
operator: [$lt, $eq, $gt, ...]
|
||||
comparator: value
|
||||
|
||||
# A pinecone fetch op
|
||||
fetch-example:
|
||||
fetch: fetch_index
|
||||
namespace: fetch_namespace
|
||||
ids: csv_list_of_vectors_to_fetch
|
||||
|
||||
# A pinecone update op
|
||||
update-example:
|
||||
type: update
|
||||
index: update_index
|
||||
id: string_id
|
||||
values: list_of_floats
|
||||
namespace: update_namespace
|
||||
metadata:
|
||||
key1: val1
|
||||
key2: val2
|
||||
key3: val3
|
||||
sparse_values:
|
||||
indices: list_of_ints
|
||||
values: list_of_floats
|
||||
|
||||
# A pinecone upsert op
|
||||
upsert-example:
|
||||
type: upsert
|
||||
index: upsert_index
|
||||
namespace: upsert_namespace
|
||||
upsert_vectors:
|
||||
- id: 1
|
||||
values: csv_separated_floats
|
||||
sparse_values:
|
||||
indices: list_of_ints
|
||||
values: list_of_floats
|
||||
metadata:
|
||||
key1: val1
|
||||
key2: val2
|
||||
- id: 2
|
||||
values: csv_separated_floats
|
||||
sparse_values:
|
||||
indices: list_of_ints
|
||||
values: list_of_floats
|
||||
|
||||
|
||||
```
|
@ -77,7 +77,7 @@ public class StandardActivity<R extends Op, S> extends SimpleActivity implements
|
||||
}
|
||||
|
||||
Optional<String> defaultDriverName = activityDef.getParams().getOptionalString("driver");
|
||||
Optional<DriverAdapter<?,?>> defaultAdapter = activityDef.getParams().getOptionalString("driver")
|
||||
Optional<DriverAdapter<?,?>> defaultAdapter = defaultDriverName
|
||||
.flatMap(name -> ServiceSelector.of(name,ServiceLoader.load(DriverAdapterLoader.class)).get())
|
||||
.map(l -> l.load(this,NBLabels.forKV()));
|
||||
|
||||
@ -93,7 +93,7 @@ public class StandardActivity<R extends Op, S> extends SimpleActivity implements
|
||||
List<DriverAdapter<?,?>> adapterlist = new ArrayList<>();
|
||||
NBConfigModel supersetConfig = ConfigModel.of(StandardActivity.class).add(yamlmodel);
|
||||
|
||||
Optional<String> defaultDriverOption = activityDef.getParams().getOptionalString("driver");
|
||||
Optional<String> defaultDriverOption = defaultDriverName;
|
||||
ConcurrentHashMap<String, OpMapper<? extends Op>> mappers = new ConcurrentHashMap<>();
|
||||
for (OpTemplate ot : opTemplates) {
|
||||
// ParsedOp incompleteOpDef = new ParsedOp(ot, NBConfiguration.empty(), List.of(), this);
|
||||
|
3
pom.xml
3
pom.xml
@ -64,6 +64,8 @@
|
||||
<module.adapter-kafka>adapter-kafka</module.adapter-kafka>
|
||||
<module.adapter-kafka>adapter-amqp</module.adapter-kafka>
|
||||
<module.adapter-jdbc>adapter-jdbc</module.adapter-jdbc>
|
||||
<module.adapter-pinecone>adapter-pinecone</module.adapter-pinecone>
|
||||
<module.adapter-milvus>adapter-milvus</module.adapter-milvus>
|
||||
|
||||
<!-- VIRTDATA MODULES -->
|
||||
<module.virtdata-api>virtdata-api</module.virtdata-api>
|
||||
@ -109,6 +111,7 @@
|
||||
<module>adapter-jdbc</module>
|
||||
<module>adapter-pinecone</module>
|
||||
<module>adapter-aws-opensearch</module>
|
||||
<module>adapter-milvus</module>
|
||||
|
||||
<!-- VIRTDATA MODULES -->
|
||||
<module>virtdata-api</module>
|
||||
|
Loading…
Reference in New Issue
Block a user