>From Hongyu Shi <[email protected]>:

Hongyu Shi has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21649?usp=email )


Change subject: [ASTERIXDB-3817][COMP] List every accepted similarity alias
......................................................................

[ASTERIXDB-3817][COMP] List every accepted similarity alias

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
The `similarity` diagnostic was built from VectorSimilarityMetric.canonical(),
so it named only the canonical spelling of each metric. fromAlias() accepts more
than that. It also takes l2, l2_squared and cosine similarity, so the message
told the user a spelling was invalid when the parser would have taken it.

Build the list from aliases() instead, which is already the single source of
truth for what is accepted, and add the negative test the diagnostic never had.

Ext-ref: MB-73290

Co-Authored-By: Claude Opus 5 <[email protected]>
Change-Id: I07be9ec20dd45c73d404ba4ef09ede860509dc17
---
M 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/create-index-vtree-bad-similarity/create-index-vtree-bad-similarity.01.ddl.sqlpp
M 
asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VectorIndexDeclUtil.java
3 files changed, 52 insertions(+), 3 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/49/21649/1

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
index 99bd8d7..376c7e5 100644
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
@@ -80,6 +80,12 @@
         </compilation-unit>
     </test-case>
     <test-case FilePath="vector">
+        <compilation-unit name="create-index-vtree-bad-similarity">
+            <output-dir 
compare="Text">create-index-vtree-bad-similarity</output-dir>
+            <expected-error>Allowed values: EUCLIDEAN, L2, EUCLIDEAN_SQUARED, 
L2_SQUARED, COSINE, COSINE SIMILARITY, DOT</expected-error>
+        </compilation-unit>
+    </test-case>
+    <test-case FilePath="vector">
         <compilation-unit name="create-index-vtree-type-mismatch">
             <output-dir 
compare="Text">create-index-vtree-type-mismatch</output-dir>
             <expected-error>VECTOR field annotation is not supported for TYPE 
BTREE</expected-error>
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/create-index-vtree-bad-similarity/create-index-vtree-bad-similarity.01.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/create-index-vtree-bad-similarity/create-index-vtree-bad-similarity.01.ddl.sqlpp
new file mode 100644
index 0000000..c35c0ba
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/create-index-vtree-bad-similarity/create-index-vtree-bad-similarity.01.ddl.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+// An unrecognized `similarity` is rejected, and the diagnostic lists every 
accepted spelling --
+// including the aliases l2, l2_squared and cosine similarity, which 
fromAlias() accepts but which
+// a canonical-names-only list would wrongly imply are invalid.
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE MovieType AS {
+  id: int,
+  embedding: [double]
+};
+
+CREATE DATASET MovieSmall(MovieType) PRIMARY KEY id;
+
+CREATE INDEX idx_emb
+  ON MovieSmall(embedding VECTOR)
+  TYPE VTREE
+  WITH { "dimension": 4, "similarity": "manhattan" }
+  EXCLUDE UNKNOWN KEY;
diff --git 
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VectorIndexDeclUtil.java
 
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VectorIndexDeclUtil.java
index abc1ebc..9b12e72 100644
--- 
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VectorIndexDeclUtil.java
+++ 
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VectorIndexDeclUtil.java
@@ -64,9 +64,15 @@
     /**
      * Human-readable list of the accepted {@code similarity} values, derived 
from
      * {@link VectorSimilarityMetric} so it never drifts from the actual set 
of recognized metrics.
+     * <p>
+     * Every alias is listed, not just the canonical name: {@code l2}, {@code 
l2_squared} and
+     * {@code cosine similarity} are accepted by {@link 
VectorSimilarityMetric#fromAlias}, so a
+     * diagnostic that omits them tells the user a spelling is invalid when it 
is not.
      */
-    private static final String ALLOWED_SIMILARITY_VALUES = 
Arrays.stream(VectorSimilarityMetric.values())
-            .map(m -> 
m.canonical().toUpperCase(Locale.ROOT)).collect(Collectors.joining(", "));
+    @AiProvenance(agent = AiProvenance.Agent.CLAUDE_OPUS_5, tool = 
AiProvenance.Tool.CLAUDE_CODE_CLI, contributionKind = 
AiProvenance.ContributionKind.ASSISTED)
+    private static final String ALLOWED_SIMILARITY_VALUES =
+            Arrays.stream(VectorSimilarityMetric.values()).flatMap(m -> 
m.aliases().stream())
+                    .map(alias -> 
alias.toUpperCase(Locale.ROOT)).collect(Collectors.joining(", "));

     private VectorIndexDeclUtil() {
     }
@@ -289,7 +295,7 @@
      * rebuilt identically. Drawing it at DDL time rather than at 
job-generation time is what makes it
      * persistable — the {@code Metadata.Index} record is written before the 
creation job is built.
      */
-    @AiProvenance(agent = AiProvenance.Agent.CLAUDE_OPUS_5, tool = 
AiProvenance.Tool.CLAUDE_CODE_UI, contributionKind = 
AiProvenance.ContributionKind.GENERATED)
+    @AiProvenance(agent = AiProvenance.Agent.CLAUDE_OPUS_5, tool = 
AiProvenance.Tool.CLAUDE_CODE_UI, contributionKind = 
AiProvenance.ContributionKind.ASSISTED)
     private static long validateSeed(AdmObjectNode node) throws 
CompilationException {
         IAdmNode seedNode = node.get(SEED);
         if (seedNode == null) {

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21649?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I07be9ec20dd45c73d404ba4ef09ede860509dc17
Gerrit-Change-Number: 21649
Gerrit-PatchSet: 1
Gerrit-Owner: Hongyu Shi <[email protected]>

Reply via email to