Vector SQL Tests¶
There are 29 tests covering SQL vector functions for math, aggregations, distance metrics, normalization, quantization, native INT8 encoding, sparse vectors, and LSM_VECTOR index creation and search.
Overview¶
Tests validate:
- Vector math functions: element-wise add, multiply, scale, and scalar broadcast
- Vector aggregations (
vectorSum,vectorAvg,vectorMin,vectorMax) across multiple rows - Distance functions: cosine similarity, L2 (Euclidean), dot product, Manhattan/L1
- Vector normalization, magnitude/L2-norm aliases, clamping, and null detection
- Score-shaping helpers:
vector.scoreTransform,vector.multiScore,vector.sparsity - Vector quantization (
INT8,BINARY) and nativeINT8encoding viaLSM_VECTOR LSM_VECTOR/LSM_SPARSE_VECTORindex creation with rich metadatavectorNeighbors/vector.neighbors/vector.sparseNeighborstop-K retrieval (by vector, by key, grouped, parameterized, and over OpenCypher)
Test Cases¶
Vector Math¶
- test_vector_math_functions: Tests
vectorAdd([1,2],[3,4]),vectorMultiply(element-wise), andvectorScale(v, scalar). - test_vector_add_subtract_scalar_broadcast:
vectorAdd/vectorSubtractbroadcast a scalar operand across the vector (andvectorAddis commutative for scalar + vector).
Vector Aggregations¶
- test_vector_aggregations: Tests
vectorSum,vectorAvg,vectorMin,vectorMaxelement-wise across rows of anARRAY_OF_FLOATSproperty.
Distance Metrics¶
- test_vector_distance_functions:
vectorCosineSimilarity,vectorL2Distance, andvectorDotProducton orthogonal vectors. - test_vector_manhattan_distance:
vectorManhattanDistance/vectorL1Distance(and the dottedvector.manhattanDistance/vector.l1Distancealiases) compute the L1 distance.
Normalization & Helpers¶
- test_vector_normalization:
vectorNormalize([3,4])returns the unit vector[0.6, 0.8]. - test_vector_l2_norm_aliases:
vectorL2Norm/vector.l2Normare aliases ofvectorMagnitude. - test_vector_clamp:
vectorClamp/vector.clamplimit each element to a[min, max]range. - test_vector_has_null:
vectorHasNull/vector.hasNulldetect NaN/null elements (e.g.sqrt(-1.0)).
Score Shaping¶
- test_vector_score_transform_modes:
vector.scoreTransformsupportsLN(==LOG) andTANHmodes. - test_vector_multi_score_fusion:
vector.multiScorefuses a list of scores;MAXreturns the largest. - test_vector_sparsity_modes:
vector.sparsityreports a default sparsity ratio plusL0andGMEANmodes.
Quantization & Encoding¶
- test_vector_quantization_functions:
vectorQuantizeInt8(v)runs and returns a non-null result. - test_int8_quantization_boundary_condition_sql: INT8 quantized
LSM_VECTORindex (Dim=16, N=10) builds and is searchable viavectorNeighbors. - test_create_index_with_quantization_int8_sql: Creates an
INT8quantizedLSM_VECTORindex, inserts N=50 vectors, and verifiesvectorNeighborssearch succeeds. - test_create_index_with_quantization_binary_sql: Creates a
BINARYquantizedLSM_VECTORindex (Dim=128) withstoreVectorsInGraphand verifies search. - test_create_index_with_native_int8_encoding_sql: Creates an
LSM_VECTORindex on aBINARYproperty with"quantization": "NONE", "encoding": "INT8"and verifies the metadata (skips if the build does not exposeencoding). - test_vector_neighbors_on_native_int8_storage_sql: Verifies
vectorNeighborsworks against native INT8-encoded storage ingested as byte arrays (skips if unsupported).
Index Creation & Metadata¶
- test_sql_create_index_builds_vector_graph_immediately_by_default: A
LSM_VECTORindex created via SQL is queryable immediately withvectorNeighbors. - test_create_index_with_rich_metadata_sql:
LSM_VECTORcreation supportsdimensions,similarity,quantization,idPropertyName,storeVectorsInGraph,addHierarchy,locationCacheSize,graphBuildCacheSize, andmutationsBeforeRebuild; verifies the resulting Java metadata.
Neighbor Search¶
- test_vector_neighbors:
vectorNeighbors(indexName, vector, k)on a basicLSM_VECTORindex. - test_vector_neighbors_accepts_parameterized_index_and_vector:
vectorNeighbors(?, ?, ?)accepts bound index name, vector, and k parameters. - test_vector_neighbors_by_key_sql:
vectorNeighbors('Word[vector]', 'docA', 3)searches from an existing record key. - test_vector_neighbors_by_key_opencypher: OpenCypher exposes
CALL vector.neighbors(...)with key-based lookup (skips if OpenCypher is unavailable). - test_vector_neighbors_group_by_sql:
vector.neighborssupports{ groupBy, groupSize }options. - test_sparse_vector_neighbors_sql:
LSM_SPARSE_VECTORindex plusvector.sparseNeighborstop-K retrieval (skips ifLSM_SPARSE_VECTORis unsupported).
End-to-End Search¶
- test_vector_delete_and_search_others_sql: Inserts 100 random vectors, deletes every 10th, and verifies nearest-match search with
vectorL2DistanceandORDER BY. - test_document_vector_search_sql: KNN search on a
DOCUMENTtype usingvectorL2DistanceandORDER BY ... LIMIT.
Pattern¶
# Create vector property and LSM_VECTOR index
db.command("sql", "CREATE VERTEX TYPE Movie")
db.command("sql", "CREATE PROPERTY Movie.embedding ARRAY_OF_FLOATS")
db.command(
"sql",
"""
CREATE INDEX ON Movie (embedding)
LSM_VECTOR
METADATA { "dimensions": 4, "similarity": "COSINE" }
""",
)
# Insert vectors
with db.transaction():
db.command("sql", "INSERT INTO Movie SET embedding = [1.0, 0.0, 0.0, 0.0]")
# Top-K search
rows = db.query(
"sql",
"SELECT expand(vectorNeighbors('Movie[embedding]', [1.0, 0.0, 0.0, 0.0], 2))",
).to_list()
Key Functions¶
- Math:
vectorAdd(),vectorSubtract(),vectorMultiply(),vectorScale() - Aggregation:
vectorSum(),vectorAvg(),vectorMin(),vectorMax() - Distance:
vectorCosineSimilarity(),vectorL2Distance(),vectorDotProduct(),vectorManhattanDistance()/vectorL1Distance() - Helpers:
vectorNormalize(),vectorMagnitude()/vectorL2Norm(),vectorClamp(),vectorHasNull() - Score shaping:
vector.scoreTransform(),vector.multiScore(),vector.sparsity() - Quantization/encoding:
vectorQuantizeInt8();LSM_VECTORquantization(INT8,BINARY,NONE) andencoding(INT8) metadata - Schema:
ARRAY_OF_FLOATS(dense),ARRAY_OF_INTEGERS+ARRAY_OF_FLOATS(sparse),BINARY(native-encoded) properties - Indexes:
LSM_VECTOR,LSM_SPARSE_VECTOR - Search:
vectorNeighbors(),vector.neighbors(),vector.sparseNeighbors()```