[GitHub] [lucene] dweiss merged pull request #11993: Upgrade gradle to 7.6.

2022-12-02 Thread GitBox


dweiss merged PR #11993:
URL: https://github.com/apache/lucene/pull/11993


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] dweiss merged pull request #11994: Upgrade gradle to 7.6 (backport)

2022-12-02 Thread GitBox


dweiss merged PR #11994:
URL: https://github.com/apache/lucene/pull/11994


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335235418

   > @uschindler I think this issue just have a GC path of ThreadLocals. BUT, 
for instance in ES, when there is a 1000-shard-nodes, and normally one shard 
with 40 segments per shard, one opened segments would allocate one buffer with 
retained heap: 100KB, so this would use 4G resident heap memory, even some 
segments are rarely used.
   
   You can use less shards as a workaround for now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335237178

   In fact there is no situation where thousands of shards makes sense on a 
single node. That's bad design.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] benwtrent commented on issue #11963: Improve vector quantization API

2022-12-02 Thread GitBox


benwtrent commented on issue #11963:
URL: https://github.com/apache/lucene/issues/11963#issuecomment-1335239951

   @rmuir thank you! I currently have a major part of the refactor already 
written locally. But, it will be big and will need its own rounds of review to 
make sure its the way we want it.
   
   I want to try and get the PR up (once the size improvements is merged) ASAP


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] benwtrent commented on a diff in pull request #11860: GITHUB-11830 Better optimize storage for vector connections

2022-12-02 Thread GitBox


benwtrent commented on code in PR #11860:
URL: https://github.com/apache/lucene/pull/11860#discussion_r1038154379


##
lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene94/ExpandingVectorValues.java:
##
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.backward_codecs.lucene94;
+
+import java.io.IOException;
+import org.apache.lucene.index.FilterVectorValues;
+import org.apache.lucene.index.VectorValues;
+import org.apache.lucene.util.BytesRef;
+
+/** reads from byte-encoded data */
+public class ExpandingVectorValues extends FilterVectorValues {
+
+  private final float[] value;
+
+  /**
+   * Constructs ExpandingVectorValues with passed byte encoded VectorValues 
iterator
+   *
+   * @param in the wrapped values
+   */
+  protected ExpandingVectorValues(VectorValues in) {

Review Comment:
   @rmuir I don't think you are a madman. Apologies if my responses implied 
that. Just a little frustrated (as this change took work and already has a 
giant review). 
   
   I am working on the refactor now and want to get a PR for it ASAP after 
this. I am 100% on your side that the current API is not optimal. So, I will be 
splitting out the byte/float32 types. It will make the whole thing better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335269730

   I will investigate the document API and try to make a proposal so that 
threadlocal is no longer needed. I'm really concerned about the merge case here 
causing regressions for folks that delete/update documents, I'll also try to 
run the benchmark myself for the unoptimized merge case.
   
   It requires a bit of time, as document api will impact 100% of lucene users 
so we need to get it right.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] luyuncheng commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


luyuncheng commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335302726

   > In fact there is no situation where thousands of shards makes sense on a 
single node. That's bad design.
   
   @rmuir i have another proposal: 
   what do you think of make `ByteBufferDataInput` as not fixed sized ( cause 
you mentioned LUCENE-10627 do not introduce any other ByteBlockPool)
   
   every time we call decompress and wrap decompressed BytesRef as 
ByteArrayDataInput
   
   the decompress can make a list ByteBuffer, and every time just copy 
dictionary, 
   this can reduce memory copy from buffer and reduce ArrayUtil.grow's memory 
copy, 
   as well as can solved buffer-heap-influence
   
   simple code like following:
   ```
 // Read blocks that intersect with the interval we need
 ArrayList bufferList = new ArrayList<>();
 while (offsetInBlock < offset + length) {
   final int bytesToDecompress = Math.min(blockLength, offset + length 
- offsetInBlock);
   byte[] bytebuffer = new byte[dictLength + blockLength];
   //Only copy dict
   System.arraycopy(dictBuffer, 0, bytebuffer, 0, dictLength);
   LZ4.decompress(in, bytesToDecompress, bytebuffer, dictLength);
   offsetInBlock += blockLength;
   
   bufferList.add(ByteBuffer.wrap(bytebuffer, dictLength, 
bytesToDecompress).slice());
 }
return = new ByteBuffersDataInput(bufferList);
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


jpountz commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335358751

   I had opened a very similar PR to this one at 
https://github.com/apache/lucene/pull/137 which handled the merge case.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


jpountz commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335365755

   I think I had not merged it because the follow-up discussion about removing 
thread locals had triggered naming/API concerns, but it should be a good 
incremental step and we could figure a way to remove threadlocals in Lucene 10 
since it will require API changes?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335391991

   > I think I had not merged it because the follow-up discussion about 
removing thread locals had triggered naming/API concerns, but it should be a 
good incremental step and we could figure a way to remove threadlocals in 
Lucene 10 since it will require API changes?
   
   I don't think so, i tend to lean towards Uwe's thoughts here. I feel like 
this is "rush in another fix for 10,000 shards".
   
   We can investigate removing the threadlocals in lucene 10. Very possibly the 
change could be backported with deprecations for `IR.document(int)` (e.g. which 
would use threadlocal like now). At least to me, that's the ideal scenario. So 
you could migrate your lucene 9 code to no longer use deprecated methods and 
not have the threadlocals.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


jpountz commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335392646

   Sounds good.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz closed pull request #137: LUCENE-9955: Reduced state of stored fields readers.

2022-12-02 Thread GitBox


jpountz closed pull request #137: LUCENE-9955: Reduced state of stored fields 
readers.
URL: https://github.com/apache/lucene/pull/137


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335398330

   its just gonna take me some time, i can't get something out there like 
today. for example nearly 100% of tests would be impacted :) It is fair, I will 
feel the same pain the users will. But it is some motivation to take care with 
the API and spend some time to do it well.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] luyuncheng commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


luyuncheng commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335420862

   Threadlocal just scale up the StoredFieldsReader's heap useage, BUT when one 
instance with only 10K segments would use 1G heap memory in 
`fieldsReaderOrig#buffer` without threadlocal. my idea is when the buffer is 
rarely used, it should be recycled


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335444854

   the idea is not to have one instance per segment. there would be zero 
instances. when you want to retrieve docs from indexreader, the user would call 
.getFieldsReader() or similar to create one. it would be eligible for GC 
afterwards.
   
   but it means we can reuse buffers per-search and per-merge rather than 
creating per-document garbage. basically it would work like every other part of 
lucene.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] rmuir commented on pull request #11987: Make Decompressor release memory buffer

