简单有效的去重
简单有效的去重
def dedupe(chunks, threshold=0.9):
kept = []
for c in chunks:
if any(jaccard(c.text, k.text) > threshold for k in kept):
continue
kept.append(c)
return kept增量索引未做版本替换时,同文档多版本片段同时命中;去重前先治理索引。
进上下文前做两件事:跨片段去重(同一内容多分块命中)与冗余修剪(保留与问题最相关的句/段);修剪后的片段要保留来源锚点,引用才能回溯。
def dedupe(chunks, threshold=0.9):
kept = []
for c in chunks:
if any(jaccard(c.text, k.text) > threshold for k in kept):
continue
kept.append(c)
return kept