async function setupRagCollection(db) {
  // Setup the vector search collections if they don't exist.
  // We use fileHash to see if a file with the same hash has already been processed,
  // to avoid duplicate data in the vector DB.
  // We use fileName to list the files that have been ingested in the frontend.
  // llm_string and prompt combo is used to see if we have already processed the same LLM query.
  const ragCollection = await createCollectionForVectorSearch(db, RAG_CHUNKS, [{ fileHash: 1 }, { fileName: 1 }]); // for the RAG chunks from input documents
  await createCollectionForVectorSearch(db, LLM_SEMANTIC_CACHE, [{ llm_string: 1, prompt: 1 }]); // for the LLM semantic cache so we can reduce LLM calls and related costs

  // Create the document embedding cache collection if it doesn't exist
  const docCacheCollections = await db.listCollections({ name: DOC_EMBEDDINGS_CACHE }).toArray();
  if (docCacheCollections.length === 0) {
    await db.createCollection(DOC_EMBEDDINGS_CACHE);
    console.log(`Created collection ${DOC_EMBEDDINGS_CACHE} for permanent document embedding cache.`);
  }

  // Create the query embedding cache collection with TTL if it doesn't exist
  const queryCacheCollections = await db.listCollections({ name: QUERY_EMBEDDINGS_CACHE }).toArray();
  if (queryCacheCollections.length === 0) {
    await db.createCollection(QUERY_EMBEDDINGS_CACHE);
    console.log(`Created collection ${QUERY_EMBEDDINGS_CACHE} for query embedding cache with TTL.`);

    // Set a TTL index (60 days) for automatic expiration
    await db.collection(QUERY_EMBEDDINGS_CACHE).createIndex({ createdAt: 1 }, { expireAfterSeconds: 5184000 }); // 60 days
    console.log('Created TTL index on query embedding cache (expiration: 60 days).');
  }
  ragCollectionReady = true;
  console.log('Vector Search and Embedding Cache Collections have been set up.');
  return ragCollection;
}
Initialize the MongoDB collection for RAG