Hi there,
I'm using solr 9.1 to implement dense vector search using the documentation
at
https://solr.apache.org/guide/solr/latest/query-guide/dense-vector-search.html

According to the guide, a valid fieldType configuration is:

<fieldType name="knn_vector" class="solr.DenseVectorField"
vectorDimension="4" similarityFunction="cosine"/>

Using the schema API, I added the following configuration:
$ grep knn_vector managed-schema.xml
  <fieldType name="knn_vector" class="solr.DenseVectorField"
vectorDimension="4" similarityFunction="euclidean"/>
  <field name="vector" type="knn_vector" multiValued="false" stored="true"/>

However, when I try to submit a document containing a vector to the server,
an error occurs:
(truncated traceback):
2022-12-13 19:10:08.763 ERROR (qtp3540494-54) [ x:fsnn]
o.a.s.s.HttpSolrCall org.apache.solr.common.SolrException: null KNN
algorithm is not supported => org.apache.solr.common.SolrException: null
KNN algorithm is not supported
at
org.apache.solr.core.SchemaCodecFactory$1.getKnnVectorsFormatForField(SchemaCodecFactory.java:134)
org.apache.solr.common.SolrException: null KNN algorithm is not supported
at
org.apache.solr.core.SchemaCodecFactory$1.getKnnVectorsFormatForField(SchemaCodecFactory.java:134)
~[?:?]
at
org.apache.lucene.codecs.lucene92.Lucene92Codec$3.getKnnVectorsFormatForField(Lucene92Codec.java:101)
~[?:?]
at
org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat$FieldsWriter.getInstance(PerFieldKnnVectorsFormat.java:148)
~[?:?]
at
org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat$FieldsWriter.writeField(PerFieldKnnVectorsFormat.java:107)
~[?:?]
at
org.apache.lucene.index.VectorValuesWriter.flush(VectorValuesWriter.java:145)
~[?:?]
at
org.apache.lucene.index.IndexingChain.writeVectors(IndexingChain.java:461)
~[?:?]

After having a dig through the source, I found
https://github.com/apache/solr/pull/910 which added this check. I note that
the documentation about dense vector search does describe the knnAlgorithm
parameter, but says that it is optional with a default value of "hnsw".
It seems that the patch changed the behaviour of this check to raise an
error if the knnAlgorithm is null/missing, rather than only if the value
isn't the expected "hnsw".

If I update the fieldType in the schema to include the knnAlgorithm,
hnswMaxConnections, and hnswBeamWidth parameters then I am able to
successfully index and search on this field.

Does this appear to be a bug in the code? Or if the parameter is expected
to always be set, perhaps a bug in the documentation.

Thanks,
Alastair

Reply via email to