Skip to content

Commit

Permalink
Revert "Backport distance functions vectors (#39330)" (#43233)
Browse files Browse the repository at this point in the history
This reverts commit e802842.
  • Loading branch information
mayya-sharipova authored Jun 14, 2019
1 parent 748237e commit baac41f
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 1,535 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ The following specialized API is available in the Score context.
==== Static Methods
The following methods are directly callable without a class/instance qualifier. Note parameters denoted by a (*) are treated as read-only values.

* double cosineSimilarity(List *, VectorScriptDocValues.DenseVectorScriptDocValues)
* double cosineSimilaritySparse(Map *, VectorScriptDocValues.SparseVectorScriptDocValues)
* double decayDateExp(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayDateGauss(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayDateLinear(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
Expand All @@ -21,23 +19,9 @@ The following methods are directly callable without a class/instance qualifier.
* double decayNumericExp(double *, double *, double *, double *, double)
* double decayNumericGauss(double *, double *, double *, double *, double)
* double decayNumericLinear(double *, double *, double *, double *, double)
* double dotProduct(List, VectorScriptDocValues.DenseVectorScriptDocValues)
* double dotProductSparse(Map *, VectorScriptDocValues.SparseVectorScriptDocValues)
* double randomScore(int *)
* double randomScore(int *, String *)
* double saturation(double, double)
* double sigmoid(double, double, double)

==== Classes By Package
The following classes are available grouped by their respective packages. Click on a class to view details about the available methods and fields.


==== org.elasticsearch.index.query
<<painless-api-reference-score-org-elasticsearch-index-query, Expand details for org.elasticsearch.index.query>>

* <<painless-api-reference-score-VectorScriptDocValues, VectorScriptDocValues>>
* <<painless-api-reference-score-VectorScriptDocValues-DenseVectorScriptDocValues, VectorScriptDocValues.DenseVectorScriptDocValues>>
* <<painless-api-reference-score-VectorScriptDocValues-SparseVectorScriptDocValues, VectorScriptDocValues.SparseVectorScriptDocValues>>

include::packages.asciidoc[]

This file was deleted.

2 changes: 1 addition & 1 deletion docs/reference/mapping/types/dense-vector.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ not exceed 1024. The number of dimensions can be
different across documents. A `dense_vector` field is
a single-valued field.

These vectors can be used for <<vector-functions,document scoring>>.
These vectors can be used for document scoring.
For example, a document score can represent a distance between
a given query vector and the indexed document vector.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/mapping/types/sparse-vector.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ not exceed 1024. The number of dimensions can be
different across documents. A `sparse_vector` field is
a single-valued field.

These vectors can be used for <<vector-functions,document scoring>>.
These vectors can be used for document scoring.
For example, a document score can represent a distance between
a given query vector and the indexed document vector.

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

[[vector-functions]]
===== Functions for vector fields

experimental[]

These functions are used for
for <<dense-vector,`dense_vector`>> and
<<sparse-vector,`sparse_vector`>> fields.

NOTE: During vector functions' calculation, all matched documents are
linearly scanned. Thus, expect the query time grow linearly
with the number of matched documents. For this reason, we recommend
to limit the number of matched documents with a `query` parameter.

For dense_vector fields, `cosineSimilarity` calculates the measure of
cosine similarity between a given query vector and document vectors.

[source,js]
--------------------------------------------------
{
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "cosineSimilarity(params.queryVector, doc['my_dense_vector'])",
"params": {
"queryVector": [4, 3.4, -0.2] <1>
}
}
}
}
}
--------------------------------------------------
// NOTCONSOLE
<1> To take advantage of the script optimizations, provide a query vector as a script parameter.

Similarly, for sparse_vector fields, `cosineSimilaritySparse` calculates cosine similarity
between a given query vector and document vectors.

[source,js]
--------------------------------------------------
{
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "cosineSimilaritySparse(params.queryVector, doc['my_sparse_vector'])",
"params": {
"queryVector": {"2": 0.5, "10" : 111.3, "50": -1.3, "113": 14.8, "4545": 156.0}
}
}
}
}
}
--------------------------------------------------
// NOTCONSOLE

For dense_vector fields, `dotProduct` calculates the measure of
dot product between a given query vector and document vectors.

[source,js]
--------------------------------------------------
{
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "dotProduct(params.queryVector, doc['my_dense_vector'])",
"params": {
"queryVector": [4, 3.4, -0.2]
}
}
}
}
}
--------------------------------------------------
// NOTCONSOLE

Similarly, for sparse_vector fields, `dotProductSparse` calculates dot product
between a given query vector and document vectors.

[source,js]
--------------------------------------------------
{
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "dotProductSparse(params.queryVector, doc['my_sparse_vector'])",
"params": {
"queryVector": {"2": 0.5, "10" : 111.3, "50": -1.3, "113": 14.8, "4545": 156.0}
}
}
}
}
}
--------------------------------------------------
// NOTCONSOLE

NOTE: If a document doesn't have a value for a vector field on which
a vector function is executed, 0 is returned as a result
for this document.

NOTE: If a document's dense vector field has a number of dimensions
different from the query's vector, 0 is used for missing dimensions
in the calculations of vector functions.


[[random-score-function]]
===== Random score function
`random_score` function generates scores that are uniformly distributed
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: [] }
5 changes: 0 additions & 5 deletions modules/mapper-extras/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,4 @@
esplugin {
description 'Adds advanced field mappers'
classname 'org.elasticsearch.index.mapper.MapperExtrasPlugin'
extendedPlugins = ['lang-painless']
}

dependencies {
compileOnly project(':modules:lang-painless')
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.VectorDVIndexFieldData;
import org.elasticsearch.search.DocValueFormat;

import java.io.IOException;
Expand Down Expand Up @@ -120,7 +119,8 @@ public Query existsQuery(QueryShardContext context) {

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new VectorDVIndexFieldData.Builder(true);
throw new UnsupportedOperationException(
"Field [" + name() + "] of type [" + typeName() + "] doesn't support sorting, scripting or aggregating");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.VectorDVIndexFieldData;
import org.elasticsearch.search.DocValueFormat;

import java.io.IOException;
Expand Down Expand Up @@ -120,7 +119,8 @@ public Query existsQuery(QueryShardContext context) {

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new VectorDVIndexFieldData.Builder(false);
throw new UnsupportedOperationException(
"Field [" + name() + "] of type [" + typeName() + "] doesn't support sorting, scripting or aggregating");
}

@Override
Expand Down
Loading

0 comments on commit baac41f

Please sign in to comment.