You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ab...@apache.org on 2023/01/09 12:05:17 UTC
[solr] branch branch_9x updated: SOLR-16588: set default knn algorithm (#1255)
This is an automated email from the ASF dual-hosted git repository.
abenedetti pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new db6218d0fe1 SOLR-16588: set default knn algorithm (#1255)
db6218d0fe1 is described below
commit db6218d0fe1c34da57d2d753d5e5bece6244961a
Author: Alessandro Benedetti <a....@sease.io>
AuthorDate: Mon Jan 9 12:33:21 2023 +0100
SOLR-16588: set default knn algorithm (#1255)
Co-authored-by: Elia <e....@sease.io>
Co-authored-by: Kevin Risden <ri...@users.noreply.github.com>
---
solr/CHANGES.txt | 2 ++
.../src/java/org/apache/solr/core/SchemaCodecFactory.java | 14 +++++++-------
.../src/java/org/apache/solr/schema/DenseVectorField.java | 3 ++-
.../test/org/apache/solr/schema/DenseVectorFieldTest.java | 3 ++-
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 6b64b3dccb4..137f3334f66 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -197,6 +197,8 @@ Bug Fixes
* SOLR-16165: Rare Deadlock in SlotAcc initialization (Justin Sweeney, noble)
+* SOLR-16588: Fixed problem with default knn algorithm (Elia Porciani via Alessandro Benedetti)
+
================== 9.1.0 ==================
New Features
diff --git a/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java b/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java
index df533b20900..45e8332a0b5 100644
--- a/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java
@@ -124,18 +124,18 @@ public class SchemaCodecFactory extends CodecFactory implements SolrCoreAware {
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 (DenseVectorField.HNSW_ALGORITHM.equals(knnAlgorithm)) {
+ int maxConn = vectorType.getHnswMaxConn();
+ int beamWidth = vectorType.getHnswBeamWidth();
+ return new Lucene94HnswVectorsFormat(maxConn, beamWidth);
} else {
throw new SolrException(
ErrorCode.SERVER_ERROR, knnAlgorithm + " KNN algorithm is not supported");
}
}
- return super.getKnnVectorsFormatForField(field);
+
+ throw new SolrException(
+ ErrorCode.SERVER_ERROR, "wrong field type for KNN vectors: " + fieldType);
}
};
}
diff --git a/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java b/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
index 6a9e77c9c9b..e41bc161dda 100644
--- a/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
+++ b/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
@@ -47,6 +47,7 @@ import org.apache.solr.uninverting.UninvertingReader;
public class DenseVectorField extends FloatPointField {
public static final String HNSW_ALGORITHM = "hnsw";
+ public static final String DEFAULT_KNN_ALGORITHM = HNSW_ALGORITHM;
static final String KNN_VECTOR_DIMENSION = "vectorDimension";
static final String KNN_SIMILARITY_FUNCTION = "similarityFunction";
@@ -104,7 +105,7 @@ public class DenseVectorField extends FloatPointField {
.orElse(DEFAULT_SIMILARITY);
args.remove(KNN_SIMILARITY_FUNCTION);
- this.knnAlgorithm = args.get(KNN_ALGORITHM);
+ this.knnAlgorithm = args.getOrDefault(KNN_ALGORITHM, DEFAULT_KNN_ALGORITHM);
args.remove(KNN_ALGORITHM);
diff --git a/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java b/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
index 46f3541551f..ad9ab23f073 100644
--- a/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
@@ -144,6 +144,7 @@ public class DenseVectorFieldTest extends AbstractBadConfigTestBase {
DenseVectorField type3 = (DenseVectorField) vector3.getType();
MatcherAssert.assertThat(type3.getSimilarityFunction(), is(VectorSimilarityFunction.COSINE));
MatcherAssert.assertThat(type3.getDimension(), is(5));
+
MatcherAssert.assertThat(type3.getKnnAlgorithm(), is("hnsw"));
MatcherAssert.assertThat(type3.getHnswMaxConn(), is(8));
MatcherAssert.assertThat(type3.getHnswBeamWidth(), is(46));
@@ -154,8 +155,8 @@ public class DenseVectorFieldTest extends AbstractBadConfigTestBase {
DenseVectorField typeDefault = (DenseVectorField) vectorDefault.getType();
MatcherAssert.assertThat(
typeDefault.getSimilarityFunction(), is(VectorSimilarityFunction.COSINE));
+ MatcherAssert.assertThat(typeDefault.getKnnAlgorithm(), is("hnsw"));
MatcherAssert.assertThat(typeDefault.getDimension(), is(4));
- assertNull(typeDefault.getKnnAlgorithm());
MatcherAssert.assertThat(typeDefault.getHnswMaxConn(), is(16));
MatcherAssert.assertThat(typeDefault.getHnswBeamWidth(), is(100));
} finally {