-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Reuse of Custom Raw Expressions #370
Comments
If you want to reuse your custom function or operators, they'll have to accept func WordSimilarity(word1, word2 StringExpression) FloatExpression {
return FloatExp(Func("word_similarity", word1, word2))
} Note the use of Now you can call this function as: WordSimilarity(String("John"), Actor.LastName)
WordSimilarity(String("James"), LTRIM(Actor.FirstName, String("A")))
etc... For func CosineDistance(vector1, vector2 Expression) FloatExpression {
return FloatExp(CustomExpression(vector1, Token("<=>"), vector2))
} Since func PgVector(array ...string) Expression {
return Raw("#1", RawArgs{"#1": <your pgvector type>})
} Finally, you should be able to write: CosineDistance(PgVector("john", "doe"), PgVector("mike", "jones", "jim", "nate"))
CosineDistance(PgVector("john"), Actor.PgVectorColumn)
etc... |
thanks for the suggestion @houten11! I should have clarified further in my example. I want to be able to be able to sum the two functions together without writing a new function altogether (going to use this in the select clause) e.g. CosineDistance() + WordSimilarity() my current workaround is not wrapping the raw queries into the expression types and then wrapping it after appending them together |
Both functions returns WordSimilarity(String("John"), Actor.LastName).ADD(
CosineDistance(PgVector("john", "doe"), PgVector("mike", "jones", "jim", "nate"))) |
ahhh I totally goofed on that. Just need to use the |
Is your feature request related to a problem? Please describe.
Unable to reuse functions of unsupported expressions/operations e.g. sample custom expressions below. would like to convert these expressions to string or take the expressions as input to write another custom function using these two as input
func WordSimilarity(word, tableName, columnName string) postgres.Expression {
return postgres.Raw("word_similarity('" + word + "', " + tableName + "." + columnName + ")")
}
func CosineDistance(embedding Vector, tableName, columnName string) postgres.BoolExpression {
return postgres.RawBool("'" + embedding.String() + "' <=> " + tableName + "." + columnName)
}
Describe the solution you'd like
The text was updated successfully, but these errors were encountered: