{"record":{"id":"ab75b6f0c926ed05","repo":"jd-opensource/joyagent-jdgenie","slug":"error-ab75b6","errorCode":null,"errorMessage":"批量保存向量数据失败","messagePattern":"批量保存向量数据失败","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/ChatModelInfoService.java","lineNumber":167,"sourceCode":"    }\n\n    private int syncVectorInfo(List<ChatModelSchema> chatModelSchemas) {\n        List<VectorSaveReq.VectorData> vectorDataList = convertToVectorData(chatModelSchemas);\n        // 分批处理\n        int batchSize = 20;\n        int total = 0;\n        for (int i = 0; i < vectorDataList.size(); i += batchSize) {\n            int endIndex = Math.min(i + batchSize, vectorDataList.size());\n            List<VectorSaveReq.VectorData> batch = vectorDataList.subList(i, endIndex);\n            try {\n                VectorSaveReq req = new VectorSaveReq();\n                req.setCollectionName(DataAgentConstants.SCHEMA_COLLECTION_NAME);\n                req.setDataList(batch);\n                vectorService.saveVector(req);\n                total += endIndex - i;\n            } catch (Exception e) {\n                log.error(\"批量保存向量数据失败{}\", e.getMessage(), e);\n                throw new RuntimeException(\"批量保存向量数据失败\");\n            }\n        }\n        return total;\n    }\n\n    private List<VectorSaveReq.VectorData> convertToVectorData(List<ChatModelSchema> schemaList) {\n        List<VectorSaveReq.VectorData> allVectors = new ArrayList<>();\n        for (ChatModelSchema schema : schemaList) {\n            String[] uuids = schema.getVectorUuid().split(\",\");\n            addVectorSaveData(allVectors, schema, schema.getColumnName(), uuids[0]);\n            addVectorSaveData(allVectors, schema, schema.getSynonyms(), uuids[1]);\n            addVectorSaveData(allVectors, schema, schema.getColumnComment(), uuids[2]);\n            if (!StandardColumnType.DECIMAL.name().equalsIgnoreCase(schema.getDataType())) {\n                //数值类型fewShot不参与向量化\n                addVectorSaveData(allVectors, schema, schema.getFewShot(), uuids[3]);\n            }\n        }\n        return allVectors;","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/ChatModelInfoService.java#L149-L185","documentation":"In syncVectorInfo, schema vectors are saved in batches via vectorService.saveVector(req); any exception in a batch is logged and rethrown as a plain RuntimeException '批量保存向量数据失败' (failed to batch-save vector data), aborting the whole synchronization and losing the error's original type/stack in the rethrown exception.","triggerScenarios":"vectorService.saveVector throwing for a batch — vector store unavailable/refusing connection, collection DataAgentConstants.SCHEMA_COLLECTION_NAME missing or dimension mismatch between embeddings and collection schema, embedding service failure producing bad vectors, or an oversized batch hitting payload limits.","commonSituations":"Vector database (e.g. Milvus/ES) is down or misconfigured in the environment; collection was recreated with a different embedding dimension; network timeouts on large batches; first-time sync where the collection hasn't been created yet.","solutions":["Check the log line 批量保存向量数据失败 for the original cause (e.getMessage() is logged with stack trace) and fix the underlying vector service issue","Verify the vector store is reachable and the SCHEMA_COLLECTION_NAME collection exists with the expected dimension","Reduce the batch size if timeouts or payload limits are involved","Rethrow preserving the cause (new RuntimeException(msg, e)) so the real failure isn't hidden"],"exampleFix":"// before\n} catch (Exception e) {\n    log.error(\"批量保存向量数据失败{}\", e.getMessage(), e);\n    throw new RuntimeException(\"批量保存向量数据失败\");\n}\n// after\n} catch (Exception e) {\n    log.error(\"批量保存向量数据失败{}\", e.getMessage(), e);\n    throw new RuntimeException(\"批量保存向量数据失败: \" + e.getMessage(), e);\n}","handlingStrategy":"retry","validationCode":"// pre-check before syncVectorInfo\nif (!vectorService.collectionExists(DataAgentConstants.SCHEMA_COLLECTION_NAME)) {\n    vectorService.createCollection(DataAgentConstants.SCHEMA_COLLECTION_NAME, expectedDimension);\n}\nif (batch == null || batch.isEmpty()) {\n    throw new IllegalStateException(\"No vector data to save\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    long total = chatModelInfoService.syncVectorInfo(...);\n} catch (RuntimeException e) {\n    if (\"批量保存向量数据失败\".equals(e.getMessage())) {\n        log.error(\"Vector sync failed; check vector store availability and collection dimension\", e);\n        // retry with smaller batch or back off\n    }\n}","preventionTips":["Ensure the vector collection exists with the correct embedding dimension before syncing","Check vector store connectivity/health before starting a sync","Use smaller batches and add retry with backoff on saveVector failures","Always preserve the original cause when rethrowing (new RuntimeException(msg, e))"],"tags":["vector-database","batch-write","exception-wrapping"],"backgroundTag":"database-write-failed","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}