Skip to content

Commit

Permalink
Improve: Start with import usearch
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Oct 10, 2024
1 parent 77d20c6 commit fb201aa
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 34 deletions.
1 change: 1 addition & 0 deletions python/scripts/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pandas as pd

import usearch
from usearch.index import Index, Key, MetricKind, ScalarKind
from usearch.numba import jit as njit
from usearch.eval import Evaluation, AddTask
Expand Down
1 change: 1 addition & 0 deletions python/scripts/bench_exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from faiss import knn, METRIC_L2, METRIC_INNER_PRODUCT
import fire

import usearch
from usearch.compiled import hardware_acceleration
from usearch.eval import random_vectors

Expand Down
1 change: 1 addition & 0 deletions python/scripts/index_faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from faiss import IndexHNSWFlat, IndexIVFPQ, read_index

import usearch
from usearch.index import BatchMatches
from usearch.index import (
DEFAULT_CONNECTIVITY,
Expand Down
34 changes: 8 additions & 26 deletions python/scripts/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
rm -rf datasets/cc_3M/*.usearch datasets/arxiv_2M/*.usearch
python python/scripts/join.py
"""

from numpy import dot
from numpy.linalg import norm
from tqdm import tqdm
from simsimd import cos_f32x4_neon, to_int

import usearch
from usearch.index import Index, MetricKind, CompiledMetric, MetricSignature
from usearch.io import load_matrix
from usearch.eval import measure_seconds
Expand Down Expand Up @@ -70,9 +72,7 @@
b.save()


print(
f"Loaded two indexes of size: {len(a):,} for {a_name} and {len(b):,} for {b_name}"
)
print(f"Loaded two indexes of size: {len(a):,} for {a_name} and {len(b):,} for {b_name}")
min_elements = min(len(a), len(b))

run_diagnostics = input("Would you like to run diagnostics? [Y/n]: ")
Expand Down Expand Up @@ -111,32 +111,16 @@
)

secs, a_self_recall = dt(lambda: a.search(a.vectors, **args).recall(a.keys))
print(
"Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(
count, a_name, a_self_recall * 100, secs
)
)
print("Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(count, a_name, a_self_recall * 100, secs))

secs, b_self_recall = dt(lambda: b.search(b.vectors, **args).recall(b.keys))
print(
"Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(
count, b_name, b_self_recall * 100, secs
)
)
print("Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(count, b_name, b_self_recall * 100, secs))

secs, ab_recall = dt(lambda: b.search(a.vectors, **args).recall(b.keys))
print(
"Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(
count, a_name, b_name, ab_recall * 100, secs
)
)
print("Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(count, a_name, b_name, ab_recall * 100, secs))

secs, ba_recall = dt(lambda: a.search(b.vectors, **args).recall(a.keys))
print(
"Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(
count, b_name, a_name, ba_recall * 100, secs
)
)
print("Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(count, b_name, a_name, ba_recall * 100, secs))


print("--------------------------------------")
Expand All @@ -150,6 +134,4 @@
recall += i == j

recall *= 100.0 / min_elements
print(
f"Took {secs:.2f}s to find {mapping_size:,} pairings with {recall:.2f}% being exact"
)
print(f"Took {secs:.2f}s to find {mapping_size:,} pairings with {recall:.2f}% being exact")
1 change: 1 addition & 0 deletions python/scripts/test_distances.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import numpy as np

import usearch
from usearch.eval import random_vectors
from usearch.index import search

Expand Down
3 changes: 1 addition & 2 deletions python/scripts/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import pytest
import numpy as np

import usearch
from usearch.eval import random_vectors, self_recall, SearchStats
from usearch.index import search

from usearch.index import (
Index,
MetricKind,
Expand Down
2 changes: 1 addition & 1 deletion python/scripts/test_jit.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
import numpy as np

import usearch
from usearch.eval import random_vectors

from usearch.index import (
Index,
MetricKind,
Expand Down
1 change: 1 addition & 0 deletions python/scripts/test_sparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import numpy as np

import usearch
from usearch.index import (
Index,
MetricKind,
Expand Down
1 change: 0 additions & 1 deletion python/scripts/test_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sqlite3
import json
import math
import sys

import numpy as np
import pytest
Expand Down
6 changes: 2 additions & 4 deletions python/scripts/test_tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import pytest
import numpy as np

import usearch
from usearch.io import load_matrix, save_matrix
from usearch.index import search
from usearch.eval import random_vectors

from usearch.index import Match, Matches, BatchMatches, Index, Indexes


Expand Down Expand Up @@ -70,9 +70,7 @@ def test_exact_search(rows: int, cols: int, k: int, reordered: bool):
reordered_keys = keys

matches: BatchMatches = search(original, original[reordered_keys], k, exact=True)
top_matches = (
[int(m.keys[0]) for m in matches] if rows > 1 else [int(matches.keys[0])]
)
top_matches = [int(m.keys[0]) for m in matches] if rows > 1 else [int(matches.keys[0])]
assert top_matches == list(reordered_keys)

matches: Matches = search(original, original[-1], k, exact=True)
Expand Down

0 comments on commit fb201aa

Please sign in to comment.