cpoerschke commented on code in PR #13525: URL: https://github.com/apache/lucene/pull/13525#discussion_r1664079407
########## lucene/core/src/java/org/apache/lucene/codecs/KnnTensorsFormat.java: ########## @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.codecs; + +import java.io.IOException; +import org.apache.lucene.index.ByteVectorValues; +import org.apache.lucene.index.FloatVectorValues; +import org.apache.lucene.index.SegmentReadState; +import org.apache.lucene.index.SegmentWriteState; +import org.apache.lucene.search.KnnCollector; +import org.apache.lucene.util.Bits; +import org.apache.lucene.util.NamedSPILoader; + +/** + * Encodes/decodes per-document tensors and any associated indexing structures required to support + * nearest-neighbor search + */ +public abstract class KnnTensorsFormat implements NamedSPILoader.NamedSPI { + + /** The maximum number of dimensions supported for each vector in the tensor */ + public static final int DEFAULT_MAX_DIMENSIONS = 1024; + + /** The maximum rank supported for each tensor */ + public static final int DEFAULT_MAX_RANK = 2; + + /** + * This static holder class prevents classloading deadlock by delaying init of doc values formats + * until needed. + */ + private static final class Holder { + private static final NamedSPILoader<KnnTensorsFormat> LOADER = + new NamedSPILoader<>(KnnTensorsFormat.class); + + private Holder() {} + + static NamedSPILoader<KnnTensorsFormat> getLoader() { + if (LOADER == null) { + throw new IllegalStateException( + "You tried to lookup a KnnTensorsFormat name before all formats could be initialized. " + + "This likely happens if you call KnnTensorsFormat#forName from a KnnTensorsFormat's ctor."); + } + return LOADER; + } + } + + private final String name; + + /** Sole constructor */ + protected KnnTensorsFormat(String name) { + NamedSPILoader.checkServiceName(name); + this.name = name; + } + + @Override + public String getName() { + return name; + } + + /** looks up a format by name */ + public static KnnTensorsFormat forName(String name) { + return Holder.getLoader().lookup(name); + } Review Comment: minor: noting that https://github.com/apache/lucene/blob/releases/lucene/9.11.1/lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java#L72-L93 also has `reloadKnnVectorsFormat` and `availableKnnVectorsFormats` but perhaps they aren't applicable here as yet? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org