Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -87,6 +87,7 @@ public class LSMVectorIndex extends PaginatedComponent implements com.arcadedb.i
private final String indexName;
private final String typeName;
private final String[] propertyNames;
private final String idPropertyName;
private final ReentrantReadWriteLock lock;
private int associatedBucketId;

Expand Down Expand Up @@ -227,6 +228,7 @@ protected LSMVectorIndex(final LSMVectorIndexBuilder builder) throws IOException
this.similarityFunction = builder.getSimilarityFunction();
this.maxConnections = builder.getMaxConnections();
this.beamWidth = builder.getBeamWidth();
this.idPropertyName = builder.getIdPropertyName();

this.lock = new ReentrantReadWriteLock();
this.transactionContexts = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -282,6 +284,7 @@ protected LSMVectorIndex(final DatabaseInternal database, final String name, fin
this.similarityFunction = VectorSimilarityFunction.valueOf(json.getString("similarityFunction", "COSINE"));
this.maxConnections = json.getInt("maxConnections", 16);
this.beamWidth = json.getInt("beamWidth", 100);
this.idPropertyName = json.getString("idPropertyName", "id");

// Load property names
final List<String> propList = new ArrayList<>();
Expand Down Expand Up @@ -1173,6 +1176,7 @@ public JSONObject toJSON() {
json.put("similarityFunction", similarityFunction.name());
json.put("maxConnections", maxConnections);
json.put("beamWidth", beamWidth);
json.put("idPropertyName", idPropertyName);
json.put("version", CURRENT_VERSION);
return json;
}
Expand Down Expand Up @@ -1276,6 +1280,10 @@ public int getBeamWidth() {
return beamWidth;
}

public String getIdPropertyName() {
return idPropertyName;
}

/**
* Gets the compacted sub-index, if any.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ private Object executeWithLSMVector(final LSMVectorIndex lsmIndex, final Object
final String keyStr = key.toString();
final String typeName = lsmIndex.getTypeName();
final String vectorProperty = lsmIndex.getPropertyNames().getFirst();
final String idProperty = lsmIndex.getIdPropertyName();

// Query for the vertex by the ID property (usually "name")
// Query for the vertex by the configured ID property
final ResultSet rs = context.getDatabase().query("sql",
"SELECT " + vectorProperty + " FROM " + typeName + " WHERE name = ? LIMIT 1", keyStr);
"SELECT " + vectorProperty + " FROM " + typeName + " WHERE " + idProperty + " = ? LIMIT 1", keyStr);

if (rs.hasNext()) {
final var result = rs.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class LSMVectorIndexBuilder extends IndexBuilder<TypeIndex> {
private VectorSimilarityFunction similarityFunction = VectorSimilarityFunction.COSINE;
private int maxConnections = 16;
private int beamWidth = 100;
private String idPropertyName = "id";

public LSMVectorIndexBuilder(final DatabaseInternal database, final String typeName, final String[] propertyNames) {
super(database, TypeIndex.class);
Expand Down Expand Up @@ -226,9 +227,28 @@ public LSMVectorIndexBuilder withBeamWidth(final int beamWidth) {
return this;
}

/**
* Sets the ID property name used to identify vertices.
* This property is used when searching for vertices by ID.
* Default is "id".
*
* @param idPropertyName the ID property name
*
* @return this builder
*/
public LSMVectorIndexBuilder withIdProperty(final String idPropertyName) {
this.idPropertyName = idPropertyName;
return this;
}

/**
* Configures the index from a metadata JSON object.
* Expected keys: dimensions, similarity, maxConnections, beamWidth
* Expected keys:
* - dimensions (required): number of vector dimensions
* - similarity (optional): similarity function (COSINE, DOT_PRODUCT, EUCLIDEAN), defaults to COSINE
* - maxConnections (optional): max connections per node in HNSW graph, defaults to 16
* - beamWidth (optional): beam width for search operations, defaults to 100
* - idPropertyName (optional): property name used to identify vertices, defaults to "id"
*
* @param metadata the metadata JSON
*
Expand All @@ -247,6 +267,9 @@ public LSMVectorIndexBuilder withMetadata(final JSONObject metadata) {
if (metadata.has("beamWidth"))
this.beamWidth = metadata.getInt("beamWidth");

if (metadata.has("idPropertyName"))
this.idPropertyName = metadata.getString("idPropertyName");

return this;
}

Expand Down Expand Up @@ -275,6 +298,10 @@ public int getBeamWidth() {
return beamWidth;
}

public String getIdPropertyName() {
return idPropertyName;
}

public String getIndexName() {
return indexName;
}
Expand Down