-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Add access to dense_vector values #71313
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
Merged
mayya-sharipova
merged 13 commits into
elastic:master
from
mayya-sharipova:dense-vector-iterator
Apr 19, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0857f54
Add access to dense_vector values
mayya-sharipova 8d2e83a
Small corrections
mayya-sharipova d9dfdb1
Merge remote-tracking branch 'upstream/master' into dense-vector-iter…
mayya-sharipova 388b1f8
Address Julie's feedback
mayya-sharipova 51f509b
Address Julie's feedback 2
mayya-sharipova 6d7bd66
Merge remote-tracking branch 'upstream/master' into dense-vector-iter…
mayya-sharipova d8edd03
Address style check
mayya-sharipova a66f755
Address Julie's feedback 3
mayya-sharipova 503fdbc
Merge remote-tracking branch 'upstream/master' into dense-vector-iter…
mayya-sharipova 32a4165
Merge remote-tracking branch 'upstream/master' into dense-vector-iter…
mayya-sharipova c0fa8a9
Merge remote-tracking branch 'upstream/master' into dense-vector-iter…
mayya-sharipova 8a6d6b8
Merge remote-tracking branch 'upstream/master' into dense-vector-iter…
mayya-sharipova 116cf96
Merge branch 'master' into dense-vector-iterator
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...n/src/yamlRestTest/resources/rest-api-spec/test/vectors/30_dense_vector_script_access.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
"Access to values of dense_vector in script": | ||
- skip: | ||
version: " - 7.12.99" | ||
reason: "Access to values of dense_vector in script was added in 7.13" | ||
- do: | ||
indices.create: | ||
index: test-index | ||
body: | ||
mappings: | ||
properties: | ||
v: | ||
type: dense_vector | ||
dims: 3 | ||
|
||
- do: | ||
bulk: | ||
index: test-index | ||
refresh: true | ||
body: | ||
- '{"index": {"_id": "1"}}' | ||
- '{"v": [1, 1, 1]}' | ||
- '{"index": {"_id": "2"}}' | ||
- '{"v": [1, 1, 2]}' | ||
- '{"index": {"_id": "3"}}' | ||
- '{"v": [1, 1, 3]}' | ||
- '{"index": {"_id": "missing_vector"}}' | ||
- '{}' | ||
|
||
# vector functions in loop – return the index of the closest parameter vector based on cosine similarity | ||
- do: | ||
search: | ||
body: | ||
query: | ||
script_score: | ||
query: { "exists": { "field": "v" } } | ||
script: | ||
source: | | ||
float[] v = doc['v'].vectorValue; | ||
float vm = doc['v'].magnitude; | ||
|
||
int closestPv = 0; | ||
float maxCosSim = -1; | ||
for (int i = 0; i < params.pvs.length; i++) { | ||
float dotProduct = 0; | ||
for (int j = 0; j < v.length; j++) { | ||
dotProduct += v[j] * params.pvs[i][j]; | ||
} | ||
float cosSim = dotProduct / (vm * (float) params.pvs_magnts[i]); | ||
if (maxCosSim < cosSim) { | ||
maxCosSim = cosSim; | ||
closestPv = i; | ||
} | ||
} | ||
closestPv; | ||
params: | ||
pvs: [ [ 1, 1, 1 ], [ 1, 1, 2 ], [ 1, 1, 3 ] ] | ||
pvs_magnts: [1.7320, 2.4495, 3.3166] | ||
|
||
- match: { hits.hits.0._id: "3" } | ||
- match: { hits.hits.0._score: 2 } | ||
- match: { hits.hits.1._id: "2" } | ||
- match: { hits.hits.1._score: 1 } | ||
- match: { hits.hits.2._id: "1" } | ||
- match: { hits.hits.2._score: 0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.