Skip to content

Commit d68e048

Browse files
committed
update name
1 parent 7bacb22 commit d68e048

13 files changed

+103
-93
lines changed

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/ByteVectorIndex.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneByteVectorIndex.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.apache.lucene.index.IndexableField;
2323
import org.apache.lucene.index.VectorSimilarityFunction;
2424

25-
/** Vector index for byte vector. */
26-
public class ByteVectorIndex extends VectorIndex<byte[]> {
25+
/** Lucene vector index for byte vector. */
26+
public class LuceneByteVectorIndex extends LuceneVectorIndex<byte[]> {
2727
private final long rowId;
2828
private final byte[] vector;
2929

30-
public ByteVectorIndex(long rowId, byte[] vector) {
30+
public LuceneByteVectorIndex(long rowId, byte[] vector) {
3131
this.rowId = rowId;
3232
this.vector = vector;
3333
}

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/FloatVectorIndex.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneFloatVectorIndex.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.apache.lucene.index.IndexableField;
2323
import org.apache.lucene.index.VectorSimilarityFunction;
2424

25-
/** Vector index for float vector. */
26-
public class FloatVectorIndex extends VectorIndex<float[]> {
25+
/** Lucene vector index for float vector. */
26+
public class LuceneFloatVectorIndex extends LuceneVectorIndex<float[]> {
2727
private final long rowId;
2828
private final float[] vector;
2929

30-
public FloatVectorIndex(long rowId, float[] vector) {
30+
public LuceneFloatVectorIndex(long rowId, float[] vector) {
3131
this.rowId = rowId;
3232
this.vector = vector;
3333
}

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/IndexMMapDirectory.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneIndexMMapDirectory.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
import java.nio.file.Path;
3535
import java.util.UUID;
3636

37-
/** A wrapper of MMapDirectory for vector index. */
38-
public class IndexMMapDirectory implements AutoCloseable {
37+
/** A wrapper of Lucene MMapDirectory for vector index. */
38+
public class LuceneIndexMMapDirectory implements AutoCloseable {
3939

4040
private static final int VERSION = 1;
4141

4242
private final Path path;
4343
private final MMapDirectory mmapDirectory;
4444

45-
public IndexMMapDirectory() throws IOException {
45+
public LuceneIndexMMapDirectory() throws IOException {
4646
this.path = Files.createTempDirectory("paimon-lucene-" + UUID.randomUUID());
4747
this.mmapDirectory = new MMapDirectory(path);
4848
}
@@ -93,8 +93,8 @@ public void serialize(OutputStream out) throws IOException {
9393
}
9494
}
9595

96-
public static IndexMMapDirectory deserialize(SeekableInputStream in) throws IOException {
97-
IndexMMapDirectory indexMMapDirectory = new IndexMMapDirectory();
96+
public static LuceneIndexMMapDirectory deserialize(SeekableInputStream in) throws IOException {
97+
LuceneIndexMMapDirectory luceneIndexMMapDirectory = new LuceneIndexMMapDirectory();
9898
try {
9999
DataInputStream dataInputStream = new DataInputStream(in);
100100
int version = dataInputStream.readInt();
@@ -110,7 +110,9 @@ public static IndexMMapDirectory deserialize(SeekableInputStream in) throws IOEx
110110
String fileName = new String(nameBytes, StandardCharsets.UTF_8);
111111
long fileLength = dataInputStream.readLong();
112112
try (IndexOutput output =
113-
indexMMapDirectory.directory().createOutput(fileName, IOContext.READONCE)) {
113+
luceneIndexMMapDirectory
114+
.directory()
115+
.createOutput(fileName, IOContext.READONCE)) {
114116
long remaining = fileLength;
115117
while (remaining > 0) {
116118
int toRead = (int) Math.min(buffer.length, remaining);
@@ -120,10 +122,10 @@ public static IndexMMapDirectory deserialize(SeekableInputStream in) throws IOEx
120122
}
121123
}
122124
}
123-
return indexMMapDirectory;
125+
return luceneIndexMMapDirectory;
124126
} catch (Exception e) {
125127
try {
126-
indexMMapDirectory.close();
128+
luceneIndexMMapDirectory.close();
127129
} catch (Exception ignored) {
128130
}
129131
if (e instanceof IOException) {

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/VectorGlobalIndexReader.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneVectorGlobalIndexReader.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
* <p>This implementation uses Lucene's native KnnFloatVectorQuery with HNSW graph for efficient
5151
* approximate nearest neighbor search.
5252
*/
53-
public class VectorGlobalIndexReader implements GlobalIndexReader {
53+
public class LuceneVectorGlobalIndexReader implements GlobalIndexReader {
5454

5555
private final List<IndexSearcher> searchers;
56-
private final List<IndexMMapDirectory> directories;
56+
private final List<LuceneIndexMMapDirectory> directories;
5757
private final List<GlobalIndexIOMeta> ioMetas;
5858

59-
public VectorGlobalIndexReader(
59+
public LuceneVectorGlobalIndexReader(
6060
GlobalIndexFileReader fileReader, List<GlobalIndexIOMeta> ioMetas) throws IOException {
6161
this.ioMetas = ioMetas;
6262
this.searchers = new ArrayList<>();
@@ -72,12 +72,14 @@ public VectorGlobalIndexReader(
7272
* @return global index result containing row IDs
7373
*/
7474
public GlobalIndexResult search(float[] query, int k) {
75-
KnnFloatVectorQuery knnQuery = new KnnFloatVectorQuery(VectorIndex.VECTOR_FIELD, query, k);
75+
KnnFloatVectorQuery knnQuery =
76+
new KnnFloatVectorQuery(LuceneVectorIndex.VECTOR_FIELD, query, k);
7677
return search(knnQuery, k);
7778
}
7879

7980
public GlobalIndexResult search(byte[] query, int k) {
80-
KnnByteVectorQuery knnQuery = new KnnByteVectorQuery(VectorIndex.VECTOR_FIELD, query, k);
81+
KnnByteVectorQuery knnQuery =
82+
new KnnByteVectorQuery(LuceneVectorIndex.VECTOR_FIELD, query, k);
8183
return search(knnQuery, k);
8284
}
8385

@@ -100,7 +102,7 @@ public void close() throws IOException {
100102
searchers.clear();
101103

102104
// Close directories
103-
for (IndexMMapDirectory directory : directories) {
105+
for (LuceneIndexMMapDirectory directory : directories) {
104106
try {
105107
directory.close();
106108
} catch (Throwable t) {
@@ -132,10 +134,11 @@ private GlobalIndexResult search(Query query, int k) {
132134
try {
133135
TopDocs topDocs = searcher.search(query, k);
134136
StoredFields storedFields = searcher.storedFields();
135-
Set<String> fieldsToLoad = Set.of(VectorIndex.ROW_ID_FIELD);
137+
Set<String> fieldsToLoad = Set.of(LuceneVectorIndex.ROW_ID_FIELD);
136138
for (org.apache.lucene.search.ScoreDoc scoreDoc : topDocs.scoreDocs) {
137139
Document doc = storedFields.document(scoreDoc.doc, fieldsToLoad);
138-
long rowId = doc.getField(VectorIndex.ROW_ID_FIELD).numericValue().longValue();
140+
long rowId =
141+
doc.getField(LuceneVectorIndex.ROW_ID_FIELD).numericValue().longValue();
139142
if (topK.size() < k) {
140143
topK.offer(new ScoredRow(rowId, scoreDoc.score));
141144
} else {
@@ -171,11 +174,11 @@ private void loadIndices(GlobalIndexFileReader fileReader, List<GlobalIndexIOMet
171174
throws IOException {
172175
for (GlobalIndexIOMeta meta : files) {
173176
try (SeekableInputStream in = fileReader.getInputStream(meta.fileName())) {
174-
IndexMMapDirectory directory = null;
177+
LuceneIndexMMapDirectory directory = null;
175178
IndexReader reader = null;
176179
boolean success = false;
177180
try {
178-
directory = IndexMMapDirectory.deserialize(in);
181+
directory = LuceneIndexMMapDirectory.deserialize(in);
179182
reader = DirectoryReader.open(directory.directory());
180183
IndexSearcher searcher = new IndexSearcher(reader);
181184
directories.add(directory);

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/VectorGlobalIndexWriter.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneVectorGlobalIndexWriter.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,33 @@
4444
* <p>This implementation uses Lucene's native KnnFloatVectorField with HNSW algorithm for efficient
4545
* approximate nearest neighbor search.
4646
*/
47-
public class VectorGlobalIndexWriter implements GlobalIndexWriter {
47+
public class LuceneVectorGlobalIndexWriter implements GlobalIndexWriter {
4848

4949
private final GlobalIndexFileWriter fileWriter;
50-
private final VectorIndexOptions vectorOptions;
50+
private final LuceneVectorIndexOptions vectorOptions;
5151
private final VectorSimilarityFunction similarityFunction;
5252
private final int sizePerIndex;
53-
private final VectorIndexFactory vectorIndexFactory;
53+
private final LuceneVectorIndexFactory vectorIndexFactory;
5454

5555
private long count = 0;
56-
private final List<VectorIndex> vectorIndices;
56+
private final List<LuceneVectorIndex> vectorIndices;
5757
private final List<ResultEntry> results;
5858

59-
public VectorGlobalIndexWriter(
59+
public LuceneVectorGlobalIndexWriter(
6060
GlobalIndexFileWriter fileWriter, DataType fieldType, Options options) {
61-
this.vectorIndexFactory = VectorIndexFactory.init(fieldType);
61+
this.vectorIndexFactory = LuceneVectorIndexFactory.init(fieldType);
6262
this.fileWriter = fileWriter;
6363
this.vectorIndices = new ArrayList<>();
6464
this.results = new ArrayList<>();
65-
this.vectorOptions = new VectorIndexOptions(options);
65+
this.vectorOptions = new LuceneVectorIndexOptions(options);
6666
this.similarityFunction = vectorOptions.metric().vectorSimilarityFunction();
6767
this.sizePerIndex = vectorOptions.sizePerIndex();
6868
}
6969

7070
@Override
7171
public void write(Object key) {
7272
count++;
73-
VectorIndex index = vectorIndexFactory.create(count, key);
73+
LuceneVectorIndex index = vectorIndexFactory.create(count, key);
7474
index.checkDimension(vectorOptions.dimension());
7575
vectorIndices.add(index);
7676
if (vectorIndices.size() >= sizePerIndex) {
@@ -96,7 +96,7 @@ public List<ResultEntry> finish() {
9696
}
9797

9898
private void flush() throws IOException {
99-
String fileName = fileWriter.newFileName(VectorGlobalIndexerFactory.IDENTIFIER);
99+
String fileName = fileWriter.newFileName(LuceneVectorGlobalIndexerFactory.IDENTIFIER);
100100
try (OutputStream out = new BufferedOutputStream(fileWriter.newOutputStream(fileName))) {
101101
buildIndex(
102102
vectorIndices,
@@ -112,24 +112,25 @@ private void flush() throws IOException {
112112
}
113113

114114
private void buildIndex(
115-
List<VectorIndex> batchVectors,
115+
List<LuceneVectorIndex> batchVectors,
116116
int m,
117117
int efConstruction,
118118
int writeBufferSize,
119119
OutputStream out) {
120120

121121
IndexWriterConfig config = getIndexWriterConfig(m, efConstruction, writeBufferSize);
122-
try (IndexMMapDirectory indexMMapDirectory = new IndexMMapDirectory()) {
123-
try (IndexWriter writer = new IndexWriter(indexMMapDirectory.directory(), config)) {
124-
for (VectorIndex vectorIndex : batchVectors) {
122+
try (LuceneIndexMMapDirectory luceneIndexMMapDirectory = new LuceneIndexMMapDirectory()) {
123+
try (IndexWriter writer =
124+
new IndexWriter(luceneIndexMMapDirectory.directory(), config)) {
125+
for (LuceneVectorIndex luceneVectorIndex : batchVectors) {
125126
Document doc = new Document();
126-
doc.add(vectorIndex.indexableField(similarityFunction));
127-
doc.add(vectorIndex.rowIdStoredField());
127+
doc.add(luceneVectorIndex.indexableField(similarityFunction));
128+
doc.add(luceneVectorIndex.rowIdStoredField());
128129
writer.addDocument(doc);
129130
}
130131
writer.commit();
131132
}
132-
indexMMapDirectory.serialize(out);
133+
luceneIndexMMapDirectory.serialize(out);
133134
} catch (Exception e) {
134135
throw new RuntimeException(e);
135136
}

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/VectorGlobalIndexer.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneVectorGlobalIndexer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@
3030
import java.io.IOException;
3131
import java.util.List;
3232

33-
/** Vector global indexer. */
34-
public class VectorGlobalIndexer implements GlobalIndexer {
33+
/** Lucene vector global indexer. */
34+
public class LuceneVectorGlobalIndexer implements GlobalIndexer {
3535

3636
private final DataType fieldType;
3737
private final Options options;
3838

39-
public VectorGlobalIndexer(DataType fieldType, Options options) {
39+
public LuceneVectorGlobalIndexer(DataType fieldType, Options options) {
4040
this.fieldType = fieldType;
4141
this.options = options;
4242
}
4343

4444
@Override
4545
public GlobalIndexWriter createWriter(GlobalIndexFileWriter fileWriter) throws IOException {
46-
return new VectorGlobalIndexWriter(fileWriter, fieldType, options);
46+
return new LuceneVectorGlobalIndexWriter(fileWriter, fieldType, options);
4747
}
4848

4949
@Override
5050
public GlobalIndexReader createReader(
5151
GlobalIndexFileReader fileReader, List<GlobalIndexIOMeta> files) throws IOException {
52-
return new VectorGlobalIndexReader(fileReader, files);
52+
return new LuceneVectorGlobalIndexReader(fileReader, files);
5353
}
5454
}

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/VectorGlobalIndexerFactory.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneVectorGlobalIndexerFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import org.apache.paimon.options.Options;
2424
import org.apache.paimon.types.DataType;
2525

26-
/** Factory for creating lucene hnsw vector global indexers. */
27-
public class VectorGlobalIndexerFactory implements GlobalIndexerFactory {
26+
/** Factory for creating Lucene vector index. */
27+
public class LuceneVectorGlobalIndexerFactory implements GlobalIndexerFactory {
2828

29-
public static final String IDENTIFIER = "lucene-hnsw";
29+
public static final String IDENTIFIER = "lucene-vector-knn";
3030

3131
@Override
3232
public String identifier() {
@@ -35,6 +35,6 @@ public String identifier() {
3535

3636
@Override
3737
public GlobalIndexer create(DataType type, Options options) {
38-
return new VectorGlobalIndexer(type, options);
38+
return new LuceneVectorGlobalIndexer(type, options);
3939
}
4040
}

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/VectorIndex.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneVectorIndex.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.apache.lucene.index.IndexableField;
2323
import org.apache.lucene.index.VectorSimilarityFunction;
2424

25-
/** Vector index interface. */
26-
public abstract class VectorIndex<T> {
25+
/** Lucene vector index interface. */
26+
public abstract class LuceneVectorIndex<T> {
2727

2828
public static final String VECTOR_FIELD = "vector";
2929
public static final String ROW_ID_FIELD = "id";

paimon-lucene/src/main/java/org/apache/paimon/lucene/index/VectorIndexFactory.java renamed to paimon-lucene/src/main/java/org/apache/paimon/lucene/index/LuceneVectorIndexFactory.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,36 @@
2323
import org.apache.paimon.types.FloatType;
2424
import org.apache.paimon.types.TinyIntType;
2525

26-
/** Factory for creating vector index instances based on data type. */
27-
public abstract class VectorIndexFactory {
26+
/** Factory for creating Lucene vector index instances based on data type. */
27+
public abstract class LuceneVectorIndexFactory {
2828

29-
public static VectorIndexFactory init(DataType dataType) {
29+
public static LuceneVectorIndexFactory init(DataType dataType) {
3030
if (dataType instanceof ArrayType
3131
&& ((ArrayType) dataType).getElementType() instanceof FloatType) {
32-
return new FloatVectorIndexFactory();
32+
return new LuceneFloatVectorIndexFactory();
3333
} else if (dataType instanceof ArrayType
3434
&& ((ArrayType) dataType).getElementType() instanceof TinyIntType) {
35-
return new ByteVectorIndexFactory();
35+
return new LuceneByteVectorIndexFactory();
3636
} else {
3737
throw new IllegalArgumentException("Unsupported data type: " + dataType);
3838
}
3939
}
4040

41-
public abstract VectorIndex create(long rowId, Object vector);
41+
public abstract LuceneVectorIndex create(long rowId, Object vector);
4242

43-
/** Factory for creating FloatVectorIndex instances. */
44-
public static class FloatVectorIndexFactory extends VectorIndexFactory {
43+
/** Factory for creating LuceneFloatVectorIndex instances. */
44+
public static class LuceneFloatVectorIndexFactory extends LuceneVectorIndexFactory {
4545
@Override
46-
public VectorIndex create(long rowId, Object vector) {
47-
return new FloatVectorIndex(rowId, (float[]) vector);
46+
public LuceneVectorIndex create(long rowId, Object vector) {
47+
return new LuceneFloatVectorIndex(rowId, (float[]) vector);
4848
}
4949
}
5050

51-
/** Factory for creating FloatVectorIndex instances. */
52-
public static class ByteVectorIndexFactory extends VectorIndexFactory {
51+
/** Factory for creating LuceneByteVectorIndex instances. */
52+
public static class LuceneByteVectorIndexFactory extends LuceneVectorIndexFactory {
5353
@Override
54-
public VectorIndex create(long rowId, Object vector) {
55-
return new ByteVectorIndex(rowId, (byte[]) vector);
54+
public LuceneVectorIndex create(long rowId, Object vector) {
55+
return new LuceneByteVectorIndex(rowId, (byte[]) vector);
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)