Dear all,

when indexing vector fields, Lucene doesn't allow specifying the vector
field as stored (it throws `IllegalStateException: Cannot store value of
type class [F`). When trying to retrieve the value using
`IndexReader.storedFields()`, the vector field isn't stored.

However, Lucene 10 stores the vectors in `.vec` files. I was able to
retrieve them using this complicated code, for which I had to make the
`readerIndex` and `readerBase` methods in `BaseCompositeReader` public
(they are protected):

    int docId = ...; // the docId to retrieve, e.g. coming out of a search
    IndexReader node = reader.getContext().reader();
    while (node instanceof BaseCompositeReader) {
      int index = ((BaseCompositeReader) node).readerIndex(docId);
      int base = ((BaseCompositeReader) node).readerBase(index);
      docId -= base;
      node = ((BaseCompositeReader)
node).getContext().children().get(index).reader();
    }
    assert node instanceof LeafReader;
    assert node.leaves().size() == 1;
    FloatVectorValues vectorValues =

node.leaves().getFirst().reader().getFloatVectorValues("myVectorField");
    float[] vector = vectorValues.vectorValue(docId);

My reader is a `MultiReader`, composed of multiple `DirectoryReader`s.

Is there any public API to retrieve the vector values? If not, is there any
particular reason to not make the vectors available, if Lucene stores them
anyway? Even if the vectors are quantized, original raw vectors are stored,
though they are never used.

Thanks,
Viliam

Reply via email to