[hnswlib] Add ArrayLike annotations and raise Numpy dependency (#13538)

This commit is contained in:
Lennart Behme
2025-02-26 09:00:23 +01:00
committed by GitHub
parent 2ca92a4140
commit 2d4d7be276
2 changed files with 9 additions and 7 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
version = "0.8.*"
# Requires a version of numpy with a `py.typed` file
requires = ["numpy>=1.20"]
requires = ["numpy>=1.21"]
upstream_repository = "https://github.com/nmslib/hnswlib"
+8 -6
View File
@@ -3,7 +3,7 @@ from collections.abc import Callable
from typing import Any, Literal, overload
import numpy as np
from numpy.typing import NDArray
from numpy.typing import ArrayLike, NDArray
BFIndex: Incomplete
@@ -17,16 +17,18 @@ class Index:
def __init__(self, index: Index) -> None: ...
@overload
def __init__(self, space: Literal["l2", "ip", "cosine"], dim: int) -> None: ...
def add_items(self, data, ids: Incomplete | None = None, num_threads: int = -1, replace_deleted: bool = False) -> None: ...
def add_items(
self, data: ArrayLike, ids: ArrayLike | None = None, num_threads: int = -1, replace_deleted: bool = False
) -> None: ...
def get_current_count(self) -> int: ...
def get_ids_list(self) -> list[int]: ...
@overload
def get_items(self, ids: Incomplete | None = ..., return_type: Literal["list"] = ...) -> list[float]: ...
def get_items(self, ids: ArrayLike | None = ..., return_type: Literal["list"] = ...) -> list[float]: ...
@overload
def get_items(self, ids: Incomplete | None = ..., return_type: Literal["numpy"] = ...) -> NDArray[np.float32]: ...
def get_items(self, ids: ArrayLike | None = ..., return_type: Literal["numpy"] = ...) -> NDArray[np.float32]: ...
@overload
def get_items(
self, ids: Incomplete | None = None, return_type: Literal["numpy", "list"] = "numpy"
self, ids: ArrayLike | None = None, return_type: Literal["numpy", "list"] = "numpy"
) -> NDArray[np.float32] | list[float]: ...
def get_max_elements(self) -> int: ...
def index_file_size(self) -> int: ...
@@ -39,7 +41,7 @@ class Index:
allow_replace_delete: bool = False,
) -> None: ...
def knn_query(
self, data, k: int = 1, num_threads: int = -1, filter: Callable[[int], bool] | None = None
self, data: ArrayLike, k: int = 1, num_threads: int = -1, filter: Callable[[int], bool] | None = None
) -> tuple[NDArray[np.uint64], NDArray[np.float32]]: ...
def load_index(self, path_to_index: str, max_elements: int = 0, allow_replace_delete: bool = False) -> None: ...
def mark_deleted(self, label: int) -> None: ...