PrepDataMatches = {
function prepareData(matches) {
if (!Array.isArray(matches) || matches.length === 0) {
throw new Error("Input 'matches' must be a non-empty array.");
}
const textEmbeddings = matches.map(match => match.report_embedding);
const imageEmbeddings = matches.map(match => match.embeddingMatch.embedding);
const embeddingLength = textEmbeddings[0]?.length;
if (!embeddingLength || !textEmbeddings.every(e => Array.isArray(e) && e.length === embeddingLength) ||
!imageEmbeddings.every(e => Array.isArray(e) && e.length === embeddingLength)) {
throw new Error("Embeddings are invalid or of inconsistent lengths.");
}
return { textEmbeddings, imageEmbeddings };
}
}