jtibshirani commented on a change in pull request #166:
URL: https://github.com/apache/lucene/pull/166#discussion_r644395730
##########
File path:
lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorFormat.java
##########
@@ -76,14 +79,55 @@
static final int VERSION_START = 0;
static final int VERSION_CURRENT = VERSION_START;
- /** Sole constructor */
+ static final String BEAM_WIDTH_KEY =
+ Lucene90HnswVectorFormat.class.getSimpleName() + ".beam_width";
+ static final String MAX_CONN_KEY =
Lucene90HnswVectorFormat.class.getSimpleName() + ".max_conn";
+
+ /**
+ * Controls how many of the nearest neighbor candidates are connected to the
new node. See {@link
+ * HnswGraph} for details.
+ */
+ private final int maxConn;
+
+ /**
+ * The number of candidate neighbors to track while searching the graph for
each newly inserted
+ * node. See {@link HnswGraph} for details.
+ */
+ private final int beamWidth;
+
public Lucene90HnswVectorFormat() {
super("Lucene90HnswVectorFormat");
+ this.maxConn = HnswGraphBuilder.DEFAULT_MAX_CONN;
+ this.beamWidth = HnswGraphBuilder.DEFAULT_BEAM_WIDTH;
+ }
+
+ public Lucene90HnswVectorFormat(int maxConn, int beamWidth) {
+ super("Lucene90HnswVectorFormat");
+ this.maxConn = maxConn;
+ this.beamWidth = beamWidth;
}
@Override
public VectorWriter fieldsWriter(SegmentWriteState state) throws IOException
{
- return new Lucene90HnswVectorWriter(state);
+ SegmentInfo segmentInfo = state.segmentInfo;
+ putFormatAttribute(segmentInfo, MAX_CONN_KEY, String.valueOf(maxConn));
+ putFormatAttribute(segmentInfo, BEAM_WIDTH_KEY, String.valueOf(beamWidth));
+ return new Lucene90HnswVectorWriter(state, maxConn, beamWidth);
+ }
+
+ private void putFormatAttribute(SegmentInfo si, String key, String value) {
+ String previousValue = si.putAttribute(key, value);
+ if (previousValue != null && previousValue.equals(value) == false) {
Review comment:
I'm not sure that writing and validating these format attributes is
necessary, since we don't use them when reading. It just seemed nice (and low
cost) to have the construction parameters available in the segment infos for
debugging.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]