Skip to content

Commit

Permalink
Fix NPE in dense_vector stats (#112720) (#112722)
Browse files Browse the repository at this point in the history
If a segment doesn't contain any documents with a dense_vector field, 
but the mapping defines it, an NPE can occur when retrieving the
dense_vector stats.

Relates #111729
  • Loading branch information
dnhatn authored Sep 10, 2024
1 parent 00f2058 commit 8080aac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/112720.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 112720
summary: Fix NPE in `dense_vector` stats
area: Vector Search
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@
---
"Dense vector stats":
- requires:
cluster_features: [ "gte_v8.15.0" ]
reason: "dense vector stats reports from primary indices in 8.15"
cluster_features: [ "gte_v8.16.0" ]
reason: "dense vector stats reports from primary indices in 8.15 and fixed in 8.16"
- do:
indices.create:
index: test1
Expand Down Expand Up @@ -329,9 +329,17 @@
- do:
indices.refresh: { }

- do:
index:
index: test2
id: "3"
refresh: true
body:
not_vector_field: "not vector"

- do: { cluster.stats: { } }

- match: { indices.docs.count: 4 }
- match: { indices.docs.count: 5 }
- match: { indices.docs.deleted: 0 }
- match: { indices.dense_vector.value_count: 8 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private long getDenseVectorValueCount(final LeafReader atomicReader, List<String
long count = 0;
for (var field : fields) {
var info = atomicReader.getFieldInfos().fieldInfo(field);
if (info.getVectorDimension() > 0) {
if (info != null && info.getVectorDimension() > 0) {
switch (info.getVectorEncoding()) {
case FLOAT32 -> {
FloatVectorValues values = atomicReader.getFloatVectorValues(info.name);
Expand Down

0 comments on commit 8080aac

Please sign in to comment.