2022-12-02 Thread GitBox


rmuir commented on PR #11987:
URL: https://github.com/apache/lucene/pull/11987#issuecomment-1335456484

   and one idea i have is to try to prototype with the term vectors first 
(since both stored fields and term vectors have per-segment threadlocals that 
I'd like to remove). it is just less tests to fix, but still gives us a chance 
to look at the idea.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] dnhatn commented on pull request #11984: Add exponential growth to TimeLimitingBulkScorer

2022-12-02 Thread GitBox


dnhatn commented on PR #11984:
URL: https://github.com/apache/lucene/pull/11984#issuecomment-1335560505

   Thanks @costin!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] dnhatn merged pull request #11984: Add exponential growth to TimeLimitingBulkScorer

2022-12-02 Thread GitBox


dnhatn merged PR #11984:
URL: https://github.com/apache/lucene/pull/11984


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] dnhatn closed issue #11676: Can TimeLimitingBulkScorer exponentially grow the window size? [LUCENE-10640]

2022-12-02 Thread GitBox


dnhatn closed issue #11676: Can TimeLimitingBulkScorer exponentially grow the 
window size? [LUCENE-10640]
URL: https://github.com/apache/lucene/issues/11676


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz commented on a diff in pull request #11860: GITHUB-11830 Better optimize storage for vector connections

2022-12-02 Thread GitBox


jpountz commented on code in PR #11860:
URL: https://github.com/apache/lucene/pull/11860#discussion_r1038244235


