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 }
0 commit comments