-
-
Notifications
You must be signed in to change notification settings - Fork 94
Description
I am using version 25.7.1. The documentation for the vectorNeighbors function shows that you can query a vector index using a node for nearest neighbors. In the documentation the key is a string value but the code assumes that the key value is an embedding.
`SELECT vectorNeighbors('Word[name,vector]','Life',10)
java.lang.ClassCastException: class java.lang.String cannot be cast to class [F (java.lang.String and [F are in module java.base of loader 'bootstrap')
at com.github.jelmerk.knn.DistanceFunctions$FloatCosineDistance.distance(DistanceFunctions.java:87)
at com.arcadedb.index.vector.HnswVectorIndex.findNearest(HnswVectorIndex.java:527)
at com.arcadedb.index.vector.HnswVectorIndex.findNeighborsFromVector(HnswVectorIndex.java:280)
at com.arcadedb.query.sql.function.vector.SQLFunctionVectorNeighbors.execute(SQLFunctionVectorNeighbors.java:67)
at com.arcadedb.query.sql.parser.FunctionCall.execute(FunctionCall.java:132)
at com.arcadedb.query.sql.parser.FunctionCall.execute(FunctionCall.java:85)
at com.arcadedb.query.sql.parser.LevelZeroIdentifier.execute(LevelZeroIdentifier.java:65)
at com.arcadedb.query.sql.parser.BaseIdentifier.execute(BaseIdentifier.java:66)
at com.arcadedb.query.sql.parser.BaseExpression.execute(BaseExpression.java:145)
at com.arcadedb.query.sql.parser.Expression.execute(Expression.java:87)
at com.arcadedb.query.sql.parser.ProjectionItem.execute(ProjectionItem.java:136)
at com.arcadedb.query.sql.parser.Projection.calculateSingle(Projection.java:141)
at com.arcadedb.query.sql.executor.ProjectionCalculationStep.calculateProjections(ProjectionCalculationStep.java:66)
at com.arcadedb.query.sql.executor.ProjectionCalculationStep$1.next(ProjectionCalculationStep.java:51)
at com.arcadedb.query.sql.parser.LocalResultSet.next(LocalResultSet.java:72)
at com.arcadedb.console.Console.executeSQL(Console.java:661)
at com.arcadedb.console.Console.execute(Console.java:294)
at com.arcadedb.console.Console.parse(Console.java:787)
at com.arcadedb.console.Console.interactiveMode(Console.java:150)
at com.arcadedb.console.Console.execute(Console.java:207)
at com.arcadedb.console.Console.main(Console.java:167)`
Using a vector for the key value in the function also fails but that is due to the conversion of the key into a float array.
`SELECT vectorNeighbors('Word[name,vector]', [1.0, 1.0, 1.0], 10)
ERROR:
java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [F ([Ljava.lang.Object; and [F are in module java.base of loader 'bootstrap')
at com.github.jelmerk.knn.DistanceFunctions$FloatCosineDistance.distance(DistanceFunctions.java:87)
at com.arcadedb.index.vector.HnswVectorIndex.findNearest(HnswVectorIndex.java:527)
at com.arcadedb.index.vector.HnswVectorIndex.findNeighborsFromVector(HnswVectorIndex.java:280)
at com.arcadedb.query.sql.function.vector.SQLFunctionVectorNeighbors.execute(SQLFunctionVectorNeighbors.java:67)
at com.arcadedb.query.sql.parser.FunctionCall.execute(FunctionCall.java:132)
at com.arcadedb.query.sql.parser.FunctionCall.execute(FunctionCall.java:85)
at com.arcadedb.query.sql.parser.LevelZeroIdentifier.execute(LevelZeroIdentifier.java:65)
at com.arcadedb.query.sql.parser.BaseIdentifier.execute(BaseIdentifier.java:66)
at com.arcadedb.query.sql.parser.BaseExpression.execute(BaseExpression.java:145)
at com.arcadedb.query.sql.parser.Expression.execute(Expression.java:87)
at com.arcadedb.query.sql.parser.ProjectionItem.execute(ProjectionItem.java:136)
at com.arcadedb.query.sql.parser.Projection.calculateSingle(Projection.java:141)
at com.arcadedb.query.sql.executor.ProjectionCalculationStep.calculateProjections(ProjectionCalculationStep.java:66)
at com.arcadedb.query.sql.executor.ProjectionCalculationStep$1.next(ProjectionCalculationStep.java:51)
at com.arcadedb.query.sql.parser.LocalResultSet.next(LocalResultSet.java:72)
at com.arcadedb.console.Console.executeSQL(Console.java:661)
at com.arcadedb.console.Console.execute(Console.java:294)
at com.arcadedb.console.Console.parse(Console.java:787)
at com.arcadedb.console.Console.interactiveMode(Console.java:150)
at com.arcadedb.console.Console.execute(Console.java:207)
at com.arcadedb.console.Console.main(Console.java:167)`
The conversion could be fixed in the SQLFunctionVectorNeighbors class to properly convert the parameter into a float array as expected by the distance function but it might be better to preserve the semantics of the documentation and first do a query against the node class to obtain the embedding of the key value so that the caller doesn't have to pass a potential very large array of values.