async function configureVectorIndex(db) {
  const collection = db.collection(RAG_CHUNKS);
  const sampleDoc = await collection.findOne({ embedding: { $exists: true } });
  if (sampleDoc?.embedding?.length) {
    const indexDefinition = {
      mappings: {
        dynamic: true,
        fields: {
          embedding: { dimensions: sampleDoc.embedding.length, similarity: 'cosine', type: 'knnVector' },
        },
      },
    };
    await setVectorIndex(db.collection(RAG_CHUNKS), indexDefinition);
    await setVectorIndex(db.collection(LLM_SEMANTIC_CACHE), indexDefinition);
    vectorIndexConfigured = true;
  } else {
    console.error('No embeddings found yet; cannot update vector index.');
  }
}
Configure or update the vector index dimensions based on our embedding results
Do this only once. If you change your embedding model to a different one,
you should switch to a new collection, since you need to use the same model that
was used to generate the embeddings when performing queries (similarity search, etc.)