Skip to main content

Similarity

Calculate the cosine similarity of two vectors.

Calculate the similarity of two vectors.

info

Similarity only works on vectors. To produce vectors from a column of strings, use create.embeddings first.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
inputTwo columns of vectors to compare the similarity of.array—Yes
outputName of the output column.string—Yes
Options
methodThe type of similarity to calculate (cosine or euclidean). Adjusted cosine adjusts the default cosine calculation to cover a range of 0-1 for typical comparisons.string; one of:
  • cosine
  • adjusted cosine
  • euclidean
"cosine"No
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No

Examples​

wrangles:
- create.embeddings:
input: col1
api_key: ${my_key}
output: col1 embeddings

- create.embeddings:
input: col2
api_key: ${my_key}
output: col2 embeddings

- similarity:
input:
- col1 embeddings
- col2 embeddings
output: similarity
method: adjusted cosine
col1col2
SKFTimken
Ball BearingRoller Bearing
col1 embeddingscol2 embeddingssimilarity
[1, 2, 3, 4][4, 3, 2, 1]0.158931
[5, 6, 7, 8][5, 6, 7, 9]0.942437
Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID92
Catalog keysimilarity
Recipe keysimilarity
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
NamespaceRoot-level
Documentation groupcompare
AliasesNone
Runtime symbolwrangles.recipe_wrangles.main.similarity
Legacy UUID7c733344-4cce-4938-8013-53742fb46a90

Sources