Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[review_comments_retriever] Avoid populating database from scratch #4659

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bugbug/tools/code_review.py
Original file line number Diff line number Diff line change
@@ -1285,8 +1285,15 @@ def clean_comment(self, comment):
return comment

def add_comments_by_hunk(self, items: Iterable[tuple[Hunk, InlineComment]]):
point_ids = self.vector_db.get_existing_ids()

def vector_points():
nonlocal point_ids

for hunk, comment in items:
if comment.id in point_ids:
continue

str_hunk = str(hunk)
vector = self.embeddings.embed_query(str_hunk)
payload = {
26 changes: 26 additions & 0 deletions bugbug/vectordb.py
Original file line number Diff line number Diff line change
@@ -46,6 +46,10 @@ def insert(self, points: Iterable[VectorPoint]):
def search(self, query: list[float]) -> Iterable[PayloadScore]:
...

@abstractmethod
def get_existing_ids(self):
...


class QdrantVectorDB(VectorDB):
def __init__(self, collection_name: str, *args, **kwargs):
@@ -83,3 +87,25 @@ def insert(self, points: Iterable[VectorPoint]):
def search(self, query: list[float]) -> Iterable[PayloadScore]:
for item in self.client.search(self.collection_name, query):
yield PayloadScore(item.score, item.id, item.payload)

def get_existing_ids(self):
point_ids = set()
offset = None

while True:
points, next_page_offset = self.client.scroll(
collection_name=self.collection_name,
limit=100,
with_payload=False,
with_vectors=False,
offset=offset,
)

point_ids.update(point.id for point in points)

if not next_page_offset:
break

offset = next_page_offset

return point_ids