Delete tokens from the vector space. The removal of tokens is done in place. If the tokens are not in the vector space, a ValueError is raised. :param tokens: A list of tokens to remove from the vector space. :raises ValueError: If any passed tokens are not
(self, tokens: Sequence[T])
| 253 | self.vector_store.insert(vectors) |
| 254 | |
| 255 | def delete(self, tokens: Sequence[T]) -> None: |
| 256 | """ |
| 257 | Delete tokens from the vector space. |
| 258 | |
| 259 | The removal of tokens is done in place. If the tokens are not in the vector space, |
| 260 | a ValueError is raised. |
| 261 | |
| 262 | :param tokens: A list of tokens to remove from the vector space. |
| 263 | :raises ValueError: If any passed tokens are not in the vector space. |
| 264 | """ |
| 265 | tokens_to_find = list(tokens) |
| 266 | curr_indices = [] |
| 267 | for idx, elem in enumerate(self.items): |
| 268 | matching_tokens = [t for t in tokens_to_find if t == elem] |
| 269 | if matching_tokens: |
| 270 | curr_indices.append(idx) |
| 271 | for t in matching_tokens: |
| 272 | tokens_to_find.remove(t) |
| 273 | |
| 274 | if tokens_to_find: |
| 275 | raise ValueError(f"Tokens {tokens_to_find} were not in the vector space.") |
| 276 | |
| 277 | self.backend.delete(curr_indices) |
| 278 | if self.vector_store is not None: |
| 279 | self.vector_store.delete(curr_indices) |
| 280 | |
| 281 | # Delete items starting from the highest index |
| 282 | for index in sorted(curr_indices, reverse=True): |
| 283 | self.items.pop(index) |
| 284 | |
| 285 | def push_to_hub( |
| 286 | self, |
no outgoing calls