##
lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene94/ExpandingVectorValues.java:
##
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.backward_codecs.lucene94;
+
+import java.io.IOException;
+import org.apache.lucene.index.FilterVectorValues;
+import org.apache.lucene.index.VectorValues;
+import org.apache.lucene.util.BytesRef;
+
+/** reads from byte-encoded data */
+public class ExpandingVectorValues extends FilterVectorValues {

Review Comment:
   @benwtrent Can you make it pkg-private?



##
lucene/core/src/java/org/apache/lucene/codecs/lucene95/Lucene95HnswVectorsFormat.java:
##
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.codecs.lucene95;
+
+import java.io.IOException;
+import org.apache.lucene.codecs.KnnVectorsFormat;
+import org.apache.lucene.codecs.KnnVectorsReader;
+import org.apache.lucene.codecs.KnnVectorsWriter;
+import org.apache.lucene.codecs.lucene90.IndexedDISI;
+import org.apache.lucene.index.SegmentReadState;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.hnsw.HnswGraph;
+
+/**
+ * Lucene 9.5 vector format, which encodes numeric vector values and an 
optional associated graph
+ * connecting the documents having values. The graph is used to power HNSW 
search. The format
+ * consists of three files:
+ *
+ * .vec (vector data) file
+ *
+ * For each field:
+ *
+ * 
+ *   Vector data ordered by field, document ordinal, and vector dimension. 
When the
+ *   vectorEncoding is BYTE, each sample is stored as a single byte. When 
it is FLOAT32, each
+ *   sample is stored as an IEEE float in little-endian byte order.
+ *   DocIds encoded by {@link IndexedDISI#writeBitSet(DocIdSetIterator, 
IndexOutput, byte)},
+ *   note that only in sparse case
+ *   OrdToDoc was encoded by {@link 
org.apache.lucene.util.packed.DirectMonotonicWriter}, note
+ *   that only in sparse case
+ * 
+ *
+ * .vex (vector index)
+ *
+ * Stores graphs connecting the documents for each field organized as a 
list of nodes' neighbours
+ * as following:
+ *
+ * 
+ *   For each level:
+ *   
+ * For each node:
+ * 
+ *   [vint] the number of neighbor nodes
+ *   array[vint] the delta encoded neighbor ordinals
+ * 
+ *   
+ *   After all levels are encoded memory offsets for each node's neighbor 
nodes encoded by
+ *   {@link org.apache.lucene.util.packed.DirectMonotonicWriter} are 
appened to the end of the
+ *   file.
+ * 
+ *
+ * .vem (vector metadata) file
+ *
+ * For each field:
+ *
+ * 
+ *   [int32] field number
+ *   [int32] vector similarity function ordinal
+ *   [vlong] offset to this field's vectors in the .vec file
+ *   [vlong] length of this field's vectors, in bytes
+ *   [vlong] offset to this field's index in the .vex file
+ *   [vlong] length of this field's index data, in bytes
+ *   [int] dimension of this field's vectors
+ *   [int] the number of documents having values for this field
+ *   [int8] if equals to -1, dense – all documents have values for 
a field. If equals to
+ *   0, sparse – some documents missing val

[GitHub] [lucene] benwtrent commented on a diff in pull request #11860: GITHUB-11830 Better optimize storage for vector connections

2022-12-02 Thread GitBox


benwtrent commented on code in PR #11860:
URL: https://github.com/apache/lucene/pull/11860#discussion_r1038415190


##
lucene/core/src/java/org/apache/lucene/codecs/lucene95/Lucene95HnswVectorsWriter.java:
##
@@ -0,0 +1,753 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.codecs.lucene95;
+
+import static 
org.apache.lucene.codecs.lucene95.Lucene95HnswVectorsFormat.DIRECT_MONOTONIC_BLOCK_SHIFT;
+import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.lucene.codecs.CodecUtil;
+import org.apache.lucene.codecs.KnnFieldVectorsWriter;
+import org.apache.lucene.codecs.KnnVectorsWriter;
+import org.apache.lucene.codecs.lucene90.IndexedDISI;
+import org.apache.lucene.index.*;
+import org.apache.lucene.index.Sorter;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.*;
+import org.apache.lucene.util.hnsw.HnswGraph;
+import org.apache.lucene.util.hnsw.HnswGraph.NodesIterator;
+import org.apache.lucene.util.hnsw.HnswGraphBuilder;
+import org.apache.lucene.util.hnsw.NeighborArray;
+import org.apache.lucene.util.hnsw.OnHeapHnswGraph;
+import org.apache.lucene.util.packed.DirectMonotonicWriter;
+
+/**
+ * Writes vector values and knn graphs to index segments.
+ *
+ * @lucene.experimental
+ */
+public final class Lucene95HnswVectorsWriter extends KnnVectorsWriter {
+
+  private final SegmentWriteState segmentWriteState;
+  private final IndexOutput meta, vectorData, vectorIndex;
+  private final int M;
+  private final int beamWidth;
+
+  private final List> fields = new ArrayList<>();
+  private boolean finished;
+
+  Lucene95HnswVectorsWriter(SegmentWriteState state, int M, int beamWidth) 
throws IOException {
+this.M = M;
+this.beamWidth = beamWidth;
+segmentWriteState = state;
+String metaFileName =
+IndexFileNames.segmentFileName(
+state.segmentInfo.name, state.segmentSuffix, 
Lucene95HnswVectorsFormat.META_EXTENSION);
+
+String vectorDataFileName =
+IndexFileNames.segmentFileName(
+state.segmentInfo.name,
+state.segmentSuffix,
+Lucene95HnswVectorsFormat.VECTOR_DATA_EXTENSION);
+
+String indexDataFileName =
+IndexFileNames.segmentFileName(
+state.segmentInfo.name,
+state.segmentSuffix,
+Lucene95HnswVectorsFormat.VECTOR_INDEX_EXTENSION);
+boolean success = false;
+try {
+  meta = state.directory.createOutput(metaFileName, state.context);
+  vectorData = state.directory.createOutput(vectorDataFileName, 
state.context);
+  vectorIndex = state.directory.createOutput(indexDataFileName, 
state.context);
+
+  CodecUtil.writeIndexHeader(
+  meta,
+  Lucene95HnswVectorsFormat.META_CODEC_NAME,
+  Lucene95HnswVectorsFormat.VERSION_CURRENT,
+  state.segmentInfo.getId(),
+  state.segmentSuffix);
+  CodecUtil.writeIndexHeader(
+  vectorData,
+  Lucene95HnswVectorsFormat.VECTOR_DATA_CODEC_NAME,
+  Lucene95HnswVectorsFormat.VERSION_CURRENT,
+  state.segmentInfo.getId(),
+  state.segmentSuffix);
+  CodecUtil.writeIndexHeader(
+  vectorIndex,
+  Lucene95HnswVectorsFormat.VECTOR_INDEX_CODEC_NAME,
+  Lucene95HnswVectorsFormat.VERSION_CURRENT,
+  state.segmentInfo.getId(),
+  state.segmentSuffix);
+  success = true;
+} finally {
+  if (success == false) {
+IOUtils.closeWhileHandlingException(this);
+  }
+}
+  }
+
+  @Override
+  public KnnFieldVectorsWriter addField(FieldInfo fieldInfo) throws 
IOException {
+FieldWriter newField =
+FieldWriter.create(fieldInfo, M, beamWidth, 
segmentWriteState.infoStream);
+fields.add(newField);
+return newField;
+  }
+
+  @Override
+  public void flush(int maxDoc, Sorter.DocMap sortMap) throws IOException {
+for (FieldWriter field : fields) {
+  if (s

[GitHub] [lucene] benwtrent commented on a diff in pull request #11860: GITHUB-11830 Better optimize storage for vector connections

2022-12-02 Thread GitBox


benwtrent commented on code in PR #11860:
URL: https://github.com/apache/lucene/pull/11860#discussion_r1038420089


##
lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraph.java:
##
@@ -144,6 +145,10 @@ public NodesIterator(int size) {
   this.size = size;
 }
 
+public int[] copy() {
+  return ArrayUtil.copyOfSubArray(nodes, 0, size);
+}

Review Comment:
   @jpountz we could, but then we lose the intrinsics. I did some performance 
testing and found that using intrinsics here with ArrayUtil is way better and 
without it flush time is increased significantly. Maybe it would be better for 
the caller to provide an array and have the iterator populate it in a function?
   
   Would you prefer:
   
   ```java
   public void consume(int[] dest) {
   System.arraycopy(nodes, 0, dest, 0, dest.length);
   }
   ```
   
   Or something? Or would you rather have the runtime cost on flush? (which 
seems unjustified to me)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org