Tencent/WeKnora · error

failed to create collection

Error message

failed to create collection: %w

What it means

Milvus collection bootstrap failed at collection creation: the per-dimension collection (with HNSW/BM25/payload indexes) could not be created, so subsequent inserts have nowhere to land and ensureCollection aborts the write path.

Solutions

  1. Inspect the wrapped Milvus error (quota, permissions, name conflict)
  2. Verify collection schema/index limits for the configured dimension
  3. Retry after resolving the cluster-side issue
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/application/repository/retriever/milvus/repository.go:186 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/2fbc3b7a36490b7e. Report an issue: GitHub.

Appendix: source

Thrown at internal/application/repository/retriever/milvus/repository.go:186

		indexOpts := make([]client.CreateIndexOption, 0)
		// hnsw index for embedding field
		indexOpts = append(indexOpts, client.NewCreateIndexOption(collectionName, fieldEmbedding, index.NewHNSWIndex(m.metricType, 16, 128)))
		indexOpts = append(indexOpts, client.NewCreateIndexOption(collectionName, fieldContentSparse, index.NewAutoIndex(entity.BM25)))
		// Create payload indexes for filtering
		indexFields := []string{fieldChunkID, fieldKnowledgeID, fieldKnowledgeBaseID, fieldSourceID, fieldIsEnabled}
		for _, fieldName := range indexFields {
			indexOpts = append(indexOpts, client.NewCreateIndexOption(collectionName, fieldName, index.NewAutoIndex(entity.IP)))
		}

		// Create collection
		createOpt := client.NewCreateCollectionOption(collectionName, schema).WithIndexOptions(indexOpts...)
		if m.shardsNum > 0 {
			createOpt = createOpt.WithShardNum(int32(m.shardsNum))
		}
		err = m.client.CreateCollection(ctx, createOpt)
		if err != nil {
			log.Errorf("[Milvus] Failed to create collection: %v", err)
			return fmt.Errorf("failed to create collection: %w", err)
		}

		log.Infof("[Milvus] Successfully created collection %s", collectionName)
	}

	loadOpt := client.NewLoadCollectionOption(collectionName)
	if m.replicaNumber > 0 {
		loadOpt = loadOpt.WithReplica(m.replicaNumber)
	}
	loadTask, err := m.client.LoadCollection(ctx, loadOpt)
	if err != nil {
		log.Errorf("[Milvus] Failed to load collection: %v", err)
		return fmt.Errorf("failed to load collection: %w", err)
	}
	if err := loadTask.Await(ctx); err != nil {
		log.Errorf("[Milvus] Failed to await load collection: %v", err)
		return fmt.Errorf("failed to await load collection: %w", err)
	}

View on GitHub (pinned to 988cbb0330)