I was able to update my code

-        FieldType vectorFieldType = VectorField.createHnswType(vector.length, VectorValues.SimilarityFunction.DOT_PRODUCT, 16, 500); -        VectorField vectorField = new VectorField(VECTOR_FIELD, vector, vectorFieldType); +        FieldType vectorFieldType = KnnVectorField.createFieldType(vector.length, VectorSimilarityFunction.DOT_PRODUCT); +        KnnVectorField vectorField = new KnnVectorField(VECTOR_FIELD, vector, vectorFieldType);

and

-            return new TopDocScorer(this, context.reader().searchNearestVectors(field, vector, topK, fanout)); +            return new TopDocScorer(this, context.reader().searchNearestVectors(field, vector, topK, null));

the indexing and searching works again :-)

Thanks

Michael

Am 01.11.21 um 18:53 schrieb Michael Wechner:
Hi

In May 2021 I have done a Vector Search implementation based on Lucene 
9.0.0-SNAPSHOT with the following code

FieldType vectorFieldType = VectorField.createHnswType(vector.length, 
VectorValues.SimilarityFunction.DOT_PRODUCT,16,500);
VectorField vectorField =new VectorField(VECTOR_FIELD, vector, vectorFieldType);
doc.add(vectorField)

and

class KnnWeightextends Weight {

     KnnWeight() {
         super(KnnQuery.this);
     }

     @Override public Scorer scorer(LeafReaderContext context)throws 
IOException {
         log.debug("Get scorer.");
         return new TopDocScorer(this, 
context.reader().searchNearestVectors(field,vector,topK,fanout));
     }

whereas fanout is of type "int"

I have now updated Lucene source and rebuilt 9.0.0-SNAPSHOT and get various 
compile errors.

I assume VectorField got renamed to KnnVectorField, right?

Does somebody maybe have some sample code how Vector search is being 
implemented with the most recent Lucene code?

Thanks

Michael

Reply via email to