Skip to content

Conversation

@luis-gasparschroeder
Copy link
Collaborator

@luis-gasparschroeder luis-gasparschroeder commented Jun 10, 2025

The LLMSimilarityEvaluator requires async execution to ensure performant e2e latency.

To achieve that, I multi-threaded the exploration logic. To ensure thread safety, the metadata objects and Vector DB ID generation maintain RW locks.

@luis-gasparschroeder luis-gasparschroeder self-assigned this Jun 10, 2025
@luis-gasparschroeder luis-gasparschroeder linked an issue Jun 10, 2025 that may be closed by this pull request
5 tasks
Copy link
Collaborator

@AlexCuadron AlexCuadron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite nice PR! The biggest issue I found is the widespread use of RLock, even when sometimes its not needed and following the google style docstring.

@luis-gasparschroeder
Copy link
Collaborator Author

Thank you for the comments @AlexCuadron. I fixed them.

@AlexCuadron AlexCuadron self-requested a review June 12, 2025 10:10
Copy link
Collaborator

@AlexCuadron AlexCuadron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

Copy link
Collaborator

@AlexCuadron AlexCuadron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite nice PR, some threading potential errors, better to fix them now than later

self._init_vector_store(len(embedding))
if self.collection.count() == 0:
return []
k_ = min(k, self.collection.count())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.index.ntotal could change between the check and usage if another thread adds/removes embeddings.

self._init_vector_store(len(embedding))

# Atomic ID generation and assignment
embedding_id = self.__next_embedding_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If add_with_ids() fails, __next_embedding_id is not incremented, but the ID was already assigned and returned, causing ID reuse.

embedding_id (int): The ID of the embedding to update.
observation (Tuple[float, int]): The observation tuple (similarity, label).
"""
entry_lock = self._get_entry_lock(embedding_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lock ordering violation. If another thread holds _store_lock and tries to get entry_lock, deadlock occurs. with entry lock should already fix this I think (?)

@luis-gasparschroeder
Copy link
Collaborator Author

This async logic is too complicated. We have a better logic proposal in #65. I close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants