Skip to content

Commit 73566aa

Browse files
committed
Add a JSON config generator to generate JSON config files for multiple option combinations
1 parent b3dab7e commit 73566aa

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

qa/vector/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,10 @@ tasks.register("printClasspath") {
107107
println "Classpath written to: ${classpathFile.absolutePath}"
108108
}
109109
}
110+
111+
tasks.register('generateJsonConfig', JavaExec) {
112+
group = "Execution"
113+
description = 'Generates JSON configuration using JsonConfigGenerator.'
114+
mainClass = 'org.elasticsearch.test.knn.JsonConfigGenerator'
115+
classpath = sourceSets.main.runtimeClasspath
116+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.test.knn;
11+
12+
13+
import org.elasticsearch.common.Strings;
14+
import org.elasticsearch.xcontent.XContentBuilder;
15+
import org.elasticsearch.xcontent.json.JsonXContent;
16+
17+
import java.io.IOException;
18+
19+
public class JsonConfigGenerator {
20+
public static void main(String[] args) throws IOException {
21+
// Create the base JSON structure
22+
XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint().humanReadable(true);
23+
builder.startArray(); // Start the array
24+
25+
for (int quantizeBits = 1; quantizeBits <= 7; quantizeBits++) {
26+
boolean reindex = true;
27+
for (int quantizeQueryBits = quantizeBits; quantizeQueryBits <= 7; quantizeQueryBits++) {
28+
for (int overSamplingFactor = 1; overSamplingFactor <= 5; overSamplingFactor++) {
29+
builder.startObject(); // Start a new JSON object
30+
builder.field("doc_vectors", "/Users/cdelgado/dev/workspace/ann-prototypes/data/corpus-ann-gist-1M.fvec");
31+
builder.field("query_vectors", "/Users/cdelgado/dev/workspace/ann-prototypes/data/queries-ann-gist-1M.fvec");
32+
builder.field("num_docs", 1000000);
33+
builder.field("num_queries", 100);
34+
builder.field("index_type", "flat");
35+
builder.field("search_threads", 20);
36+
builder.field("index_threads", 20);
37+
builder.field("reindex", reindex);
38+
builder.field("force_merge", true);
39+
builder.field("vector_space", "euclidean");
40+
builder.field("vector_encoding", "float32");
41+
builder.field("dimensions", -1);
42+
builder.field("use_new_flat_vectors_format", true);
43+
builder.field("quantize_bits", quantizeBits);
44+
builder.field("quantize_query_bits", quantizeQueryBits);
45+
builder.field("over_sampling_factor", overSamplingFactor);
46+
builder.endObject(); // End the JSON object
47+
reindex = false;
48+
}
49+
}
50+
}
51+
52+
builder.endArray(); // End the array
53+
54+
// Print the generated JSON
55+
System.out.println(Strings.toString(builder));
56+
}
57+
}

0 commit comments

Comments
 (0)