2929import org .apache .lucene .store .IndexInput ;
3030import org .apache .lucene .util .BitSet ;
3131import org .apache .lucene .util .Bits ;
32- import org .apache .lucene .util .IOFunction ;
3332import org .elasticsearch .core .IOUtils ;
3433import org .elasticsearch .search .vectors .IVFKnnSearchStrategy ;
3534
3635import java .io .Closeable ;
3736import java .io .IOException ;
3837import java .util .ArrayList ;
3938import java .util .Collections ;
40- import java .util .HashMap ;
4139import java .util .List ;
4240import java .util .Map ;
4341
@@ -53,11 +51,10 @@ public abstract class IVFVectorsReader extends KnnVectorsReader {
5351 private final SegmentReadState state ;
5452 private final FieldInfos fieldInfos ;
5553 protected final IntObjectHashMap <FieldEntry > fields ;
56- private final IOFunction <String , FlatVectorsReader > rawVectorReaders ;
57- private final Map <String , FlatVectorsReader > loadedReaders = new HashMap <>();
54+ private final Map <String , FlatVectorsReader > rawVectorReaders ;
5855
5956 @ SuppressWarnings ("this-escape" )
60- protected IVFVectorsReader (SegmentReadState state , IOFunction <String , FlatVectorsReader > rawVectorReaders ) throws IOException {
57+ protected IVFVectorsReader (SegmentReadState state , Map <String , FlatVectorsReader > rawVectorReaders ) throws IOException {
6158 this .state = state ;
6259 this .fieldInfos = state .fieldInfos ;
6360 this .fields = new IntObjectHashMap <>();
@@ -222,20 +219,19 @@ private static VectorEncoding readVectorEncoding(DataInput input) throws IOExcep
222219
223220 @ Override
224221 public final void checkIntegrity () throws IOException {
225- for (var reader : loadedReaders .values ()) {
222+ for (var reader : rawVectorReaders .values ()) {
226223 reader .checkIntegrity ();
227224 }
228225 CodecUtil .checksumEntireFile (ivfCentroids );
229226 CodecUtil .checksumEntireFile (ivfClusters );
230227 }
231228
232- private synchronized FlatVectorsReader getReaderForField (String field ) throws IOException {
229+ private FlatVectorsReader getReaderForField (String field ) {
233230 String formatName = fields .get (fieldInfos .fieldInfo (field ).number ).rawVectorFormatName ;
234- FlatVectorsReader reader = loadedReaders .get (formatName );
235- if (reader == null ) {
236- reader = rawVectorReaders .apply (formatName );
237- loadedReaders .put (formatName , reader );
238- }
231+ FlatVectorsReader reader = rawVectorReaders .get (formatName );
232+ if (reader == null ) throw new IllegalArgumentException (
233+ "Could not find raw vector format [" + formatName + "] for field [" + field + "]"
234+ );
239235 return reader ;
240236 }
241237
@@ -343,7 +339,7 @@ public final void search(String field, byte[] target, KnnCollector knnCollector,
343339
344340 @ Override
345341 public void close () throws IOException {
346- List <Closeable > closeables = new ArrayList <>(loadedReaders .values ());
342+ List <Closeable > closeables = new ArrayList <>(rawVectorReaders .values ());
347343 Collections .addAll (closeables , ivfCentroids , ivfClusters );
348344 IOUtils .close (closeables );
349345 }
0 commit comments