From a2274cb88b7b76fd619966d6427702f19a9fe961 Mon Sep 17 00:00:00 2001 From: Dt8333 Date: Fri, 14 Nov 2025 17:59:08 +0800 Subject: [PATCH] =?UTF-8?q?chore(core.db):=20=E6=B7=BB=E5=8A=A0typings?= =?UTF-8?q?=EF=BC=8C=E4=BD=BFfaiss=E5=8F=82=E6=95=B0=E8=83=BD=E8=A2=AB?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=AF=86=E5=88=AB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typings/faiss/__init__.pyi | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 typings/faiss/__init__.pyi diff --git a/typings/faiss/__init__.pyi b/typings/faiss/__init__.pyi new file mode 100644 index 000000000..fc316dfea --- /dev/null +++ b/typings/faiss/__init__.pyi @@ -0,0 +1,49 @@ +"""Minimal type stubs for faiss used in this project. + +This file only exposes a small subset of the faiss API that the +project uses, including the runtime-monkeypatched signatures such as +`Index.add_with_ids` so Pyright/Pylance stops reporting false positives. +""" + +from typing import Any + +import numpy as np + +class Index: + d: int + ntotal: int + code_size: int + nprobe: int + + def add(self, x: np.ndarray) -> None: ... + def add_with_ids(self, x: np.ndarray, ids: np.ndarray) -> None: ... + def search( + self, + x: np.ndarray, + k: int, + *, + params: Any = ..., + D: np.ndarray | None = ..., + I: np.ndarray | None = ..., + ) -> tuple[np.ndarray, np.ndarray]: ... + def remove_ids(self, x: np.ndarray) -> int: ... + def reconstruct(self, key: int, x: np.ndarray | None = ...) -> np.ndarray: ... + def reconstruct_n( + self, n0: int = ..., ni: int = ..., x: np.ndarray | None = ... + ) -> np.ndarray: ... + def range_search( + self, x: np.ndarray, thresh: float, *, params: Any = ... + ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ... + def add_sa_codes(self, codes: np.ndarray, ids: np.ndarray | None = ...) -> None: ... + def sa_encode(self, x: np.ndarray) -> np.ndarray: ... + def sa_decode(self, codes: np.ndarray) -> np.ndarray: ... + +class IndexFlatL2(Index): + def __init__(self, d: int) -> None: ... + +class IndexIDMap(Index): + def __init__(self, index: Index) -> None: ... + +def read_index(path: str) -> Index: ... +def write_index(index: Index, path: str | None = ...) -> None: ... +def normalize_L2(x: np.ndarray) -> None: ...