Skip to content

Commit 727a313

Browse files
committed
update new features
1 parent 8a6a63a commit 727a313

18 files changed

Lines changed: 804 additions & 501 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ coverage/
9292
jacoco.exec
9393

9494
# AI Tools
95-
.claude
95+
.claude
96+
97+
# specification file
98+
SPEC.md

README.md

Lines changed: 359 additions & 385 deletions
Large diffs are not rendered by default.

src/main/java/io/endee/client/Endee.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
public class Endee {
4343
private static final Logger logger = LoggerFactory.getLogger(Endee.class);
4444
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(30);
45-
private static final int MAX_DIMENSION = 10000;
45+
private static final int MAX_DIMENSION = 8000;
46+
private static final int MIN_DIMENSION = 2;
47+
private static final List<String> VALID_SPARSE_MODELS = List.of("default", "endee_bm25");
4648

4749
private String token;
4850
private String baseUrl;
@@ -56,13 +58,13 @@ public class Endee {
5658
*/
5759
public Endee() {
5860
this(null);
59-
this.baseUrl = "http://127.0.0.1:8080/api/v1";
6061
}
6162

6263
/**
6364
* Creates a new Endee client.
6465
*
65-
* @param token the Auth token (optional)
66+
* @param token the Auth token (optional). Format: {@code "account:password"} or {@code
67+
* "account:password:region"}
6668
*/
6769
public Endee(String token) {
6870
this.token = token;
@@ -106,20 +108,28 @@ public String setBaseUrl(String url) {
106108
public String createIndex(CreateIndexOptions options) {
107109
if (!ValidationUtils.isValidIndexName(options.getName())) {
108110
throw new IllegalArgumentException(
109-
"Invalid index name. Index name must be alphanumeric and can contain underscores and less than 48 characters");
110-
}
111-
if (options.getDimension() > MAX_DIMENSION) {
112-
throw new IllegalArgumentException("Dimension cannot be greater than " + MAX_DIMENSION);
111+
"Invalid index name. Must be alphanumeric with underscores, max 48 characters.");
113112
}
114-
if (options.getSparseDimension() != null && options.getSparseDimension() < 0) {
115-
throw new IllegalArgumentException("Sparse dimension cannot be less than 0");
113+
if (options.getDimension() < MIN_DIMENSION || options.getDimension() > MAX_DIMENSION) {
114+
throw new IllegalArgumentException(
115+
"Dimension must be between " + MIN_DIMENSION + " and " + MAX_DIMENSION);
116116
}
117117

118118
String normalizedSpaceType = options.getSpaceType().getValue().toLowerCase();
119119
if (!List.of("cosine", "l2", "ip").contains(normalizedSpaceType)) {
120120
throw new IllegalArgumentException("Invalid space type: " + options.getSpaceType());
121121
}
122122

123+
String sparseModel = options.getSparseModel();
124+
if (sparseModel != null) {
125+
String normalized = sparseModel.toLowerCase();
126+
if (!VALID_SPARSE_MODELS.contains(normalized)) {
127+
throw new IllegalArgumentException(
128+
"Invalid sparseModel. Must be one of: " + VALID_SPARSE_MODELS);
129+
}
130+
sparseModel = normalized;
131+
}
132+
123133
Map<String, Object> data = new HashMap<>();
124134
data.put("index_name", options.getName());
125135
data.put("dim", options.getDimension());
@@ -129,8 +139,8 @@ public String createIndex(CreateIndexOptions options) {
129139
data.put("checksum", -1);
130140
data.put("precision", options.getPrecision().getValue());
131141

132-
if (options.getSparseDimension() != null) {
133-
data.put("sparse_dim", options.getSparseDimension());
142+
if (sparseModel != null) {
143+
data.put("sparse_model", sparseModel);
134144
}
135145
if (options.getVersion() != null) {
136146
data.put("version", options.getVersion());
@@ -158,7 +168,7 @@ public String createIndex(CreateIndexOptions options) {
158168
/**
159169
* Lists all indexes.
160170
*
161-
* @return list of index information
171+
* @return raw JSON string of index information
162172
* @throws EndeeException if the operation fails
163173
*/
164174
public String listIndexes() {
@@ -228,14 +238,19 @@ public Index getIndex(String name) {
228238
indexInfo.setTotalElements(data.get("total_elements").asLong());
229239
indexInfo.setPrecision(Precision.fromValue(data.get("precision").asText()));
230240
indexInfo.setM(data.get("M").asInt());
231-
indexInfo.setChecksum(data.get("checksum").asLong());
232241
indexInfo.setEfCon(data.get("ef_con").asInt());
233242

243+
if (data.has("checksum") && !data.get("checksum").isNull()) {
244+
indexInfo.setChecksum(data.get("checksum").asLong());
245+
}
234246
if (data.has("version") && !data.get("version").isNull()) {
235247
indexInfo.setVersion(data.get("version").asInt());
236248
}
237-
if (data.has("sparse_dim") && !data.get("sparse_dim").isNull()) {
238-
indexInfo.setSparseDimension(data.get("sparse_dim").asInt());
249+
if (data.has("sparse_model") && !data.get("sparse_model").isNull()) {
250+
indexInfo.setSparseModel(data.get("sparse_model").asText());
251+
}
252+
if (data.has("lib_token") && !data.get("lib_token").isNull()) {
253+
indexInfo.setLibToken(data.get("lib_token").asText());
239254
}
240255

241256
return new Index(name, token, baseUrl, version, indexInfo);

0 commit comments

Comments
 (0)