Look up the index and return IDs of related documents by keyword overlap.
(doc: dict)
| 42 | |
| 43 | |
| 44 | def find_cross_references(doc: dict) -> list: |
| 45 | """Look up the index and return IDs of related documents by keyword overlap.""" |
| 46 | index = load_index() |
| 47 | keywords = set(doc.get("keywords", [])) |
| 48 | refs = [] |
| 49 | for record_id, entry in index.items(): |
| 50 | other_keywords = set(entry.get("keywords", [])) |
| 51 | overlap = keywords & other_keywords |
| 52 | if len(overlap) >= 3: |
| 53 | refs.append({"id": record_id, "shared_keywords": list(overlap)}) |
| 54 | return refs |
| 55 | |
| 56 | |
| 57 | def process_and_save(doc: dict) -> str: |
no test coverage detected