You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2026/06/29 21:32:22 UTC

[XL] Change in asterixdb[master]: DON'T MERGE: dummy vector distance patches for CI

From Ian Maxon <im...@apache.org>:

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


Change subject: DON'T MERGE: dummy vector distance patches for CI
......................................................................

DON'T MERGE: dummy vector distance patches for CI

Change-Id: I45176e7da13ed222f48bb36b13f0ab4074a0bdb9
---
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.10.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.11.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.12.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.13.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.14.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.15.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.16.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.5.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.6.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.7.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.8.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.9.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.99.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.10.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.11.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.12.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.13.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.14.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.15.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.16.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.3.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.4.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.5.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.6.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.7.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.8.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.9.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/CosineDistanceDescriptor.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/DotProductDescriptor.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanDistanceDescriptor.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanSquaredDistanceDescriptor.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorDistanceScalarEvaluator.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorListDecoder.java
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/VectorDistanceCalculation.java
M hyracks-fullstack/pom.xml
44 files changed, 1,181 insertions(+), 0 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/85/21385/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
new file mode 100644
index 0000000..27d4ddf
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/VectorQueries.xml
@@ -0,0 +1,25 @@
+<!--
+  ~ 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.
+  -->
+<test-group name="vector">
+    <test-case FilePath="vector">
+        <compilation-unit name="distance-functions">
+            <output-dir compare="Clean-JSON">distance-functions</output-dir>
+        </compilation-unit>
+    </test-case>
+</test-group>
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.1.ddl.sqlpp
new file mode 100644
index 0000000..5353267
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.1.ddl.sqlpp
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+drop  dataverse VectorVerse if exists;
+create  dataverse VectorVerse;
+
+use VectorVerse;
+
+
+create type VectorVerse.OpenType as
+{
+ id : int
+};
+
+create  dataset vectorDataset(VectorVerse.OpenType) primary key id;
+create  dataset vectorDataset2(VectorVerse.OpenType) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.10.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.10.query.sqlpp
new file mode 100644
index 0000000..e0b6307
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.10.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT row.name AS name, l2_squared_distance(row.embedding, [0.1, 0.2]) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.11.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.11.query.sqlpp
new file mode 100644
index 0000000..609db64
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.11.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT cosine_distance([float("1.0"), float("0.0")], [float("0.0"), float("1.0")]) AS distance;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.12.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.12.query.sqlpp
new file mode 100644
index 0000000..9665bd4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.12.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT euclidean_squared_distance([double("1.0"), double("2.0")], [double("2.0"), double("4.0")]) AS distance;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.13.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.13.query.sqlpp
new file mode 100644
index 0000000..8abb935
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.13.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT euclidean_distance([float("1.0"), float("2.0")], [double("1.0"), double("2.0")]) AS distance;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.14.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.14.query.sqlpp
new file mode 100644
index 0000000..e703792
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.14.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT euclidean_distance({"v": [float("0.1"), float("0.2")]}.v, [float("0.1"), float("0.2")]) AS distance;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.15.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.15.query.sqlpp
new file mode 100644
index 0000000..7417580
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.15.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT euclidean_distance({"v": [1, 2]}.v, [1, 2]) AS distance;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.16.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.16.query.sqlpp
new file mode 100644
index 0000000..f5f5877
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.16.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT euclidean_distance([float("1.0"), double("2.0")], [float("1.0"), float("2.0")]) AS distance;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.2.update.sqlpp
new file mode 100644
index 0000000..c3d5dc8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.2.update.sqlpp
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+use VectorVerse;
+
+
+
+INSERT INTO vectorDataset([
+  { "id": 1, "name": "Alpha", "embedding": [0.12, 0.53, 0.34, 0.78, 0.23, 0.91, 0.45, 0.67, 0.89, 0.11, 0.39, 0.44, 0.76, 0.31, 0.22, 0.68, 0.57, 0.49, 0.94, 0.61] },
+  { "id": 2, "name": "Beta", "embedding": [0.15, 0.51, 0.35, 0.77, 0.25, 0.90, 0.44, 0.66, 0.88, 0.10, 0.38, 0.43, 0.75, 0.32, 0.23, 0.67, 0.56, 0.48, 0.93, 0.60] },
+  { "id": 3, "name": "Gamma", "embedding": [0.1, 0.2] },
+  { "id": 4, "name": "Delta", "embedding": [0.1, 0.2, 0.3] },
+  { "id": 5, "name": "Epsilon", "embedding": [1.0, 1.0] },
+  { "id": 6, "name": "Zeta", "embedding": [0.0, 0.0] },
+  { "id": 7, "name": "Eta", "embedding": [0.12, 0.53, 0.34, 0.78, 0.23, 0.91, 0.45, 0.67, 0.89, 0.11, 0.39, 0.44, 0.76, 0.31, 0.22, 0.68, 0.57, 0.49, 0.94, 0.61] },
+  { "id": 8, "name": "InvalidString", "embedding": "not a vector" },
+  { "id": 9, "name": "InvalidDate", "embedding": datetime("2023-01-01T00:00:00Z") },
+  { "id": 10, "name": "BadArray", "embedding": ["a", "b", "c"] }
+]);
+
+
+INSERT INTO vectorDataset2([
+  { "id": 1, "name": "Theta", "embedding": [0.2, 0.4] },
+  { "id": 2, "name": "Iota", "embedding": [0.5, 0.5] }
+]);
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.3.query.sqlpp
new file mode 100644
index 0000000..ddc987f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.3.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+USE VectorVerse;
+SELECT row.name AS name, cosine_distance(row.embedding, [0.1, 0.2]) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
+
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.4.query.sqlpp
new file mode 100644
index 0000000..0ae941b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.4.query.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+FROM vectorDataset row1, vectorDataset2 row2
+SELECT row1.name AS name1, row2.name AS name2,
+euclidean_distance(row1.embedding, row2.embedding) AS distance
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
+
+
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.5.query.sqlpp
new file mode 100644
index 0000000..95b5326
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.5.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT row.name AS name, euclidean_distance(row.embedding, [0.1, 0.2]) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.6.query.sqlpp
new file mode 100644
index 0000000..351fd04
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+WITH const_emb AS ([0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34,0.12, 0.53, 0.34])
+SELECT row.name AS name , euclidean_distance(row.embedding, const_emb) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
+
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.7.query.sqlpp
new file mode 100644
index 0000000..1e37ce9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.7.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT row.name AS name, euclidean_squared_distance(row.embedding, [0.1, 0.2]) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.8.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.8.query.sqlpp
new file mode 100644
index 0000000..3adc4ba
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.8.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT row.name AS name, dot_product(row.embedding, [0.1, 0.2]) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.9.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.9.query.sqlpp
new file mode 100644
index 0000000..8b08686
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.9.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+USE VectorVerse;
+SELECT row.name AS name, l2_distance(row.embedding, [0.1, 0.2]) AS distance
+FROM vectorDataset row
+ORDER BY distance ASC NULLS LAST
+LIMIT 5;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.99.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.99.ddl.sqlpp
new file mode 100644
index 0000000..3778894
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/vector/distance-functions/vector_distance.99.ddl.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+drop  dataverse VectorVerse;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.10.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.10.adm
new file mode 100644
index 0000000..1d459e7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.10.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.0, "name": "Gamma" }
+{ "distance": 0.05000000000000001, "name": "Zeta" }
+{ "distance": 1.4500000000000002, "name": "Epsilon" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.11.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.11.adm
new file mode 100644
index 0000000..5294e47
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.11.adm
@@ -0,0 +1 @@
+{ "distance": 1.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.12.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.12.adm
new file mode 100644
index 0000000..975e6de
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.12.adm
@@ -0,0 +1 @@
+{ "distance": 5.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.13.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.13.adm
new file mode 100644
index 0000000..c4bd9c3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.13.adm
@@ -0,0 +1 @@
+{ "distance": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.14.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.14.adm
new file mode 100644
index 0000000..c4bd9c3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.14.adm
@@ -0,0 +1 @@
+{ "distance": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.15.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.15.adm
new file mode 100644
index 0000000..c4bd9c3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.15.adm
@@ -0,0 +1 @@
+{ "distance": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.16.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.16.adm
new file mode 100644
index 0000000..c4bd9c3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.16.adm
@@ -0,0 +1 @@
+{ "distance": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.3.adm
new file mode 100644
index 0000000..ae17619
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.3.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.0, "name": "Gamma" }
+{ "distance": 0.0513167019494862, "name": "Epsilon" }
+{ "distance": null, "name": "Zeta" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.4.adm
new file mode 100644
index 0000000..625e805
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.4.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.223606797749979, "name1": "Gamma", "name2": "Theta" }
+{ "distance": 0.447213595499958, "name1": "Zeta", "name2": "Theta" }
+{ "distance": 0.5, "name1": "Gamma", "name2": "Iota" }
+{ "distance": 0.7071067811865476, "name1": "Zeta", "name2": "Iota" }
+{ "distance": 0.7071067811865476, "name1": "Epsilon", "name2": "Iota" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.5.adm
new file mode 100644
index 0000000..ca7d1bd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.5.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.0, "name": "Gamma" }
+{ "distance": 0.223606797749979, "name": "Zeta" }
+{ "distance": 1.2041594578792296, "name": "Epsilon" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.6.adm
new file mode 100644
index 0000000..69a9304
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.6.adm
@@ -0,0 +1,5 @@
+{ "distance": null, "name": "Zeta" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
+{ "distance": null, "name": "Delta" }
+{ "distance": null, "name": "InvalidString" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.7.adm
new file mode 100644
index 0000000..1d459e7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.7.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.0, "name": "Gamma" }
+{ "distance": 0.05000000000000001, "name": "Zeta" }
+{ "distance": 1.4500000000000002, "name": "Epsilon" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.8.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.8.adm
new file mode 100644
index 0000000..cd45bbf
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.8.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.0, "name": "Zeta" }
+{ "distance": 0.05000000000000001, "name": "Gamma" }
+{ "distance": 0.30000000000000004, "name": "Epsilon" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.9.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.9.adm
new file mode 100644
index 0000000..ca7d1bd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/vector/distance-functions/vector_distance.9.adm
@@ -0,0 +1,5 @@
+{ "distance": 0.0, "name": "Gamma" }
+{ "distance": 0.223606797749979, "name": "Zeta" }
+{ "distance": 1.2041594578792296, "name": "Epsilon" }
+{ "distance": null, "name": "Alpha" }
+{ "distance": null, "name": "Beta" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 9ca46d7..4980447 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -23,6 +23,7 @@
         <!ENTITY GeoQueries SYSTEM "queries_sqlpp/geojson/GeoJSONQueries.xml">
         <!ENTITY TemporalQueries SYSTEM "queries_sqlpp/temporal/TemporalQueries.xml">
         <!ENTITY CBOJoinQueries SYSTEM "queries_sqlpp/cbo-join/CBOJoinQueries.xml">
+        <!ENTITY VectorQueries SYSTEM "queries_sqlpp/vector/VectorQueries.xml">
         ]>
 <test-suite xmlns="urn:xml.testframework.asterix.apache.org" ResultOffsetPath="results" QueryOffsetPath="queries_sqlpp" QueryFileExtension=".sqlpp" SourceLocation="true">
   &ObjectsQueries;
@@ -31,4 +32,5 @@
   &TemporalQueries;
   &SqlppQueries;
   &CBOJoinQueries;
+  &VectorQueries;
 </test-suite>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
index f13f777..58b7329 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
@@ -166,6 +166,13 @@
         addFunctionMapping("variance_samp", "var_samp");
         addFunctionMapping("variance_pop", "var_pop");
 
+        //Vector functions
+        addFunctionMapping("l2_distance", "euclidean-distance");
+        addFunctionMapping("l2_squared_distance", "euclidean-squared-distance");
+        addFunctionMapping("cosine_distance", "cosine-distance");
+        addFunctionMapping("dot_product", "dot-product");
+
+
         // OGC SFA geospatial function aliases.
         // Many GIS dialects use CamelCase (e.g. ST_IsEmpty) which lowercases to
         // compressed forms like st_isempty; these don't normalize to the canonical
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index a74ccf7..a8767a4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -1196,6 +1196,13 @@
     public static final FunctionIdentifier GET_OVERLAPPING_INTERVAL =
             FunctionConstants.newAsterix("get-overlapping-interval", 2);
 
+    //Vector functions
+    public static final FunctionIdentifier EUCLIDEAN_DISTANCE = FunctionConstants.newAsterix("euclidean-distance", 2);
+    public static final FunctionIdentifier EUCLIDEAN_SQUARED_DISTANCE =
+            FunctionConstants.newAsterix("euclidean-squared-distance", 2);
+    public static final FunctionIdentifier COSINE_DISTANCE = FunctionConstants.newAsterix("cosine-distance", 2);
+    public static final FunctionIdentifier DOT_PRODUCT = FunctionConstants.newAsterix("dot-product", 2);
+
     // Temporal functions
     public static final FunctionIdentifier UNIX_TIME_FROM_DATE_IN_DAYS =
             FunctionConstants.newAsterix("unix-time-from-date-in-days", 1);
@@ -1920,6 +1927,12 @@
         addFunction(SQL_KURTOSIS_DISTINCT, NullableDoubleTypeComputer.INSTANCE, true);
         addFunction(SCALAR_SQL_KURTOSIS_DISTINCT, NullableDoubleTypeComputer.INSTANCE, true);
 
+        // Vector functions
+        addFunction(EUCLIDEAN_DISTANCE, ADoubleTypeComputer.INSTANCE, true);
+        addFunction(EUCLIDEAN_SQUARED_DISTANCE, ADoubleTypeComputer.INSTANCE, true);
+        addFunction(COSINE_DISTANCE, ADoubleTypeComputer.INSTANCE, true);
+        addFunction(DOT_PRODUCT, ADoubleTypeComputer.INSTANCE, true);
+
         // Window functions
 
         addFunction(CUME_DIST, ADoubleTypeComputer.INSTANCE, false);
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/CosineDistanceDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/CosineDistanceDescriptor.java
new file mode 100644
index 0000000..938669e
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/CosineDistanceDescriptor.java
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.vector;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.utils.VectorDistanceCalculation;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class CosineDistanceDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    public final static IFunctionDescriptorFactory FACTORY = CosineDistanceDescriptor::new;
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return BuiltinFunctions.COSINE_DISTANCE;
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(final IEvaluatorContext ctx) throws HyracksDataException {
+                return new VectorDistanceScalarEvaluator(ctx, args, getIdentifier(),
+                        VectorDistanceCalculation::cosineDistance, sourceLoc);
+            }
+        };
+
+    }
+
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/DotProductDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/DotProductDescriptor.java
new file mode 100644
index 0000000..536c240
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/DotProductDescriptor.java
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.vector;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.utils.VectorDistanceCalculation;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class DotProductDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    public final static IFunctionDescriptorFactory FACTORY = DotProductDescriptor::new;
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return BuiltinFunctions.DOT_PRODUCT;
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(final IEvaluatorContext ctx) throws HyracksDataException {
+                return new VectorDistanceScalarEvaluator(ctx, args, getIdentifier(),
+                        VectorDistanceCalculation::dotProduct, sourceLoc);
+            }
+        };
+
+    }
+
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanDistanceDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanDistanceDescriptor.java
new file mode 100644
index 0000000..4ade6a6
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanDistanceDescriptor.java
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.vector;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.utils.VectorDistanceCalculation;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class EuclideanDistanceDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    public final static IFunctionDescriptorFactory FACTORY = EuclideanDistanceDescriptor::new;
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return BuiltinFunctions.EUCLIDEAN_DISTANCE;
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(final IEvaluatorContext ctx) throws HyracksDataException {
+                return new VectorDistanceScalarEvaluator(ctx, args, getIdentifier(),
+                        VectorDistanceCalculation::euclidean, sourceLoc);
+            }
+        };
+
+    }
+
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanSquaredDistanceDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanSquaredDistanceDescriptor.java
new file mode 100644
index 0000000..d8cd083
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/EuclideanSquaredDistanceDescriptor.java
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.vector;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.utils.VectorDistanceCalculation;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class EuclideanSquaredDistanceDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    public final static IFunctionDescriptorFactory FACTORY = EuclideanSquaredDistanceDescriptor::new;
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return BuiltinFunctions.EUCLIDEAN_SQUARED_DISTANCE;
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(final IEvaluatorContext ctx) throws HyracksDataException {
+                return new VectorDistanceScalarEvaluator(ctx, args, getIdentifier(),
+                        VectorDistanceCalculation::euclideanSquared, sourceLoc);
+            }
+        };
+
+    }
+
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorDistanceScalarEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorDistanceScalarEvaluator.java
new file mode 100644
index 0000000..e5fb255
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorDistanceScalarEvaluator.java
@@ -0,0 +1,207 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.vector;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.function.ToDoubleBiFunction;
+
+import org.apache.asterix.common.exceptions.RuntimeDataException;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.ADouble;
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.exceptions.ExceptionUtil;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.runtime.evaluators.common.ListAccessor;
+import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class VectorDistanceScalarEvaluator implements IScalarEvaluator {
+
+    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private final DataOutput dataOutput = resultStorage.getDataOutput();
+
+    private final IPointable pointableLeft;
+    private final IPointable pointableRight;
+    private final IScalarEvaluator evaluatorLeft;
+    private final IScalarEvaluator evaluatorRight;
+
+    // Function ID, for error reporting.
+    private final FunctionIdentifier funcId;
+    private final SourceLocation sourceLoc;
+    private final ToDoubleBiFunction<double[], double[]> distanceFunc;
+
+    private final AMutableDouble aDouble = new AMutableDouble(-1);
+    private final VectorListDecoder decoder;
+    private final IEvaluatorContext ctx;
+
+    private final ISerializerDeserializer<ADouble> doubleSerde =
+            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+
+    private final ListAccessor listAccessorLeft = new ListAccessor();
+    private final ListAccessor listAccessorRight = new ListAccessor();
+    private final boolean isConstantLeft;
+    private final boolean isConstantRight;
+    private double[] vectorArgsLeft = new double[0];
+    private double[] vectorArgsRight = new double[0];
+
+    public VectorDistanceScalarEvaluator(IEvaluatorContext context, final IScalarEvaluatorFactory[] evaluatorFactories,
+            FunctionIdentifier funcId, ToDoubleBiFunction<double[], double[]> distanceFunc, SourceLocation sourceLoc)
+            throws HyracksDataException {
+        this.distanceFunc = distanceFunc;
+        this.funcId = funcId;
+        this.sourceLoc = sourceLoc;
+        this.decoder = new VectorListDecoder(sourceLoc, funcId);
+        this.ctx = context;
+
+        pointableLeft = new VoidPointable();
+        pointableRight = new VoidPointable();
+        evaluatorLeft = evaluatorFactories[0].createScalarEvaluator(context);
+        evaluatorRight = evaluatorFactories[1].createScalarEvaluator(context);
+
+        boolean constantLeft = false;
+        boolean constantRight = false;
+        try {
+
+            if (evaluatorFactories[0] instanceof ConstantEvalFactory) {
+                constantLeft = true;
+                ATypeTag leftArgType = resolveConstantArgType(evaluatorLeft, pointableLeft, listAccessorLeft);
+                if (leftArgType != null) {
+                    vectorArgsLeft = decoder.createArrayFromList(listAccessorLeft,
+                            decoder.ensureDoubleCapacity(vectorArgsLeft, listAccessorLeft.size()));
+                }
+            }
+
+            if (evaluatorFactories[1] instanceof ConstantEvalFactory) {
+                constantRight = true;
+                ATypeTag rightArgType = resolveConstantArgType(evaluatorRight, pointableRight, listAccessorRight);
+                if (rightArgType != null) {
+                    vectorArgsRight = decoder.createArrayFromList(listAccessorRight,
+                            decoder.ensureDoubleCapacity(vectorArgsRight, listAccessorRight.size()));
+                }
+            }
+
+        } catch (IOException e) {
+            constantLeft = false;
+            constantRight = false;
+        }
+
+        this.isConstantLeft = constantLeft;
+        this.isConstantRight = constantRight;
+    }
+
+    @Override
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+        resultStorage.reset();
+        try {
+            if (!isConstantLeft) {
+                evaluatorLeft.evaluate(tuple, pointableLeft);
+            }
+            if (!isConstantRight) {
+                evaluatorRight.evaluate(tuple, pointableRight);
+            }
+
+            if (PointableHelper.checkAndSetMissingOrNull(result, pointableLeft, pointableRight)) {
+                return;
+            }
+
+            if (!isConstantLeft && !checkListTypeAndReset(result, listAccessorLeft, pointableLeft, 0)) {
+                return;
+            }
+            if (!isConstantRight && !checkListTypeAndReset(result, listAccessorRight, pointableRight, 1)) {
+                return;
+            }
+
+            if (listAccessorLeft.size() != listAccessorRight.size() || listAccessorLeft.size() == 0
+                    || listAccessorRight.size() == 0) {
+                ExceptionUtil.warnFunctionEvalFailed(ctx, sourceLoc, funcId,
+                        "vector distance expects equal-length non-empty lists");
+                PointableHelper.setNull(result);
+                return;
+            }
+
+            vectorArgsLeft = isConstantLeft ? vectorArgsLeft
+                    : decoder.createArrayFromList(listAccessorLeft,
+                            decoder.ensureDoubleCapacity(vectorArgsLeft, listAccessorLeft.size()));
+            vectorArgsRight = isConstantRight ? vectorArgsRight
+                    : decoder.createArrayFromList(listAccessorRight,
+                            decoder.ensureDoubleCapacity(vectorArgsRight, listAccessorRight.size()));
+
+            double distanceCal = distanceFunc.applyAsDouble(vectorArgsLeft, vectorArgsRight);
+
+            if (Double.isNaN(distanceCal)) {
+                ExceptionUtil.warnFunctionEvalFailed(ctx, sourceLoc, funcId, "distance computed to NaN");
+                PointableHelper.setNull(result);
+                return;
+            }
+            writeResult(distanceCal, dataOutput);
+            result.set(resultStorage);
+        } catch (RuntimeDataException e) {
+            ExceptionUtil.warnFunctionEvalFailed(ctx, sourceLoc, funcId, e.getMessage());
+            PointableHelper.setNull(result);
+        } catch (IOException e) {
+            ExceptionUtil.warnFunctionEvalFailed(ctx, sourceLoc, funcId, e.getMessage());
+            PointableHelper.setNull(result);
+        }
+    }
+
+    protected void writeResult(double distance, DataOutput dataOutput) throws IOException {
+        aDouble.setValue(distance);
+        doubleSerde.serialize(aDouble, dataOutput);
+    }
+
+    private boolean checkListTypeAndReset(IPointable result, ListAccessor listAccessor, IPointable pointable,
+            int argIdx) throws HyracksDataException {
+        if (!decoder.checkListType(pointable)) {
+            ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, funcId, pointable.getByteArray()[pointable.getStartOffset()],
+                    argIdx, new byte[] { ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG,
+                            ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG });
+            PointableHelper.setNull(result);
+            return false;
+        }
+        listAccessor.reset(pointable.getByteArray(), pointable.getStartOffset());
+        return true;
+    }
+
+    private ATypeTag resolveConstantArgType(IScalarEvaluator evaluator, IPointable pointable, ListAccessor listAccessor)
+            throws HyracksDataException {
+        evaluator.evaluate(null, pointable);
+        if (!decoder.checkListType(pointable)) {
+            // Do not fail at open/compile time for constants; return NULL at runtime with warning instead.
+            return null;
+        }
+        listAccessor.reset(pointable.getByteArray(), pointable.getStartOffset());
+        ATypeTag argType = decoder.resolveArgType(listAccessor);
+        return (argType != null && decoder.isNumericType(argType)) ? argType : null;
+    }
+
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorListDecoder.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorListDecoder.java
new file mode 100644
index 0000000..aa588a4
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/vector/VectorListDecoder.java
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.vector;
+
+import static org.apache.asterix.om.types.EnumDeserializer.ATYPETAGDESERIALIZER;
+
+import java.io.IOException;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
+import org.apache.asterix.runtime.evaluators.common.ListAccessor;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+
+/**
+ * Decodes AsterixDB list pointables into primitive arrays for the vector-distance evaluators. This isolates all of the
+ * type-tag handling, per-element extraction, and reusable-buffer management away from the evaluator, which only needs
+ * to orchestrate the decoding and feed the resulting typed arrays to the distance kernels.
+ */
+public final class VectorListDecoder {
+
+    private final SourceLocation sourceLoc;
+    private final IPointable tempArrVal = new VoidPointable();
+    private final ArrayBackedValueStorage storage = new ArrayBackedValueStorage();
+
+    public VectorListDecoder(SourceLocation sourceLoc, FunctionIdentifier funcId) {
+        this.sourceLoc = sourceLoc;
+    }
+
+    public boolean checkListType(IPointable pointable) {
+        return ATYPETAGDESERIALIZER.deserialize(pointable.getByteArray()[pointable.getStartOffset()]).isListType();
+    }
+
+    public double[] createArrayFromList(ListAccessor listAccessor, double[] primitiveArray) throws IOException {
+        ATypeTag typeTag = listAccessor.getItemType();
+        for (int i = 0; i < listAccessor.size(); i++) {
+            listAccessor.getOrWriteItem(i, tempArrVal, storage);
+            primitiveArray[i] = extractNumericVector(tempArrVal, typeTag);
+        }
+        return primitiveArray;
+    }
+
+    private double extractNumericVector(IPointable pointable, ATypeTag derivedTypeTag) throws TypeMismatchException {
+        byte[] data = pointable.getByteArray();
+        int offset = pointable.getStartOffset();
+        if (derivedTypeTag == ATypeTag.ANY) {
+            derivedTypeTag = ATYPETAGDESERIALIZER.deserialize(data[offset]);
+        }
+        if (isNumericType(derivedTypeTag)) {
+            return getValueFromTag(derivedTypeTag, data, offset);
+        } else {
+            throw new TypeMismatchException(sourceLoc, derivedTypeTag.serialize(), ATypeTag.DOUBLE.serialize());
+        }
+    }
+
+    private double getValueFromTag(ATypeTag typeTag, byte[] data, int offset) {
+        return switch (typeTag) {
+            case TINYINT -> AInt8SerializerDeserializer.getByte(data, offset + 1);
+            case SMALLINT -> AInt16SerializerDeserializer.getShort(data, offset + 1);
+            case INTEGER -> AInt32SerializerDeserializer.getInt(data, offset + 1);
+            case BIGINT -> AInt64SerializerDeserializer.getLong(data, offset + 1);
+            case FLOAT -> AFloatSerializerDeserializer.getFloat(data, offset + 1);
+            case DOUBLE -> ADoubleSerializerDeserializer.getDouble(data, offset + 1);
+            default -> Double.NaN;
+        };
+    }
+
+    public ATypeTag resolveArgType(ListAccessor listAccessor) {
+        ATypeTag itemType = listAccessor.getItemType();
+        return itemType == ATypeTag.ANY ? resolveAnyItemType(listAccessor) : itemType;
+    }
+
+    public ATypeTag resolveAnyItemType(ListAccessor listAccessor) {
+        if (listAccessor.size() == 0) {
+            return null;
+        }
+        try {
+            listAccessor.getOrWriteItem(0, this.tempArrVal, this.storage);
+            return EnumDeserializer.ATYPETAGDESERIALIZER
+                    .deserialize(tempArrVal.getByteArray()[tempArrVal.getStartOffset()]);
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    /**
+     * For {@code list(any)} values, {@link #resolveArgType(ListAccessor)} derives the effective item type from the first
+     * element's runtime tag. This helper checks that all items share that same runtime tag.
+     *
+     * @return the first mismatching runtime tag, or {@code null} if homogeneous / not {@code ANY}
+     */
+    public ATypeTag findFirstMismatchedAnyItemType(ListAccessor listAccessor, ATypeTag expectedItemTag)
+            throws IOException {
+        if (listAccessor.getItemType() != ATypeTag.ANY) {
+            return null;
+        }
+        for (int i = 0; i < listAccessor.size(); i++) {
+            ATypeTag actual = listAccessor.getItemTypeAt(i);
+            if (actual != expectedItemTag) {
+                return actual;
+            }
+        }
+        return null;
+    }
+
+    public boolean isNumericType(ATypeTag typeTag) {
+        return ATypeHierarchy.getTypeDomain(typeTag) == ATypeHierarchy.Domain.NUMERIC;
+    }
+
+    public double[] ensureDoubleCapacity(double[] arr, int size) {
+        return arr.length == size ? arr : new double[size];
+    }
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
index cef34ab..b4990ab 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
@@ -647,6 +647,10 @@
 import org.apache.asterix.runtime.evaluators.functions.temporal.WeekOfYearDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.YearMonthDurationGreaterThanComparatorDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.YearMonthDurationLessThanComparatorDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.vector.CosineDistanceDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.vector.DotProductDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.vector.EuclideanDistanceDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.vector.EuclideanSquaredDistanceDescriptor;
 import org.apache.asterix.runtime.runningaggregates.std.DenseRankRunningAggregateDescriptor;
 import org.apache.asterix.runtime.runningaggregates.std.NtileRunningAggregateDescriptor;
 import org.apache.asterix.runtime.runningaggregates.std.PercentRankRunningAggregateDescriptor;
@@ -1334,6 +1338,12 @@
         fc.add(GetOverlappingIntervalDescriptor.FACTORY);
         fc.add(DurationFromIntervalDescriptor.FACTORY);
 
+        // Vector functions
+        fc.add(EuclideanDistanceDescriptor.FACTORY);
+        fc.add(EuclideanSquaredDistanceDescriptor.FACTORY);
+        fc.add(CosineDistanceDescriptor.FACTORY);
+        fc.add(DotProductDescriptor.FACTORY);
+
         // Type functions.
         fc.add(GetTypeDescriptor.FACTORY);
         fc.add(IsArrayDescriptor.FACTORY);
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/VectorDistanceCalculation.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/VectorDistanceCalculation.java
new file mode 100644
index 0000000..6c5a426
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/VectorDistanceCalculation.java
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.runtime.utils;
+
+public class VectorDistanceCalculation {
+
+    public static double euclidean(double[] a, double[] b) {
+        if (a.length != b.length) {
+            return Double.NaN;
+        }
+        double sum = euclideanSquared(a, b);
+        return Math.sqrt(sum);
+    }
+
+    public static double euclideanSquared(double[] a, double[] b) {
+        if (a.length != b.length) {
+            return Double.NaN;
+        }
+        double sum = 0.0;
+        for (int i = 0; i < a.length; i++) {
+            double diff = a[i] - b[i];
+            sum += diff * diff;
+        }
+        return sum;
+    }
+
+    public static double cosineSimilarity(double[] a, double[] b) {
+        if (a.length != b.length) {
+            return Double.NaN;
+        }
+        double dot = 0.0, normA = 0.0, normB = 0.0;
+        for (int i = 0; i < a.length; i++) {
+            dot += a[i] * b[i];
+            normA += a[i] * a[i];
+            normB += b[i] * b[i];
+        }
+        if (normA == 0.0 || normB == 0.0 || Double.isNaN(normA) || Double.isNaN(normB) || Double.isNaN(dot)) {
+            return Double.NaN; // or throw exception for zero vector
+        }
+        return dot / (Math.sqrt(normA) * Math.sqrt(normB));
+    }
+
+    public static double cosineDistance(double[] a, double[] b) {
+        double similarity = cosineSimilarity(a, b);
+        return Double.isNaN(similarity) ? Double.NaN : 1.0 - similarity;
+    }
+
+    public static double dotProduct(double[] a, double[] b) {
+        if (a.length != b.length) {
+            return Double.NaN;
+        }
+        double sum = 0.0;
+        for (int i = 0; i < a.length; i++) {
+            sum += a[i] * b[i];
+        }
+        if (Double.isNaN(sum)) {
+            return Double.NaN; // Handle NaN case
+        }
+        return sum;
+    }
+}
diff --git a/hyracks-fullstack/pom.xml b/hyracks-fullstack/pom.xml
index 41c4505..72b80f0 100644
--- a/hyracks-fullstack/pom.xml
+++ b/hyracks-fullstack/pom.xml
@@ -690,6 +690,7 @@
           <excludeSubProjects>true</excludeSubProjects>
           <excludes combine.children="append">
             <exclude>**/*.iml</exclude>
+            <exclude>**/target/**</exclude>
           </excludes>
         </configuration>
       </plugin>

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21385?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: I45176e7da13ed222f48bb36b13f0ab4074a0bdb9
Gerrit-Change-Number: 21385
Gerrit-PatchSet: 1
Gerrit-Owner: Ian Maxon <im...@apache.org>
Gerrit-CC: Calvin Thomas Dani <ca...@gmail.com>