Skip to content

Commit

Permalink
Move dense_vector and sparse_vector to module (#43280)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayya-sharipova committed Jun 18, 2019
1 parent a9e829a commit 952ddf2
Show file tree
Hide file tree
Showing 41 changed files with 479 additions and 336 deletions.
2 changes: 2 additions & 0 deletions docs/reference/mapping/types/dense-vector.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[role="xpack"]
[testenv="basic"]
[[dense-vector]]
=== Dense vector datatype

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/mapping/types/sparse-vector.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[role="xpack"]
[testenv="basic"]
[[sparse-vector]]
=== Sparse vector datatype

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/query-dsl/script-score-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ to be the most efficient by using the internal mechanisms.
--------------------------------------------------
// NOTCONSOLE

[role="xpack"]
[testenv="basic"]
[[vector-functions]]
===== Functions for vector fields

Expand Down
4 changes: 4 additions & 0 deletions docs/reference/rest-api/info.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Example response:
"available" : true,
"enabled" : true
},
"vectors" : {
"available" : true,
"enabled" : true
},
"watcher" : {
"available" : true,
"enabled" : true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
- match: { classes.6.methods.0.parameters.0 : java.lang.CharSequence }
- match: { classes.6.methods.0.parameters.1 : int }
- match: { classes.6.methods.0.parameters.2 : int }
- match: { imported_methods.0.name: dotProduct }
- match: { class_bindings.0.name: cosineSimilarity }
- match: { imported_methods.0.name: saturation }
- match: { class_bindings.0.name: decayDateExp }
- match: { instance_bindings: [] }
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public Map<String, Mapper.TypeParser> getMappers() {
mappers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
mappers.put(RankFeatureFieldMapper.CONTENT_TYPE, new RankFeatureFieldMapper.TypeParser());
mappers.put(RankFeaturesFieldMapper.CONTENT_TYPE, new RankFeaturesFieldMapper.TypeParser());
mappers.put(DenseVectorFieldMapper.CONTENT_TYPE, new DenseVectorFieldMapper.TypeParser());
mappers.put(SparseVectorFieldMapper.CONTENT_TYPE, new SparseVectorFieldMapper.TypeParser());
mappers.put(SearchAsYouTypeFieldMapper.CONTENT_TYPE, new SearchAsYouTypeFieldMapper.TypeParser());
return Collections.unmodifiableMap(mappers);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,15 @@ public synchronized boolean isJdbcAllowed() {
return licensed && localStatus.active;
}

/**
* Determine if Vectors support should be enabled.
* <p>
* Vectors is available for all license types except {@link OperationMode#MISSING}
*/
public synchronized boolean isVectorsAllowed() {
return status.active;
}

/**
* Determine if ODBC support should be enabled.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
import org.elasticsearch.xpack.core.vectors.VectorsFeatureSetUsage;
import org.elasticsearch.xpack.core.watcher.WatcherFeatureSetUsage;
import org.elasticsearch.xpack.core.watcher.WatcherMetaData;
import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchAction;
Expand Down Expand Up @@ -437,7 +438,9 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_FRAME, DataFrameFeatureSetUsage::new),
new NamedWriteableRegistry.Entry(PersistentTaskParams.class, DataFrameField.TASK_NAME, DataFrameTransform::new),
new NamedWriteableRegistry.Entry(Task.Status.class, DataFrameField.TASK_NAME, DataFrameTransformState::new),
new NamedWriteableRegistry.Entry(PersistentTaskState.class, DataFrameField.TASK_NAME, DataFrameTransformState::new)
new NamedWriteableRegistry.Entry(PersistentTaskState.class, DataFrameField.TASK_NAME, DataFrameTransformState::new),
// Vectors
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VECTORS, VectorsFeatureSetUsage::new)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public final class XPackField {
public static final String CCR = "ccr";
/** Name constant for the data frame feature. */
public static final String DATA_FRAME = "data_frame";
/** Name constant for the vectors feature. */
public static final String VECTORS = "vectors";

private XPackField() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ private XPackSettings() {
/** Setting for enabling or disabling sql. Defaults to true. */
public static final Setting<Boolean> SQL_ENABLED = Setting.boolSetting("xpack.sql.enabled", true, Setting.Property.NodeScope);

/** Setting for enabling or disabling vectors. Defaults to true. */
public static final Setting<Boolean> VECTORS_ENABLED = Setting.boolSetting("xpack.vectors.enabled", true, Setting.Property.NodeScope);

/*
* SSL settings. These are the settings that are specifically registered for SSL. Many are private as we do not explicitly use them
* but instead parse based on a prefix (eg *.ssl.*)
Expand Down Expand Up @@ -204,6 +207,7 @@ public static List<Setting<?>> getAllSettings() {
settings.add(PASSWORD_HASHING_ALGORITHM);
settings.add(INDEX_LIFECYCLE_ENABLED);
settings.add(DATA_FRAME_ENABLED);
settings.add(VECTORS_ENABLED);
return Collections.unmodifiableList(settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public class XPackUsageFeatureAction extends Action<XPackUsageFeatureResponse> {
public static final XPackUsageFeatureAction INDEX_LIFECYCLE = new XPackUsageFeatureAction(XPackField.INDEX_LIFECYCLE);
public static final XPackUsageFeatureAction CCR = new XPackUsageFeatureAction(XPackField.CCR);
public static final XPackUsageFeatureAction DATA_FRAME = new XPackUsageFeatureAction(XPackField.DATA_FRAME);
public static final XPackUsageFeatureAction VECTORS = new XPackUsageFeatureAction(XPackField.VECTORS);

public static final List<XPackUsageFeatureAction> ALL = Arrays.asList(
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, SQL, ROLLUP, INDEX_LIFECYCLE, CCR, DATA_FRAME
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, SQL, ROLLUP, INDEX_LIFECYCLE, CCR, DATA_FRAME, VECTORS
);

private XPackUsageFeatureAction(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.core.vectors;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;

import java.io.IOException;

public class VectorsFeatureSetUsage extends XPackFeatureSet.Usage {

public VectorsFeatureSetUsage(StreamInput input) throws IOException {
super(input);
}

public VectorsFeatureSetUsage(boolean available, boolean enabled) {
super(XPackField.VECTORS, available, enabled);
}
}
22 changes: 22 additions & 0 deletions x-pack/plugin/vectors/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
evaluationDependsOn(xpackModule('core'))

apply plugin: 'elasticsearch.esplugin'

esplugin {
name 'vectors'
description 'A plugin for working with vectors'
classname 'org.elasticsearch.xpack.vectors.Vectors'
extendedPlugins = ['x-pack-core', 'lang-painless']
}
archivesBaseName = 'x-pack-vectors'

dependencies {
compileOnly project(':modules:lang-painless:spi')
compileOnly project(path: xpackModule('core'), configuration: 'default')
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
if (isEclipse) {
testCompile project(path: xpackModule('core-tests'), configuration: 'testArtifacts')
}
}

integTest.enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.vectors;

import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
import org.elasticsearch.xpack.vectors.mapper.DenseVectorFieldMapper;
import org.elasticsearch.xpack.vectors.mapper.SparseVectorFieldMapper;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static java.util.Collections.emptyMap;

public class Vectors extends Plugin implements MapperPlugin, ActionPlugin {

public static final String NAME = "vectors";
protected final boolean enabled;

public Vectors(Settings settings) {
this.enabled = XPackSettings.VECTORS_ENABLED.get(settings);
}

public Collection<Module> createGuiceModules() {
return Collections.singletonList(b -> {
XPackPlugin.bindFeatureSet(b, VectorsFeatureSet.class);
});
}

@Override
public List<ActionPlugin.ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Collections.singletonList(
new ActionPlugin.ActionHandler<>(XPackUsageFeatureAction.VECTORS, VectorsFeatureSet.UsageTransportAction.class));
}

@Override
public Map<String, Mapper.TypeParser> getMappers() {
if (enabled == false) {
return emptyMap();
}
Map<String, Mapper.TypeParser> mappers = new LinkedHashMap<>();
mappers.put(DenseVectorFieldMapper.CONTENT_TYPE, new DenseVectorFieldMapper.TypeParser());
mappers.put(SparseVectorFieldMapper.CONTENT_TYPE, new SparseVectorFieldMapper.TypeParser());
return Collections.unmodifiableMap(mappers);
}
}
Loading

0 comments on commit 952ddf2

Please sign in to comment.