Skip to content

Commit bb863b7

Browse files
committed
update to use ES logger instead of infostream
1 parent 47d4b98 commit bb863b7

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

qa/vector/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
requires org.elasticsearch.base;
1212
requires org.elasticsearch.server;
1313
requires org.elasticsearch.xcontent;
14+
requires org.elasticsearch.cli;
1415
requires org.apache.lucene.core;
1516
requires org.apache.lucene.codecs;
1617
requires org.apache.lucene.queries;

qa/vector/src/main/java/org/elasticsearch/test/knn/KnnIndexTester.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import org.apache.lucene.codecs.KnnVectorsFormat;
1616
import org.apache.lucene.codecs.lucene101.Lucene101Codec;
1717
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat;
18+
import org.elasticsearch.cli.ProcessInfo;
1819
import org.elasticsearch.common.Strings;
1920
import org.elasticsearch.common.logging.LogConfigurator;
21+
import org.elasticsearch.common.settings.Settings;
2022
import org.elasticsearch.core.PathUtils;
2123
import org.elasticsearch.index.codec.vectors.ES813Int8FlatVectorFormat;
2224
import org.elasticsearch.index.codec.vectors.ES814HnswScalarQuantizedVectorsFormat;
@@ -35,6 +37,7 @@
3537
import java.util.ArrayList;
3638
import java.util.List;
3739
import java.util.Locale;
40+
import java.util.Map;
3841

