Skip to content

Commit e39b14a

Browse files
committed
Copy Lucene99FlatVectorsReader allowing direct IO to be specified directly
1 parent d84eb1f commit e39b14a

File tree

5 files changed

+444
-3
lines changed

5 files changed

+444
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.index.codec.vectors.es818;
11+
12+
import org.apache.lucene.store.IOContext;
13+
import org.apache.lucene.store.IndexInput;
14+
15+
import java.io.IOException;
16+
17+
/**
18+
* A hook for {@link ES818FlatVectorsReader} to specify the input should be opened using DirectIO.
19+
* Remove when IOContext allows more extensible payloads to be specified.
20+
*/
21+
public interface DirectIODirectory {
22+
IndexInput openInputDirect(String name, IOContext context) throws IOException;
23+
}

server/src/main/java/org/elasticsearch/index/codec/vectors/es818/ES818BinaryQuantizedVectorsFormat.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.lucene.codecs.hnsw.FlatVectorsFormat;
2424
import org.apache.lucene.codecs.hnsw.FlatVectorsReader;
2525
import org.apache.lucene.codecs.hnsw.FlatVectorsWriter;
26-
import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsFormat;
2726
import org.apache.lucene.index.SegmentReadState;
2827
import org.apache.lucene.index.SegmentWriteState;
2928

@@ -97,7 +96,7 @@ public class ES818BinaryQuantizedVectorsFormat extends FlatVectorsFormat {
9796
static final String VECTOR_DATA_EXTENSION = "veb";
9897
static final int DIRECT_MONOTONIC_BLOCK_SHIFT = 16;
9998

100-
private static final FlatVectorsFormat rawVectorFormat = new Lucene99FlatVectorsFormat(
99+
private static final ES818FlatVectorsFormat rawVectorFormat = new ES818FlatVectorsFormat(
101100
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
102101
);
103102

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)