Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the signature of vector script functions. #48260

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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 cosineSimilarity(List *, String *)
* double cosineSimilaritySparse(Map *, String *)
* double decayDateExp(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayDateGauss(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayDateLinear(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
Expand All @@ -21,8 +21,8 @@ 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 dotProduct(List, String *)
* double dotProductSparse(Map *, String *)
* double randomScore(int *)
* double randomScore(int *, String *)
* double saturation(double, double)
Expand Down
16 changes: 8 additions & 8 deletions docs/reference/vectors/vector-functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ GET my_index/_search
}
},
"script": {
"source": "cosineSimilarity(params.query_vector, doc['my_dense_vector']) + 1.0", <2>
"source": "cosineSimilarity(params.query_vector, 'my_dense_vector') + 1.0", <2>
"params": {
"query_vector": [4, 3.4, -0.2] <3>
}
Expand Down Expand Up @@ -105,7 +105,7 @@ GET my_index/_search
},
"script": {
"source": """
double value = dotProduct(params.query_vector, doc['my_dense_vector']);
double value = dotProduct(params.query_vector, 'my_dense_vector');
return sigmoid(1, Math.E, -value); <1>
""",
"params": {
Expand Down Expand Up @@ -139,7 +139,7 @@ GET my_index/_search
}
},
"script": {
"source": "1 / (1 + l1norm(params.queryVector, doc['my_dense_vector']))", <1>
"source": "1 / (1 + l1norm(params.queryVector, 'my_dense_vector'))", <1>
"params": {
"queryVector": [4, 3.4, -0.2]
}
Expand Down Expand Up @@ -178,7 +178,7 @@ GET my_index/_search
}
},
"script": {
"source": "1 / (1 + l2norm(params.queryVector, doc['my_dense_vector']))",
"source": "1 / (1 + l2norm(params.queryVector, 'my_dense_vector'))",
"params": {
"queryVector": [4, 3.4, -0.2]
}
Expand Down Expand Up @@ -262,7 +262,7 @@ GET my_sparse_index/_search
}
},
"script": {
"source": "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector']) + 1.0",
"source": "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector') + 1.0",
"params": {
"query_vector": {"2": 0.5, "10" : 111.3, "50": -1.3, "113": 14.8, "4545": 156.0}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ GET my_sparse_index/_search
},
"script": {
"source": """
double value = dotProductSparse(params.query_vector, doc['my_sparse_vector']);
double value = dotProductSparse(params.query_vector, 'my_sparse_vector');
return sigmoid(1, Math.E, -value);
""",
"params": {
Expand Down Expand Up @@ -327,7 +327,7 @@ GET my_sparse_index/_search
}
},
"script": {
"source": "1 / (1 + l1normSparse(params.queryVector, doc['my_sparse_vector']))",
"source": "1 / (1 + l1normSparse(params.queryVector, 'my_sparse_vector'))",
"params": {
"queryVector": {"2": 0.5, "10" : 111.3, "50": -1.3, "113": 14.8, "4545": 156.0}
}
Expand Down Expand Up @@ -358,7 +358,7 @@ GET my_sparse_index/_search
}
},
"script": {
"source": "1 / (1 + l2normSparse(params.queryVector, doc['my_sparse_vector']))",
"source": "1 / (1 + l2normSparse(params.queryVector, 'my_sparse_vector'))",
"params": {
"queryVector": {"2": 0.5, "10" : 111.3, "50": -1.3, "113": 14.8, "4545": 156.0}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Map<String, Object> getParams() {
}

/** The doc lookup for the Lucene segment this script was created for. */
public final Map<String, ScriptDocValues<?>> getDoc() {
public Map<String, ScriptDocValues<?>> getDoc() {
return leafLookup.doc();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "dotProduct(params.query_vector, doc['my_dense_vector'])"
source: "dotProduct(params.query_vector, 'my_dense_vector')"
params:
query_vector: [0.5, 111.3, -13.0, 14.8, -156.0]

Expand Down Expand Up @@ -82,7 +82,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilarity(params.query_vector, doc['my_dense_vector'])"
source: "cosineSimilarity(params.query_vector, 'my_dense_vector')"
params:
query_vector: [0.5, 111.3, -13.0, 14.8, -156.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "l1norm(params.query_vector, doc['my_dense_vector'])"
source: "l1norm(params.query_vector, 'my_dense_vector')"
params:
query_vector: [0.5, 111.3, -13.0, 14.8, -156.0]

Expand Down Expand Up @@ -83,7 +83,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "l2norm(params.query_vector, doc['my_dense_vector'])"
source: "l2norm(params.query_vector, 'my_dense_vector')"
params:
query_vector: [0.5, 111.3, -13.0, 14.8, -156.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilarity(params.query_vector, doc['my_dense_vector'])"
source: "cosineSimilarity(params.query_vector, 'my_dense_vector')"
params:
query_vector: [10, 10, 10]

Expand All @@ -81,7 +81,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilarity(params.query_vector, doc['my_dense_vector'])"
source: "cosineSimilarity(params.query_vector, 'my_dense_vector')"
params:
query_vector: [10.0, 10.0, 10.0]

Expand Down Expand Up @@ -111,7 +111,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilarity(params.query_vector, doc['my_dense_vector'])"
source: "cosineSimilarity(params.query_vector, 'my_dense_vector')"
params:
query_vector: [1, 2, 3, 4]
- match: { error.root_cause.0.type: "script_exception" }
Expand All @@ -125,7 +125,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "dotProduct(params.query_vector, doc['my_dense_vector'])"
source: "dotProduct(params.query_vector, 'my_dense_vector')"
params:
query_vector: [1, 2, 3, 4]
- match: { error.root_cause.0.type: "script_exception" }
Expand Down Expand Up @@ -161,7 +161,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilarity(params.query_vector, doc['my_dense_vector'])"
source: "cosineSimilarity(params.query_vector, 'my_dense_vector')"
params:
query_vector: [10.0, 10.0, 10.0]
- match: { error.root_cause.0.type: "script_exception" }
Expand All @@ -177,7 +177,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "doc['my_dense_vector'].size() == 0 ? 0 : cosineSimilarity(params.query_vector, doc['my_dense_vector'])"
source: "doc['my_dense_vector'].size() == 0 ? 0 : cosineSimilarity(params.query_vector, 'my_dense_vector')"
params:
query_vector: [10.0, 10.0, 10.0]

Expand Down Expand Up @@ -209,7 +209,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "dotProductSparse(params.query_vector, doc['my_dense_vector'])"
source: "dotProductSparse(params.query_vector, 'my_dense_vector')"
params:
query_vector: {"2": 0.5, "10" : 111.3, "3": 44}
- match: { error.root_cause.0.type: "script_exception" }
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "dotProductSparse(params.query_vector, doc['my_sparse_vector'])"
source: "dotProductSparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"2": 0.5, "10" : 111.3, "50": -13.0, "113": 14.8, "4545": -156.0}

Expand Down Expand Up @@ -87,7 +87,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"2": -0.5, "10" : 111.3, "50": -13.0, "113": 14.8, "4545": -156.0}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "l1normSparse(params.query_vector, doc['my_sparse_vector'])"
source: "l1normSparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"2": 0.5, "10" : 111.3, "50": -13.0, "113": 14.8, "4545": -156.0}

Expand Down Expand Up @@ -88,7 +88,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "l2normSparse(params.query_vector, doc['my_sparse_vector'])"
source: "l2normSparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"2": 0.5, "10" : 111.3, "50": -13.0, "113": 14.8, "4545": -156.0}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10}

Expand All @@ -83,7 +83,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10.0}

Expand Down Expand Up @@ -127,7 +127,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10.0}
- match: { error.root_cause.0.type: "script_exception" }
Expand All @@ -145,7 +145,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "doc['my_sparse_vector'].size() == 0 ? 0 : cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "doc['my_sparse_vector'].size() == 0 ? 0 : cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10.0}

Expand Down Expand Up @@ -194,7 +194,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"100": -200.0, "11" : 300.33, "12": -34.8988, "2": 230.0, "30": 15.555}

Expand Down Expand Up @@ -230,7 +230,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "dotProduct(params.query_vector, doc['my_sparse_vector'])"
source: "dotProduct(params.query_vector, 'my_sparse_vector')"
params:
query_vector: [0.5, 111]
- match: { error.root_cause.0.type: "script_exception" }
Expand Down Expand Up @@ -273,7 +273,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "dotProductSparse(params.query_vector, doc['my_sparse_vector'])"
source: "dotProductSparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10, "5": 5}

Expand Down Expand Up @@ -304,7 +304,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "cosineSimilaritySparse(params.query_vector, doc['my_sparse_vector'])"
source: "cosineSimilaritySparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10, "5" : 5}

Expand Down Expand Up @@ -334,7 +334,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "l1normSparse(params.query_vector, doc['my_sparse_vector'])"
source: "l1normSparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10, "5": 5}

Expand All @@ -361,7 +361,7 @@ setup:
script_score:
query: {match_all: {} }
script:
source: "l2normSparse(params.query_vector, doc['my_sparse_vector'])"
source: "l2normSparse(params.query_vector, 'my_sparse_vector')"
params:
query_vector: {"1": 10, "5": 5}

Expand Down
Loading