risdenk commented on code in PR #1255:
URL: https://github.com/apache/solr/pull/1255#discussion_r1061858513
##########
solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java:
##########
@@ -124,18 +124,18 @@ public KnnVectorsFormat
getKnnVectorsFormatForField(String field) {
if (fieldType instanceof DenseVectorField) {
DenseVectorField vectorType = (DenseVectorField) fieldType;
String knnAlgorithm = vectorType.getKnnAlgorithm();
- if (knnAlgorithm != null) {
- if (knnAlgorithm.equals(DenseVectorField.HNSW_ALGORITHM)) {
- int maxConn = vectorType.getHnswMaxConn();
- int beamWidth = vectorType.getHnswBeamWidth();
- return new Lucene94HnswVectorsFormat(maxConn, beamWidth);
- }
+ if (knnAlgorithm.equals(DenseVectorField.HNSW_ALGORITHM)) {
Review Comment:
nit the following will avoid any NPE if `knnAlgorithm` is ever null.:
```suggestion
if (DenseVectorField.HNSW_ALGORITHM.equals(knnAlgorithm)) {
```
##########
solr/core/src/java/org/apache/solr/schema/DenseVectorField.java:
##########
@@ -104,7 +106,7 @@ public void init(IndexSchema schema, Map<String, String>
args) {
.orElse(DEFAULT_SIMILARITY);
args.remove(KNN_SIMILARITY_FUNCTION);
- this.knnAlgorithm = args.get(KNN_ALGORITHM);
+ this.knnAlgorithm =
Optional.ofNullable(args.get(KNN_ALGORITHM)).orElse(DEFAULT_KNN_ALGORITHM);
Review Comment:
use getOrDefault?
https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#getOrDefault-java.lang.Object-V-
```suggestion
this.knnAlgorithm = args.getOrDefault(KNN_ALGORITHM,
DEFAULT_KNN_ALGORITHM);
```
##########
solr/core/src/java/org/apache/solr/schema/DenseVectorField.java:
##########
@@ -104,7 +106,7 @@ public void init(IndexSchema schema, Map<String, String>
args) {
.orElse(DEFAULT_SIMILARITY);
args.remove(KNN_SIMILARITY_FUNCTION);
- this.knnAlgorithm = args.get(KNN_ALGORITHM);
+ this.knnAlgorithm =
Optional.ofNullable(args.get(KNN_ALGORITHM)).orElse(DEFAULT_KNN_ALGORITHM);
Review Comment:
This should cleanup the imports too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]