Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ public void checkCreate(boolean isBatch) {
E.checkArgumentNotNull(this.indexType,
"The index type of index label '%s' " +
"can't be null", this.name);
if(this.indexType == IndexType.VECTOR){
E.checkArgumentNotNull(this.userdata,
"The user_data(dimension and metric) of vector index " +
"label '%s' " +
"can't be null", this.name);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code format

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will fix it


}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.exception.NotAllowException;
import org.apache.hugegraph.type.define.Action;
import org.apache.hugegraph.util.E;

public class Userdata extends HashMap<String, Object> {

Expand Down Expand Up @@ -61,4 +63,10 @@ public static void check(Userdata userdata, Action action) {
"Unknown schema action '%s'", action));
}
}

public static void checkDimensionAndMetric(Userdata userdata) {
E.checkArgument((userdata.get("dimension") != null) &&
(userdata.get("metric") != null),
"The vector index dimension and metric can't not be null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.Action;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.CollectionType;
import org.apache.hugegraph.type.define.DataType;
import org.apache.hugegraph.type.define.IndexType;
Expand Down Expand Up @@ -390,6 +391,11 @@ public IndexLabelBuilder unique() {
return this;
}

public IndexLabelBuilder vector() {
this.indexType = IndexType.VECTOR;
return this;
}

@Override
public IndexLabelBuilder on(HugeType baseType, String baseValue) {
E.checkArgument(baseType == HugeType.VERTEX_LABEL ||
Expand Down Expand Up @@ -526,6 +532,21 @@ private void checkFields(Set<Id> propertyIds) {
"Search index can only build on text property, " +
"but got %s(%s)", dataType, field);
}

// Vector index must build on float list
if(this.indexType.isVector()){
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be 'if (this.indexType.isVector()) {' to follow Java coding conventions.

Suggested change
if(this.indexType.isVector()){
if (this.indexType.isVector()) {

Copilot uses AI. Check for mistakes.
E.checkArgument(fields.size() == 1,
"vector index can only build on " +
"one field, but got %s fields: '%s'",
fields.size(), fields);
String field = fields.iterator().next();
DataType dataType = this.graph().propertyKey(field).dataType();
Cardinality cardinality = this.graph().propertyKey(field).cardinality();
E.checkArgument((dataType == DataType.FLOAT) &&
(cardinality == Cardinality.LIST),
"vector index can only build on Float List, " +
"but got %s(%s)", dataType, cardinality);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code format

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will fix it

}

private void checkFields4Range() {
Expand Down Expand Up @@ -587,6 +608,9 @@ private void checkRepeatIndex(SchemaLabel schemaLabel) {
case UNIQUE:
this.checkRepeatUniqueIndex(schemaLabel);
break;
case VECTOR:
this.checkRepeatVectorIndex(schemaLabel);
break;
default:
throw new AssertionError(String.format(
"Unsupported index type: %s", this.indexType));
Expand Down Expand Up @@ -675,6 +699,11 @@ private void checkRepeatShardIndex(SchemaLabel schemaLabel) {
}
}

private void checkRepeatVectorIndex(SchemaLabel schemaLabel) {
this.checkRepeatIndex(schemaLabel, IndexType.VECTOR);
}


private void checkRepeatUniqueIndex(SchemaLabel schemaLabel) {
this.checkRepeatIndex(schemaLabel, List::containsAll, IndexType.UNIQUE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public enum HugeType implements SerialEnum {
SEARCH_INDEX(170, "AI"),
SHARD_INDEX(175, "HI"),
UNIQUE_INDEX(178, "UI"),
VECTOR_INDEX(180, "VI"),

TASK(180, "TASK"),
SERVER(181, "SERVER"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public enum IndexType implements SerialEnum {
SHARD(4, "shard"),

// For unique index
UNIQUE(5, "unique");
UNIQUE(5, "unique"),

//For vector index
VECTOR(6, "vector");

private byte code = 0;
private String name = null;
Expand Down Expand Up @@ -80,6 +83,8 @@ public HugeType type() {
return HugeType.SHARD_INDEX;
case UNIQUE:
return HugeType.UNIQUE_INDEX;
case VECTOR:
return HugeType.VECTOR_INDEX;
default:
throw new AssertionError(String.format(
"Unknown index type '%s'", this));
Expand Down Expand Up @@ -117,4 +122,8 @@ public boolean isShard() {
public boolean isUnique() {
return this == UNIQUE;
}

public boolean isVector() {
return this == VECTOR;
}
}
Loading