Skip to content

Commit 999f8a2

Browse files
committed
modified search all to register insert_one
1 parent d322538 commit 999f8a2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

engine/base_client/search.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def search_one(
4444

4545
@classmethod
4646
def insert_one(
47-
cls, vector: List[float], meta_conditions, top: Optional[int]
47+
cls, vector: List[float], meta_conditions
4848
) -> List[Tuple[int, float]]:
4949
raise NotImplementedError()
5050

@@ -67,11 +67,20 @@ def _search_one(cls, query, top: Optional[int] = None):
6767
precision = len(ids.intersection(query.expected_result[:top])) / top
6868
return precision, end - start
6969

70+
@classmethod
71+
def _insert_one(cls, query):
72+
start = time.perf_counter()
73+
cls.insert_one(query.vector, query.meta_conditions)
74+
end = time.perf_counter()
75+
# No precision metric for inserts, so precision=1.0
76+
return 1.0, end - start
77+
7078
def search_all(
7179
self,
7280
distance,
7381
queries: Iterable[Query],
7482
num_queries: int = -1,
83+
insert_fraction: float = 0.0,
7584
):
7685
parallel = self.search_params.get("parallel", 1)
7786
top = self.search_params.get("top", None)
@@ -87,6 +96,7 @@ def search_all(
8796
self.setup_search()
8897

8998
search_one = functools.partial(self.__class__._search_one, top=top)
99+
insert_one = functools.partial(self.__class__._insert_one)
90100

91101
# Convert queries to a list for potential reuse
92102
# Also, converts query vectors to bytes beforehand, preparing them for sending to client without affecting search time measurements
@@ -172,7 +182,8 @@ def cycling_query_generator(queries, total_count):
172182
# Create worker processes
173183
processes = []
174184
for chunk in query_chunks:
175-
process = Process(target=worker_function, args=(self, distance, search_one, chunk, result_queue))
185+
process = Process(target=worker_function, args=(self, distance, search_one, insert_one,
186+
chunk, result_queue, insert_fraction))
176187
processes.append(process)
177188

178189
# Start worker processes

0 commit comments

Comments
 (0)