22
33from collections import defaultdict
44from math import ceil
5- from typing import Generic , Literal , Sequence
5+ from typing import Any , Generic , Literal , Sequence
66
77import numpy as np
88from frozendict import frozendict
@@ -102,6 +102,8 @@ def from_records(
102102 columns : Sequence [str ] | None = None ,
103103 use_ann : bool = True ,
104104 model : Encoder | None = None ,
105+ ann_backend : Backend | str = Backend .USEARCH ,
106+ ** kwargs : Any ,
105107 ) -> SemHash :
106108 """
107109 Initialize a SemHash instance from records.
@@ -112,6 +114,8 @@ def from_records(
112114 :param columns: Columns to featurize if records are dictionaries.
113115 :param use_ann: Whether to use approximate nearest neighbors (True) or basic search (False). Default is True.
114116 :param model: (Optional) An Encoder model. If None, the default model is used (minishlab/potion-base-8M).
117+ :param ann_backend: (Optional) The ANN backend to use if use_ann is True. Defaults to Backend.USEARCH.
118+ :param **kwargs: Any additional keyword arguments to pass to the Vicinity index.
115119 :return: A SemHash instance with a fitted vicinity index.
116120 :raises ValueError: If columns are not provided for dictionary records.
117121 """
@@ -151,11 +155,12 @@ def from_records(
151155 embeddings = cls ._featurize (deduplicated_records , columns , model )
152156
153157 # Build the Vicinity index
154- backend = Backend . USEARCH if use_ann else Backend .BASIC
158+ backend = ann_backend if use_ann else Backend .BASIC
155159 index = Index .from_vectors_and_items (
156160 vectors = embeddings ,
157161 items = items ,
158162 backend_type = backend ,
163+ ** kwargs ,
159164 )
160165
161166 return cls (index = index , columns = columns , model = model , was_string = was_string )
0 commit comments