diff --git a/server/utils/vectorDbProviders/milvus/index.js b/server/utils/vectorDbProviders/milvus/index.js index 3dac303feb49ba439b26fa0c9cc76d99ef6d63a1..a304e8714e56eb65295f37a138b28e0b075e1e14 100644 --- a/server/utils/vectorDbProviders/milvus/index.js +++ b/server/utils/vectorDbProviders/milvus/index.js @@ -18,8 +18,12 @@ const Milvus = { // Milvus/Zilliz only allows letters, numbers, and underscores in collection names // so we need to enforce that by re-normalizing the names when communicating with // the DB. + // If the first char of the collection is not an underscore or letter the collection name will be invalid. normalize: function (inputString) { - return inputString.replace(/[^a-zA-Z0-9_]/g, "_"); + let normalized = inputString.replace(/[^a-zA-Z0-9_]/g, "_"); + if (new RegExp(/^[a-zA-Z_]/).test(normalized.slice(0, 1))) + normalized = `anythingllm_${normalized}`; + return normalized; }, connect: async function () { if (process.env.VECTOR_DB !== "milvus") diff --git a/server/utils/vectorDbProviders/zilliz/index.js b/server/utils/vectorDbProviders/zilliz/index.js index 9b1d5a221ea676e4f080223494c6b5ed07bfe052..be0e9e7d40d5d5174e1713c19bc1ee0564cb9369 100644 --- a/server/utils/vectorDbProviders/zilliz/index.js +++ b/server/utils/vectorDbProviders/zilliz/index.js @@ -20,8 +20,12 @@ const Zilliz = { // Milvus/Zilliz only allows letters, numbers, and underscores in collection names // so we need to enforce that by re-normalizing the names when communicating with // the DB. + // If the first char of the collection is not an underscore or letter the collection name will be invalid. normalize: function (inputString) { - return inputString.replace(/[^a-zA-Z0-9_]/g, "_"); + let normalized = inputString.replace(/[^a-zA-Z0-9_]/g, "_"); + if (new RegExp(/^[a-zA-Z_]/).test(normalized.slice(0, 1))) + normalized = `anythingllm_${normalized}`; + return normalized; }, connect: async function () { if (process.env.VECTOR_DB !== "zilliz")