3942
/**
4043
* A utility class to create and test KNN indices using Lucene.
@@ -47,7 +50,16 @@ public class KnnIndexTester {
4750

4851
static {
4952
LogConfigurator.loadLog4jPlugins();
50-
LogConfigurator.configureESLogging(); // native access requires logging to be initialized
53+
54+
// necessary otherwise the es.logger.level system configuration in build.gradle is ignored
55+
ProcessInfo pinfo = ProcessInfo.fromSystem();
56+
Map<String, String> sysprops = pinfo.sysprops();
57+
String loggerLevel = sysprops.getOrDefault("es.logger.level", Level.INFO.name());
58+
Settings settings = Settings.builder().put("logger.level", loggerLevel).build();
59+
LogConfigurator.configureWithoutConfig(settings);
60+
61+
// native access requires logging to be initialized
62+
LogConfigurator.configureESLogging();
5163
}
5264

5365
static final String INDEX_DIR = "target/knn_index";

server/src/main/java/org/elasticsearch/index/codec/vectors/DefaultIVFVectorsWriter.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import org.apache.lucene.internal.hppc.IntArrayList;
1818
import org.apache.lucene.store.IndexInput;
1919
import org.apache.lucene.store.IndexOutput;
20-
import org.apache.lucene.util.InfoStream;
2120
import org.apache.lucene.util.VectorUtil;
2221
import org.apache.lucene.util.quantization.OptimizedScalarQuantizer;
2322
import org.elasticsearch.index.codec.vectors.cluster.HierarchicalKMeans;
2423
import org.elasticsearch.index.codec.vectors.cluster.KMeansResult;
24+
import org.elasticsearch.logging.LogManager;
25+
import org.elasticsearch.logging.Logger;
2526
import org.elasticsearch.simdvec.ES91OSQVectorsScorer;
2627

2728
import java.io.IOException;
@@ -31,14 +32,14 @@
3132
import static org.apache.lucene.codecs.lucene102.Lucene102BinaryQuantizedVectorsFormat.INDEX_BITS;
3233
import static org.apache.lucene.util.quantization.OptimizedScalarQuantizer.discretize;
3334
import static org.apache.lucene.util.quantization.OptimizedScalarQuantizer.packAsBinary;
34-
import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.IVF_VECTOR_COMPONENT;
3535

3636
/**
3737
* Default implementation of {@link IVFVectorsWriter}. It uses {@link HierarchicalKMeans} algorithm to
3838
* partition the vector space, and then stores the centroids and posting list in a sequential
3939
* fashion.
4040
*/
4141
public class DefaultIVFVectorsWriter extends IVFVectorsWriter {
42+
private static final Logger logger = LogManager.getLogger(DefaultIVFVectorsWriter.class);
4243

4344
private final int vectorPerCluster;
4445

@@ -53,7 +54,6 @@ long[] buildAndWritePostingsLists(
5354
CentroidSupplier centroidSupplier,
5455
FloatVectorValues floatVectorValues,
5556
IndexOutput postingsOutput,
56-
InfoStream infoStream,
5757
IntArrayList[] assignmentsByCluster
5858
) throws IOException {
5959
// write the posting lists
@@ -79,14 +79,14 @@ long[] buildAndWritePostingsLists(
7979
writePostingList(cluster, postingsOutput, binarizedByteVectorValues);
8080
}
8181

82-
if (infoStream.isEnabled(IVF_VECTOR_COMPONENT)) {
83-
printClusterQualityStatistics(assignmentsByCluster, infoStream);
82+
if (logger.isDebugEnabled()) {
83+
printClusterQualityStatistics(assignmentsByCluster);
8484
}
8585

8686
return offsets;
8787
}
8888

89-
private static void printClusterQualityStatistics(IntArrayList[] clusters, InfoStream infoStream) {
89+
private static void printClusterQualityStatistics(IntArrayList[] clusters) {
9090
float min = Float.MAX_VALUE;
9191
float max = Float.MIN_VALUE;
9292
float mean = 0;
@@ -105,20 +105,9 @@ private static void printClusterQualityStatistics(IntArrayList[] clusters, InfoS
105105
max = Math.max(max, cluster.size());
106106
}
107107
float variance = m2 / (clusters.length - 1);
108-
infoStream.message(
109-
IVF_VECTOR_COMPONENT,
110-
"Centroid count: "
111-
+ clusters.length
112-
+ " min: "
113-
+ min
114-
+ " max: "
115-
+ max
116-
+ " mean: "
117-
+ mean
118-
+ " stdDev: "
119-
+ Math.sqrt(variance)
120-
+ " variance: "
121-
+ variance
108+
logger.debug(
109+
"Centroid count: {} min: {} max: {} mean: {} stdDev: {} variance: {}",
110+
clusters.length, min, max, mean, Math.sqrt(variance), variance
122111
);
123112
}
124113

@@ -208,17 +197,16 @@ CentroidAssignments calculateAndWriteCentroids(
208197
float[] globalCentroid
209198
) throws IOException {
210199
// TODO: take advantage of prior generated clusters from mergeState in the future
211-
return calculateAndWriteCentroids(fieldInfo, floatVectorValues, centroidOutput, mergeState.infoStream, globalCentroid, false);
200+
return calculateAndWriteCentroids(fieldInfo, floatVectorValues, centroidOutput, globalCentroid, false);
212201
}
213202

214203
CentroidAssignments calculateAndWriteCentroids(
215204
FieldInfo fieldInfo,
216205
FloatVectorValues floatVectorValues,
217206
IndexOutput centroidOutput,
218-
InfoStream infoStream,
219207
float[] globalCentroid
220208
) throws IOException {
221-
return calculateAndWriteCentroids(fieldInfo, floatVectorValues, centroidOutput, infoStream, globalCentroid, true);
209+
return calculateAndWriteCentroids(fieldInfo, floatVectorValues, centroidOutput, globalCentroid, true);
222210
}
223211

224212
/**
@@ -228,7 +216,6 @@ CentroidAssignments calculateAndWriteCentroids(
228216
* @param fieldInfo merging field info
229217
* @param floatVectorValues the float vector values to merge
230218
* @param centroidOutput the centroid output
231-
* @param infoStream the merge state
232219
* @param globalCentroid the global centroid, calculated by this method and used to quantize the centroids
233220
* @param cacheCentroids whether the centroids are kept or discarded once computed
234221
* @return the vector assignments, soar assignments, and if asked the centroids themselves that were computed
@@ -238,7 +225,6 @@ CentroidAssignments calculateAndWriteCentroids(
238225
FieldInfo fieldInfo,
239226
FloatVectorValues floatVectorValues,
240227
IndexOutput centroidOutput,
241-
InfoStream infoStream,
242228
float[] globalCentroid,
243229
boolean cacheCentroids
244230
) throws IOException {
@@ -266,12 +252,9 @@ CentroidAssignments calculateAndWriteCentroids(
266252
// write centroids
267253
writeCentroids(centroids, fieldInfo, globalCentroid, centroidOutput);
268254

269-
if (infoStream.isEnabled(IVF_VECTOR_COMPONENT)) {
270-
infoStream.message(
271-
IVF_VECTOR_COMPONENT,
272-
"calculate centroids and assign vectors time ms: " + ((System.nanoTime() - nanoTime) / 1000000.0)
273-
);
274-
infoStream.message(IVF_VECTOR_COMPONENT, "final centroid count: " + centroids.length);
255+
if (logger.isDebugEnabled()) {
256+
logger.debug("calculate centroids and assign vectors time ms: {}", (System.nanoTime() - nanoTime) / 1000000.0);
257+
logger.debug("final centroid count: {}", centroids.length);
275258
}
276259

277260
IntArrayList[] assignmentsByCluster = new IntArrayList[centroids.length];

server/src/main/java/org/elasticsearch/index/codec/vectors/IVFVectorsFormat.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
*/
4646
public class IVFVectorsFormat extends KnnVectorsFormat {
4747

48-
public static final String IVF_VECTOR_COMPONENT = "IVF";
4948
public static final String NAME = "IVFVectorsFormat";
5049
// centroid ordinals -> centroid values, offsets
5150
public static final String CENTROID_EXTENSION = "cenivf";

server/src/main/java/org/elasticsearch/index/codec/vectors/IVFVectorsWriter.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.lucene.store.IOContext;
2929
import org.apache.lucene.store.IndexInput;
3030
import org.apache.lucene.store.IndexOutput;
31-
import org.apache.lucene.util.InfoStream;
3231
import org.apache.lucene.util.VectorUtil;
3332
import org.elasticsearch.core.IOUtils;
3433
import org.elasticsearch.core.SuppressForbidden;
@@ -134,7 +133,6 @@ abstract CentroidAssignments calculateAndWriteCentroids(
134133
FieldInfo fieldInfo,
135134
FloatVectorValues floatVectorValues,
136135
IndexOutput centroidOutput,
137-
InfoStream infoStream,
138136
float[] globalCentroid
139137
) throws IOException;
140138

@@ -143,7 +141,6 @@ abstract long[] buildAndWritePostingsLists(
143141
CentroidSupplier centroidSupplier,
144142
FloatVectorValues floatVectorValues,
145143
IndexOutput postingsOutput,
146-
InfoStream infoStream,
147144
IntArrayList[] assignmentsByCluster
148145
) throws IOException;
149146

@@ -168,7 +165,6 @@ public final void flush(int maxDoc, Sorter.DocMap sortMap) throws IOException {
168165
fieldWriter.fieldInfo,
169166
floatVectorValues,
170167
ivfCentroids,
171-
segmentWriteState.infoStream,
172168
globalCentroid
173169
);
174170

@@ -180,7 +176,6 @@ public final void flush(int maxDoc, Sorter.DocMap sortMap) throws IOException {
180176
centroidSupplier,
181177
floatVectorValues,
182178
ivfClusters,
183-
segmentWriteState.infoStream,
184179
centroidAssignments.assignmentsByCluster()
185180
);
186181
// write posting lists
@@ -313,7 +308,6 @@ public final void mergeOneField(FieldInfo fieldInfo, MergeState mergeState) thro
313308
centroidSupplier,
314309
floatVectorValues,
315310
ivfClusters,
316-
mergeState.infoStream,
317311
centroidAssignments.assignmentsByCluster()
318312
);
319313
assert offsets.length == centroidSupplier.size();

0 commit comments

Comments
 (0)