Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MilvusContainer ¶
type MilvusContainer struct {
testcontainers.Container
}
MilvusContainer represents the Milvus container type used in the module
Example (Collections) ¶
// createCollections { ctx := context.Background() milvusContainer, err := milvus.RunContainer(ctx, testcontainers.WithImage("milvusdb/milvus:v2.3.9")) if err != nil { log.Fatalf("failed to start container: %s", err) } // Clean up the container defer func() { if err := milvusContainer.Terminate(ctx); err != nil { log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic } }() connectionStr, err := milvusContainer.ConnectionString(ctx) if err != nil { log.Fatalf("failed to get connection string: %s", err) // nolint:gocritic } // Create a client to interact with the Milvus container milvusClient, err := client.NewGrpcClient(context.Background(), connectionStr) if err != nil { log.Fatal("failed to connect to Milvus:", err.Error()) } defer milvusClient.Close() collectionName := "book" schema := &entity.Schema{ CollectionName: collectionName, Description: "Test book search", Fields: []*entity.Field{ { Name: "book_id", DataType: entity.FieldTypeInt64, PrimaryKey: true, AutoID: false, }, { Name: "word_count", DataType: entity.FieldTypeInt64, PrimaryKey: false, AutoID: false, }, { Name: "book_intro", DataType: entity.FieldTypeFloatVector, TypeParams: map[string]string{ "dim": "2", }, }, }, EnableDynamicField: true, } err = milvusClient.CreateCollection( context.Background(), // ctx schema, 2, // shardNum ) if err != nil { log.Fatalf("failed to create collection: %s", err) // nolint:gocritic } list, err := milvusClient.ListCollections(context.Background()) if err != nil { log.Fatalf("failed to list collections: %s", err) // nolint:gocritic } // } fmt.Println(len(list))
Output: 1
func RunContainer ¶
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error)
RunContainer creates an instance of the Milvus container type
Example ¶
// runMilvusContainer { ctx := context.Background() milvusContainer, err := milvus.RunContainer(ctx, testcontainers.WithImage("milvusdb/milvus:v2.3.9")) if err != nil { log.Fatalf("failed to start container: %s", err) } // Clean up the container defer func() { if err := milvusContainer.Terminate(ctx); err != nil { log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic } }() // } state, err := milvusContainer.State(ctx) if err != nil { log.Fatalf("failed to get container state: %s", err) // nolint:gocritic } fmt.Println(state.Running)
Output: true
func (*MilvusContainer) ConnectionString ¶
func (c *MilvusContainer) ConnectionString(ctx context.Context) (string, error)
ConnectionString returns the connection string for the milvus container, using the default 19530 port, and obtaining the host and exposed port from the container.
Click to show internal directories.
Click to hide internal directories.