|
| 1 | +/* |
| 2 | + * @notice |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | + * contributor license agreements. See the NOTICE file distributed with |
| 5 | + * this work for additional information regarding copyright ownership. |
| 6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | + * (the "License"); you may not use this file except in compliance with |
| 8 | + * the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * Modifications copyright (C) 2024 Elasticsearch B.V. |
| 19 | + */ |
| 20 | +package org.elasticsearch.index.codec.vectors.es818; |
| 21 | + |
| 22 | +import org.apache.lucene.codecs.hnsw.FlatVectorsFormat; |
| 23 | +import org.apache.lucene.codecs.hnsw.FlatVectorsReader; |
| 24 | +import org.apache.lucene.codecs.hnsw.FlatVectorsScorer; |
| 25 | +import org.apache.lucene.codecs.hnsw.FlatVectorsWriter; |
| 26 | +import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsWriter; |
| 27 | +import org.apache.lucene.index.SegmentReadState; |
| 28 | +import org.apache.lucene.index.SegmentWriteState; |
| 29 | + |
| 30 | +import java.io.IOException; |
| 31 | + |
| 32 | +/** Copied from Lucene99FlatVectorsFormat in Lucene 10.1 */ |
| 33 | +public class ES818FlatVectorsFormat extends FlatVectorsFormat { |
| 34 | + |
| 35 | + static final String NAME = "Lucene99FlatVectorsFormat"; |
| 36 | + static final String META_CODEC_NAME = "Lucene99FlatVectorsFormatMeta"; |
| 37 | + static final String VECTOR_DATA_CODEC_NAME = "Lucene99FlatVectorsFormatData"; |
| 38 | + static final String META_EXTENSION = "vemf"; |
| 39 | + static final String VECTOR_DATA_EXTENSION = "vec"; |
| 40 | + |
| 41 | + public static final int VERSION_START = 0; |
| 42 | + public static final int VERSION_CURRENT = VERSION_START; |
| 43 | + |
| 44 | + static final int DIRECT_MONOTONIC_BLOCK_SHIFT = 16; |
| 45 | + private final FlatVectorsScorer vectorsScorer; |
| 46 | + |
| 47 | + /** Constructs a format */ |
| 48 | + public ES818FlatVectorsFormat(FlatVectorsScorer vectorsScorer) { |
| 49 | + super(NAME); |
| 50 | + this.vectorsScorer = vectorsScorer; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException { |
| 55 | + return new Lucene99FlatVectorsWriter(state, vectorsScorer); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException { |
| 60 | + return new ES818FlatVectorsReader(state, vectorsScorer); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public String toString() { |
| 65 | + return "ES818FlatVectorsFormat(" + "vectorsScorer=" + vectorsScorer + ')'; |
| 66 | + } |
| 67 | +} |
0 commit comments