jd-opensource/joyagent-jdgenie · error · RuntimeException

向量集合大小与元数据集合大小不一致,vectorSize:

Error message

向量集合大小与元数据集合大小不一致,vectorSize:

What it means

upsertVectors requires vectors.size() == payloads.size() so each point gets exactly one payload; a size mismatch means index pairing would corrupt data, so it throws RuntimeException with both sizes ("向量集合大小与元数据集合大小不一致,vectorSize:...payloadSize:...").

Solutions

  1. Ensure vectors and payloads are built in the same loop so they stay index-aligned
  2. Filter both lists together (e.g. as pairs) rather than independently
  3. Log both sizes and diff the sources when they diverge

Example fix

// before
vectors = vectors.stream().filter(v -> v.size() == dim).collect(toList());
payloads = buildPayloads(allRecords); // built from original list
qdrantService.upsertVectors(collection, vectors, payloads);
// after
List<VectorWithPayload> pairs = items.stream()
    .filter(i -> i.vector.size() == dim)
    .collect(toList());
qdrantService.upsertVectors(collection,
    pairs.stream().map(p -> p.vector).collect(toList()),
    pairs.stream().map(p -> p.payload).collect(toList()));
Defensive patterns

Strategy: validation

Validate before calling

if (vectors.size() != payloads.size()) {
    throw new IllegalStateException("vector/payload size mismatch: " + vectors.size() + " vs " + payloads.size());
}

Try / catch

try {
    qdrantService.upsertVectors(collectionName, vectors, payloads);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains("向量集合大小与元数据集合大小不一致")) {
        log.error("batch misaligned: {}", e.getMessage());
    } else throw e;
}

Prevention

When it happens

Trigger: Calling upsertVectors where vectors and payloads lists have different lengths — typically one list was filtered/deduplicated independently, or a partial failure caused one list to lose items.

Common situations: Filtering vectors (e.g. dropping bad embeddings) without filtering payloads in step; duplicate handling removing items from only one list; off-by-one or async ordering bugs in batch assembly.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08). Data as JSON: /api/errors/09ea965c4575ec2e. Report an issue: GitHub.

Appendix: source

Thrown at genie-backend/src/main/java/com/jd/genie/service/QdrantService.java:147

    public void deleteByFilterSync(String collectionName, Points.Filter filter) throws ExecutionException, InterruptedException {
        client.deleteAsync(collectionName, filter).get();
    }

    public Points.UpdateResult upsertVectors(String collectionName, List<List<Float>> vectors, List<Map<String, JsonWithInt.Value>> payloads) throws ExecutionException, InterruptedException {
        if (StringUtils.isBlank(collectionName)) {
            throw new RuntimeException("集合名为空!");
        }

        if (CollectionUtils.isEmpty(vectors)) {
            throw new RuntimeException("向量集合为空!");
        }

        if (CollectionUtils.isEmpty(payloads)) {
            throw new RuntimeException("元数据集合为空!");
        }

        if (vectors.size() != payloads.size()) {
            throw new RuntimeException("向量集合大小与元数据集合大小不一致,vectorSize:" + vectors.size() + ",payloadSize:" + payloads.size());
        }

        List<Points.PointStruct> pointStructList = new ArrayList<>();
        for (int i = 0; i < vectors.size(); i++) {
            Points.PointStruct pointStruct = Points.PointStruct.newBuilder()
                    .setId(id(UUID.randomUUID()))
                    .setVectors(vectors(vectors.get(i)))
                    .putAllPayload(payloads.get(i))
                    .build();
            pointStructList.add(pointStruct);
        }

        return client.upsertAsync(collectionName, pointStructList).get();
    }

    public Points.UpdateResult upsertVectors(String collectionName, List<String> idList, List<List<Float>> vectors, List<Map<String, JsonWithInt.Value>> payloads) throws ExecutionException, InterruptedException {
        if (StringUtils.isBlank(collectionName)) {
            throw new RuntimeException("集合名为空!");

View on GitHub (pinned to 2417e0b8b6)