cosine_similarity
def cosine_similarity(left: ExprLike, right: ExprLike) -> ExprCompute the cosine similarity of left and right.
See the Wikipedia article “Cosine similarity” .
Only implemented for fixed size lists of the 16-, 32-, and 64-bit floating-point types.
Examples
{/pytest-codeblocks:skip/}
>>> import spiral.expressions as se
>>> import pyarrow as pa
>>> needle = pa.scalar([1, 0, 0], type=pa.list_(pa.float64(), 3))
>>> sp.scan({"result": se.vector.cosine_similarity(t["embedding"], needle)}).to_table()
pyarrow.Table
x: int64
result: double
----
x: ...
result: ...Arguments:
left- an array of fixed-size-list of length N and type Tright- an array of fixed-size-list of length N and type T
Returns:
an array of T
dot
def dot(left: ExprLike, right: ExprLike) -> ExprCompute the dot product of left and right.
Only implemented for fixed size lists of the 16-, 32-, and 64-bit floating-point types.
Examples
{/pytest-codeblocks:skip/}
>>> import spiral.expressions as se
>>> sp.scan({"5_34_sim": se.vector.dot(t["layer5"], t["layer34"])}).to_table()
pyarrow.Table
x: int64
5_34_sim: double
----
x: ...
4_34_sim: ...Arguments:
left- an array of fixed-size-list of length N and type Tright- an array of fixed-size-list of length N and type T
Returns:
an array of T
norm
def norm(array: ExprLike) -> ExprCompute the Euclidean (L2) norm of array.
Only implemented for fixed size lists of the 16-, 32-, and 64-bit floating-point types.
Examples
{/pytest-codeblocks:skip/}
>>> import spiral.expressions as se
>>> sp.scan({"norm": se.vector.norm(t["embedding"])}).to_table()
pyarrow.Table
x: int64
norm: double
----
x: ...
norm: ...Arguments:
array- an array of fixed-size-list of type T
Returns:
an array of T
Last updated on