Skip to content

Commit 31954c2

Browse files
committed
iter
1 parent 9bc24c3 commit 31954c2

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

qa/vector/src/main/java/org/elasticsearch/test/knn/KnnIndexer.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ public boolean isEnabled(String component) {
124124
similarityFunction
125125
);
126126

127-
Files.createDirectory(indexPath);
127+
if (Files.exists(indexPath)) {
128+
logger.debug("KnnIndexer: existing index at %s", indexPath);
129+
} else {
130+
Files.createDirectory(indexPath);
131+
}
128132

129133
long start = System.nanoTime();
130134
try (
@@ -269,6 +273,7 @@ static class VectorReader {
269273
final float[] target;
270274
final ByteBuffer bytes;
271275
final FileChannel input;
276+
long position;
272277

273278
static VectorReader create(FileChannel input, int dim, VectorEncoding vectorEncoding) throws IOException {
274279
int bufferSize = dim * vectorEncoding.byteSize;
@@ -288,22 +293,26 @@ static VectorReader create(FileChannel input, int dim, VectorEncoding vectorEnco
288293
}
289294

290295
void reset() throws IOException {
291-
input.position(0);
296+
position = 0;
297+
input.position(position);
292298
}
293299

294300
private void readNext() throws IOException {
295-
int bytesRead = Channels.readFromFileChannel(this.input, this.input.position(), bytes);
301+
int bytesRead = Channels.readFromFileChannel(this.input, position, bytes);
296302
if (bytesRead < bytes.capacity()) {
303+
position = 0;
304+
bytes.position(0);
297305
// wrap around back to the start of the file if we hit the end:
298306
logger.warn("VectorReader hit EOF when reading " + this.input + "; now wrapping around to start of file again");
299-
this.input.position(0);
300-
bytesRead = Channels.readFromFileChannel(this.input, this.input.position(), bytes);
307+
this.input.position(position);
308+
bytesRead = Channels.readFromFileChannel(this.input, position, bytes);
301309
if (bytesRead < bytes.capacity()) {
302310
throw new IllegalStateException(
303311
"vector file " + input + " doesn't even have enough bytes for a single vector? got bytesRead=" + bytesRead
304312
);
305313
}
306314
}
315+
position += bytesRead;
307316
bytes.position(0);
308317
}
309318

0 commit comments

Comments
 (0)