Skip to content

Points

Insert, retrieve, search, and delete points (vectors with payload) in a Qdrant collection.

This example assumes using Qdrant; is in scope and apiKey contains your Qdrant API key.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var client = Client;
var collectionName = $"test_points_{Guid.NewGuid():N}";

// Create a collection with 4-dimensional vectors using Dot product distance.

await client.Collections.CreateCollectionAsync(
    collectionName: collectionName,
    vectors: new VectorParams
    {
        Size = 4,
        Distance = Distance.Dot,
    });

// Upsert points with vectors and payload data.

var upsertResponse = await client.Points.UpsertPointsAsync(
    collectionName: collectionName,
    wait: true,
    request: new PointsList
    {
        Points =
        [
            new PointStruct
            {
                Id = 1,
                Vector = new VectorStruct { Value1 = new[] { 0.05f, 0.61f, 0.76f, 0.74f } },
                Payload = new Payload { AdditionalProperties = new Dictionary<string, object> { ["city"] = "Berlin" } },
            },
            new PointStruct
            {
                Id = 2,
                Vector = new VectorStruct { Value1 = new[] { 0.19f, 0.81f, 0.75f, 0.11f } },
                Payload = new Payload { AdditionalProperties = new Dictionary<string, object> { ["city"] = "London" } },
            },
            new PointStruct
            {
                Id = 3,
                Vector = new VectorStruct { Value1 = new[] { 0.36f, 0.55f, 0.47f, 0.94f } },
                Payload = new Payload { AdditionalProperties = new Dictionary<string, object> { ["city"] = "Moscow" } },
            },
            new PointStruct
            {
                Id = 4,
                Vector = new VectorStruct { Value1 = new[] { 0.18f, 0.01f, 0.85f, 0.80f } },
                Payload = new Payload { AdditionalProperties = new Dictionary<string, object> { ["city"] = "New York" } },
            },
            new PointStruct
            {
                Id = 5,
                Vector = new VectorStruct { Value1 = new[] { 0.24f, 0.18f, 0.22f, 0.44f } },
                Payload = new Payload { AdditionalProperties = new Dictionary<string, object> { ["city"] = "Tokyo" } },
            },
        ],
    });

Console.WriteLine("Upserted 5 points.");

// Retrieve a specific point by its ID.

var getPointResponse = await client.Points.GetPointAsync(
    collectionName: collectionName,
    id: 1);

Console.WriteLine($"Retrieved point with ID: {getPointResponse.Result!.Id}");

// Count points in the collection.

var countResponse = await client.Points.CountPointsAsync(
    collectionName: collectionName,
    exact: true);

Console.WriteLine($"Collection contains {countResponse.Result.Count} points.");

// Search for the 3 nearest neighbors using a query vector.

var queryResponse = await client.Search.QueryPointsAsync(
    collectionName: collectionName,
    request: new QueryRequest
    {
        Query = new QueryInterface
        {
            Value1 = new VectorInput
            {
                Value1 = new[] { 0.2f, 0.1f, 0.9f, 0.7f },
            },
        },
        Limit = 3,
        WithPayload = true,
    });

foreach (var point in queryResponse.Result.Points)
{
    Console.WriteLine($"Point ID: {point.Id}, Score: {point.Score}");
}

// Delete specific points by ID.

var deleteResponse = await client.Points.DeletePointsAsync(
    collectionName: collectionName,
    wait: true,
    request: new PointIdsList
    {
        Points = [1, 2],
    });

// Verify the remaining point count.

var countAfterDelete = await client.Points.CountPointsAsync(
    collectionName: collectionName,
    exact: true);

Console.WriteLine("Deleted 2 points. 3 remaining.");

// Cleanup: delete the collection.

await client.Collections.DeleteCollectionAsync(
    collectionName: collectionName);