ekaterinadimitrova2 commented on code in PR #2459:
URL: https://github.com/apache/cassandra/pull/2459#discussion_r1258846311


##########
doc/modules/cassandra/partials/vector_functions.adoc:
##########
@@ -0,0 +1,41 @@
+[cols=",",options="header",]
+|===
+|Function | Description
+
+| `similarity_cosine(vector, vector)` | Calculates the cosine similarity score 
between two float vectors of the same dimension.
+
+Examples:
+
+`similarity_cosine([0.1, 0.2], null)` -> `null`
+
+`similarity_cosine([0.1, 0.2], [0.1, 0.2])` -> `1`
+
+`similarity_cosine([0.1, 0.2], [-0.1, -0.2])` -> `0`
+
+`similarity_cosine([0.1, 0.2], [0.9, 0.8])` -> `0.964238`

Review Comment:
   is this one correct?



##########
src/java/org/apache/cassandra/cql3/CQL3Type.java:
##########
@@ -867,6 +867,12 @@ public CQL3Type prepare(String keyspace, Types udts) 
throws InvalidRequestExcept
                 CQL3Type type = element.prepare(keyspace, udts);
                 return new Vector(type.getType(), dimention);
             }
+
+            @Override
+            public String toString()
+            {
+                return "vector<" + element.toString() + ", " + dimention + '>';

Review Comment:
   ```suggestion
                   return "vector<" + element.toString() + ", " + dimension + 
'>';
   ```



##########
test/unit/org/apache/cassandra/cql3/functions/VectorFctsTest.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.cassandra.cql3.functions;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.lucene.index.VectorSimilarityFunction;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+@RunWith(Parameterized.class)
+public class VectorFctsTest extends CQLTester
+{
+    @Parameterized.Parameter
+    public String function;
+
+    @Parameterized.Parameter(1)
+    public VectorSimilarityFunction luceneFunction;
+
+    @Parameterized.Parameters(name = "{index}: function={0}")
+    public static Collection<Object[]> data()
+    {
+        return Arrays.asList(new Object[][]{
+        { "system.similarity_cosine", VectorSimilarityFunction.COSINE },
+        { "system.similarity_euclidean", VectorSimilarityFunction.EUCLIDEAN },
+        { "system.similarity_dot_product", 
VectorSimilarityFunction.DOT_PRODUCT }
+        });
+    }
+
+    @Test
+    public void testVectorSimilarityFunction()
+    {
+        createTable(KEYSPACE, "CREATE TABLE %s (pk int primary key,  value 
vector<float, 2>, " +

Review Comment:
   ```suggestion
           createTable(KEYSPACE, "CREATE TABLE %s (pk int PRIMARY KEY,  value 
vector<float, 2>, " +
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to