Skip to content
Merged
Show file tree
Hide file tree
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 tests/test_conflicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def test_chunks_from_one_document_are_not_a_conflict_with_themselves():
assert detect_conflicts([_hit("hr-policy"), _hit("hr-policy")]) == []


def test_duplicate_chunks_from_two_documents_report_one_conflict_pair():
hits = [_hit("hr-policy"), _hit("hr-policy"), _hit("finance-policy"), _hit("finance-policy")]
conflicts = detect_conflicts(hits)
assert len(conflicts) == 1
assert {conflicts[0].doc_a, conflicts[0].doc_b} == {"hr-policy", "finance-policy"}


def test_a_single_source_of_truth_produces_no_conflict():
assert detect_conflicts([_hit("hr-policy")]) == []

Expand Down
9 changes: 9 additions & 0 deletions vaultrag/conflicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ def detect_conflicts(hits: list[Hit]) -> list[Conflict]:
both answering the same question. That is worth a flag even when they happen to agree.
"""
out: list[Conflict] = []
seen_pairs: set[frozenset[str]] = set()
official = [h for h in hits if h.is_official]

for i, a in enumerate(official):
for b in official[i + 1 :]:
if a.doc_id == b.doc_id:
continue
pair = frozenset((a.doc_id, b.doc_id))
if pair in seen_pairs:
continue
seen_pairs.add(pair)
out.append(
Conflict(
doc_a=a.doc_id,
Expand All @@ -70,6 +75,10 @@ def detect_conflicts(hits: list[Hit]) -> list[Conflict]:
for a in official:
for b in unofficial:
if a.doc_id != b.doc_id:
pair = frozenset((a.doc_id, b.doc_id))
if pair in seen_pairs:
continue
seen_pairs.add(pair)
out.append(
Conflict(
doc_a=a.doc_id,
Expand Down
Loading