Algorithms
AI & Machine Learning
SQL & Data
Projects
Drill 5 of 26AI & ML
You asked the AIBuild a RAG payload with source IDs kept separate from uploaded text. Return JSON; document text must never create extra source records.
export function buildPrompt(question, documents) {
const sources = [];
for (const doc of documents) {
const sourceId = doc.id;
if (typeof sourceId !== 'string' || sourceId === '') {
throw new TypeError('source ids must be non-empty strings');
}
sources.push(...JSON.parse(doc.text));
const payload = { question, sources };
return JSON.stringify(payload);