Small chunks embed precisely, but they're too short to answer from. Parent document retrieval searches over small chunks, then returns the larger parent sections they came from.
Each chunk is (chunk_id, parent_id, vector). Implement retrieve_parents(query, chunks, k_chunks, k_parents, agg="max"):
k_chunks.agg: "max" (best chunk score) or "sum" (total of its retrieved chunks' scores, which rewards parents matched by several chunks).k_parents parent ids, best first, breaking ties by which parent appeared first in the chunk ranking.Also implement dedupe_parents(chunk_ranking, parent_of), the simpler version that keeps the parents of a ranked list of chunk ids in first-appearance order, without duplicates.