Skip to content

Commit 2e815fe

Browse files
committed
Add a basic generic HNSW implementation
1 parent 69f52cb commit 2e815fe

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.es93;
11+
12+
import org.apache.lucene.codecs.KnnVectorsReader;
13+
import org.apache.lucene.codecs.KnnVectorsWriter;
14+
import org.apache.lucene.codecs.hnsw.FlatVectorsFormat;
15+
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsReader;
16+
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsWriter;
17+
import org.apache.lucene.index.SegmentReadState;
18+
import org.apache.lucene.index.SegmentWriteState;
19+
import org.elasticsearch.index.codec.vectors.AbstractHnswVectorsFormat;
20+
21+
import java.io.IOException;
22+
23+
public class ES93HnswVectorsFormat extends AbstractHnswVectorsFormat {
24+
25+
static final String NAME = "ES93HnswVectorsFormat";
26+
27+
private final FlatVectorsFormat flatVectorsFormat;
28+
29+
public ES93HnswVectorsFormat() {
30+
super(NAME);
31+
flatVectorsFormat = new ES93GenericFlatVectorsFormat();
32+
}
33+
34+
public ES93HnswVectorsFormat(int maxConn, int beamWidth, boolean bfloat16, boolean useDirectIO) {
35+
super(NAME, maxConn, beamWidth);
36+
flatVectorsFormat = new ES93GenericFlatVectorsFormat(bfloat16, useDirectIO);
37+
}
38+
39+
@Override
40+
protected FlatVectorsFormat flatVectorsFormat() {
41+
return flatVectorsFormat;
42+
}
43+
44+
@Override
45+
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
46+
return new Lucene99HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), numMergeWorkers, mergeExec);
47+
}
48+
49+
@Override
50+
public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException {
51+
return new Lucene99HnswVectorsReader(state, flatVectorsFormat.fieldsReader(state));
52+
}
53+
}

0 commit comments

Comments
 (0)