Commit b44fcfb
authored
Script: Fields API for Dense Vector (#83550)
Adds the fields API for `dense_vector` field mapper.
Adds a `DenseVector` interface for the value type.
Implemented by:
* `KnnDenseVector` which wraps a decoded float array from `VectorValues`
* `BinaryDenseVector` which lazily decodes a `BytesRef` from `BinaryDocValues`
The vector operations have moved into those implements from `BinaryDenseVectorScriptDocValues.java` and `KnnDenseVectorScriptDocValues.java`, respectively.
The `DenseVector` API is:
```
float getMagnitude();
double dotProduct(float[] | List);
double l1Norm(float[] | List);
double l2Norm(float[] | List);
float[] getVector();
int dims();
boolean isEmpty(); // does the value exist
int size(); // 0 if isEmpty(), 1 otherwise
Iterator<Float> iterator()
```
`dotProduct`, `l1Norm` and `l2Norm` take a `float[]` or a `List` via the
a delegating `default` method on the `DenseVector` interface.
The `DenseVectorDocValuesField` abstract class contains two getter APIS.
It is implemented by `KnnDenseVectorDocValuesField` and
`BinaryDenseVectorDocValuesField`.
```
DenseVector get()
DenseVector get(DenseVector defaultValue)
```
The `get()` method is included because there isn't a good default dense vector,
so that API returns an empty `DenseVector` which throws an
`IllegalArgumentException` for all method calls other than `isEmpty()`,
`size()` and `iterator()`.
The empty dense vector will always be `DenseVector.EMPTY` in case users want
to use equality checks.
Refs: #791051 parent e7ca532 commit b44fcfb
19 files changed
Lines changed: 1883 additions & 390 deletions
File tree
- docs/changelog
- x-pack/plugin
- src/yamlRestTest/resources/rest-api-spec/test/vectors
- vectors/src
- main
- java/org/elasticsearch/xpack/vectors/query
- resources/org/elasticsearch/xpack/vectors/query
- test/java/org/elasticsearch/xpack/vectors/query
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments