Skip to content

Commit eaabbfa

Browse files
Refactor token insertion in Vicinity class to simplify duplicate handling
- Replaced the nested loop for checking duplicates with a single extend operation for tokens. - Improved efficiency by directly appending tokens to the items list, ensuring proper management of duplicates.
1 parent 022c7b1 commit eaabbfa

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

vicinity/vicinity.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ def insert(self, tokens: Sequence[Any], vectors: npt.NDArray) -> None:
241241
if vectors.shape[1] != self.dim:
242242
raise ValueError("The inserted vectors must have the same dimension as the backend.")
243243

244-
for token in tokens:
245-
for item in self.items:
246-
if item == token:
247-
raise ValueError(f"Token {token} is already in the vector space.")
248-
self.items.append(token)
244+
self.items.extend(tokens)
249245
self.backend.insert(vectors)
250246
if self.vector_store is not None:
251247
self.vector_store.insert(vectors)

0 commit comments

Comments
 (0)