InsertAsync()

Inserts rows into a collection.

public Task<MutationResp> InsertAsync(InsertReq request, CancellationToken cancellationToken = default)

Request Syntax

var request = new InsertReq
{
    CollectionName = "my_collection",
    ColumnsData =
    [
        FieldData.Create("id", new long[] { 1, 2 }),
        FieldData.CreateVarChar("title", new[] { "A", "B" }),
        FieldData.Create("embedding", new[]
        {
            new[] { 0.1f, 0.2f },
            new[] { 0.3f, 0.4f }
        })
    ]
};

MutationResp result = await client.InsertAsync(request);

REQUEST PARAMETERS:

  • DatabaseName (string?) -

    An optional database name to operate on. When empty, the client’s currently selected database is used.

  • CollectionName (string) -

    The name of the collection to insert into.

  • ColumnsData (IReadOnlyList) -

    The column-based data to insert; each field contains one value per row. Mutually exclusive with RowsData. See FieldData.

  • RowsData (IReadOnlyList>) -

    Optional row-based data to insert: one dictionary per row mapping field names to values. Mutually exclusive with ColumnsData. Values are encoded according to the collection schema.

  • PartitionName (string?) -

    An optional partition to insert into.

  • RlsPrincipal (string?) -

    The row-level security (RLS) principal for the operation. When set, Milvus applies the row policies of the collection to this operation.

  • SkipRls (bool?) -

    Whether the operation should skip row-level security (RLS) enforcement. When null, the server default applies.

RETURN TYPE:

Task

RETURNS:

A MutationResp object that contains the result of the insert operation. If RowsData and ColumnsData are both empty, an empty result is returned without issuing the RPC.

MutationResp
    LongIds      // -> IReadOnlyList<long>?
    StringIds    // -> IReadOnlyList<string>?
    InsertCount  // -> long
    DeleteCount  // -> long
    UpsertCount  // -> long
    Timestamp    // -> ulong
    SuccessIndex // -> IReadOnlyList<long>?
    ErrorIndex   // -> IReadOnlyList<long>?
    Cost         // -> long
    Acknowledged // -> bool

PARAMETERS:

  • LongIds (IReadOnlyList?) -

    The ids of the mutated rows when the primary key is an integer, or null for string keys.

  • StringIds (IReadOnlyList?) -

    The ids of the mutated rows when the primary key is a string, or null for integer keys.

  • InsertCount (long) -

    The number of inserted rows.

  • DeleteCount (long) -

    The number of deleted rows.

  • UpsertCount (long) -

    The number of upserted rows.

  • Timestamp (ulong) -

    The hybrid timestamp of the mutation, used by the CollectionTsCache for Session consistency.

  • SuccessIndex (IReadOnlyList?) -

    The zero-based indexes of the rows that were successfully written, or null when the server reports no partial-failure information.

  • ErrorIndex (IReadOnlyList?) -

    The zero-based indexes of the rows that failed, or null when the server reports no partial-failure information. An empty-but-non-null list means all rows succeeded.

  • Cost (long) -

    The cost of the mutation in milliseconds, as reported by the server’s report_value extra info, or 0 when the server does not report a cost.

  • Acknowledged (bool) -

    Whether the mutation was acknowledged by the server. The current server does not populate the flag.

EXCEPTIONS:

  • MilvusException

    Thrown when the RPC fails or the server returns an error. Inspect the exception message for details.

Example

using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Dml;
using Milvus.Client.V2.Responses.Dml;
using Milvus.Client.V2.Types;

using var client = new MilvusClientV2(new ConnectConfig
{
    Uri = "localhost:19530",
    Username = "root",
    Password = "Milvus"
});
await client.ConnectAsync();

MutationResp result = await client.InsertAsync(new InsertReq
{
    CollectionName = "my_collection",
    RowsData =
    [
        new Dictionary<string, object?> { ["id"] = 1L, ["title"] = "A", ["vector"] = new[] { 0.1f, 0.2f } },
        new Dictionary<string, object?> { ["id"] = 2L, ["title"] = "B", ["vector"] = new[] { 0.3f, 0.4f } }
    ]
});

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?