@@ -297,7 +297,15 @@ def _build_where_clause(self, where_sql: Optional[str]) -> str:
297297 return f"WHERE { where_sql } "
298298
299299 # ---------- querying ----------
300- def query (self , vector : np .ndarray , k : int = 10 , ef : Optional [int ] = None , assume_normalized : Optional [bool ] = None ):
300+ def query (
301+ self ,
302+ vector : np .ndarray ,
303+ k : int = 10 ,
304+ ef : Optional [int ] = None ,
305+ assume_normalized : Optional [bool ] = None
306+ ) -> List [Tuple [str , float ]]:
307+ """Query the index with a single vector.
308+ """
301309 if self ._index is None :
302310 raise RuntimeError ("Index not built or loaded." )
303311 v = np .asarray (vector , dtype = np .float32 ).reshape (1 , - 1 )
@@ -322,6 +330,8 @@ def query(self, vector: np.ndarray, k: int = 10, ef: Optional[int] = None, assum
322330
323331 # ---------- persistence ----------
324332 def save_index (self , path_prefix : str ) -> None :
333+ """Save index to files with given prefix.
334+ """
325335 if self ._index is None or self ._ids is None :
326336 raise RuntimeError ("Index not built or loaded." )
327337 meta_path = f"{ path_prefix } .meta.json"
@@ -335,6 +345,8 @@ def save_index(self, path_prefix: str) -> None:
335345 json .dump (meta , f )
336346
337347 def load_index (self , path_prefix : str ) -> None :
348+ """Load index from files with given prefix.
349+ """
338350 meta_path = f"{ path_prefix } .meta.json"
339351 ids_path = f"{ path_prefix } .ids.npy"
340352 hnsw_path = str (path_prefix ) #f"{path_prefix}.nmslib"
0 commit comments