Skip to content
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

remove cosine_distance/euclidean_distance impl #752

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/datachain/sql/sqlite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,6 @@ def register_user_defined_sql_functions() -> None:
# Register optional functions if we have the necessary dependencies
# and otherwise register functions that will raise an exception with
# installation instructions
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from memory: we need this as a fallback because usearch is not available on Windows - unum-cloud/usearch#427

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description on that PR should shed some light on the approach

from .vector import cosine_distance, euclidean_distance
except ImportError as exc:
# We want to throw an exception when trying to compile these
# functions and also if the functions are called using raw SQL.
cosine_distance = missing_vector_function("cosine_distance", exc)
euclidean_distance = missing_vector_function("euclidean_distance", exc)
_compiler_hooks["cosine_distance"] = cosine_distance
_compiler_hooks["euclidean_distance"] = euclidean_distance

def create_vector_functions(conn):
conn.create_function("cosine_distance", 2, cosine_distance, deterministic=True)
conn.create_function(
"euclidean_distance", 2, euclidean_distance, deterministic=True
)

_registered_function_creators["vector_functions"] = create_vector_functions

def create_numeric_functions(conn):
conn.create_function("divide", 2, lambda a, b: a / b, deterministic=True)
Expand Down
23 changes: 0 additions & 23 deletions src/datachain/sql/sqlite/vector.py

This file was deleted.

4 changes: 3 additions & 1 deletion tests/unit/sql/test_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math

import pytest
from pytest import approx

from datachain import func
from datachain.sql import select
Expand All @@ -14,7 +15,8 @@ def test_cosine_distance(warehouse):
func.cosine_distance([0.0, 10.0], [1.0, 0.0]).label("cos4"),
)
result = tuple(warehouse.db.execute(query))
assert result == ((0.0, 0.0, 1.0, 1.0),)
# using approx due to https://github.com/unum-cloud/usearch/issues/320
assert result == ((approx(0.0, abs=1e-6), approx(0.0, abs=1e-6), 1.0, 1.0),)


def test_euclidean_distance(warehouse):
Expand Down
Loading