dcapwell commented on PR #2310:
URL: https://github.com/apache/cassandra/pull/2310#issuecomment-1563297122

   > Where will this leave the ability to expose a `similarity_cosine(a, b)` 
function to CQL? I believe there are some difficulties around type inference.
   
   @jbellis can you expand on that?  What I see in 
`org.apache.cassandra.cql3.functions.NativeFunctions#add(org.apache.cassandra.cql3.functions.FunctionFactory)`
 that we can use a `Factory`, so we can see the arguments given to us.
   
   ```
   private static boolean isFloatVector(AbstractType<?> type)
       {
           type = type.unwrap();
           return type instanceof VectorType && ((VectorType<?>) 
type).getElementsType() == FloatType.instance;
       }
   
   ...
   functions.add(new FunctionFactory("similarity_cosine", 
FunctionParameter.anyMap())
           {
               @Nullable
               @Override
               protected NativeFunction 
doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> 
receiverType)
               {
                   if (!(isFloatVector(receiverType) && 
argTypes.stream().allMatch(CollectionFcts::isFloatVector)))
                       return null;
                   if (!argTypes.stream().allMatch(t -> t.equals(receiverType)))
                       return null;
                   VectorType<Float> type = (VectorType<Float>) receiverType;
                   return makeSimilarityCosine(type);
               }
           });
   ...
   ```
   
   so this should match if-and-only-if args and receiver are float vectors of 
the same size


-- 
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