POST/v2/namespaces/:namespace

Creates, updates, or deletes documents.

A :namespace is an isolated set of documents and is implicitly created when the first document is inserted, or explicitly created with create_namespace. Namespace names must match [A-Za-z0-9-_.]{1,128}.

We recommend creating a namespace per isolated document space instead of filtering when possible. Large batches of writes are highly encouraged to maximize throughput and minimize cost. Write requests can have a payload size of up to 512 MB. See Performance.

Within a namespace, documents are uniquely referred to by their ID. Document IDs are unsigned 64-bit integers, 128-bit UUIDs, or strings up to 64 bytes.

This concept ports the examples below. The full write reference (every parameter, the response, attributes and the schema) is on turbopuffer.com.

Examples

Row-based writes

Row-based writes may be more convenient than column-based writes. You can pass any combination of upsert_rows, patch_rows, patch_by_filter, deletes, and delete_by_filter to the write request.

If the same document ID appears multiple times in the request, the request will fail with an HTTP 400 error.

# choose best region: https://turbopuffer.com/docs/regions
curl https://gcp-us-east4.turbopuffer.com/v2/namespaces/write-upsert-row-example-curl \
  -X POST --fail-with-body \
  -H "Authorization: Bearer $TURBOPUFFER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "distance_metric": "cosine_distance",
  "upsert_rows": [
    {
      "id": 1,
      "vector": [0.1, 0.1],
      "my-string": "one",
      "my-uint": 12,
      "my-bool": true,
      "my-string-array": ["a", "b"]
    },
    {
      "id": 2,
      "vector": [0.2, 0.2],
      "my-string-array": ["b", "d"]
    }
  ],
  "patch_rows": [
    {
      "id": 3,
      "my-bool": true
    }
  ],
  "deletes": [4]
}'

# Response payload
# {
#   "status": "OK"
# }
// dotnet add package Turbopuffer
using System;
using System.Collections.Generic;
using Turbopuffer;
using Turbopuffer.Models.Namespaces;

using var tpuf = new TurbopufferClient
{
    // Pick the right region: https://turbopuffer.com/docs/regions
    Region = "gcp-us-east4",
};

var ns = tpuf.Namespace("write-upsert-row-example-csharp");
// If an error occurs, this call raises a TurbopufferApiException if a retry was not successful.
await ns.Write(
    new NamespaceWriteParams
    {
        UpsertRows =
        [
            new Row()
                .Set("id", 1)
                .Set("vector", new[] { 0.1f, 0.1f })
                .Set("my-string", "one")
                .Set("my-uint", 12)
                .Set("my-bool", true)
                .Set("my-string-array", new[] { "a", "b" }),
            new Row()
                .Set("id", 2)
                .Set("vector", new[] { 0.2f, 0.2f })
                .Set("my-string-array", new[] { "b", "d" }),
        ],
        PatchRows = [new Row().Set("id", 3).Set("my-bool", true)],
        Deletes = [4L],
        DistanceMetric = DistanceMetric.CosineDistance,
    }
);
package main

import (
	"context"
	"os"

	"github.com/turbopuffer/turbopuffer-go/v2"
	"github.com/turbopuffer/turbopuffer-go/v2/option"
)

func main() {
	ctx := context.Background()
	tpuf := turbopuffer.NewClient(
		// API tokens are created in the dashboard: https://turbopuffer.com/dashboard
		option.WithAPIKey(os.Getenv("TURBOPUFFER_API_KEY")),
		option.WithRegion("gcp-us-east4"), // choose best region: https://turbopuffer.com/docs/regions
	)

	ns := tpuf.Namespace("write-upsert-row-example-go")
	// If an error occurs, this call raises an error if a retry was not successful.
	_, err := ns.Write(
		ctx,
		turbopuffer.NamespaceWriteParams{
			UpsertRows: []turbopuffer.RowParam{
				{
					"id":              1,
					"vector":          []float32{0.1, 0.1},
					"my-string":       "one",
					"my-uint":         12,
					"my-bool":         true,
					"my-string-array": []string{"a", "b"},
				},
				{
					"id":              2,
					"vector":          []float32{0.2, 0.2},
					"my-string-array": []string{"b", "d"},
				},
			},
			PatchRows: []turbopuffer.RowParam{
				{
					"id":      3,
					"my-bool": true,
				},
			},
			Deletes:        []any{4},
			DistanceMetric: turbopuffer.DistanceMetricCosineDistance,
		},
	)
	if err != nil {
		panic(err)
	}
}
package com.turbopuffer.docs;

import com.turbopuffer.client.okhttp.*;
import com.turbopuffer.core.*;
import com.turbopuffer.models.namespaces.*;
import java.util.*;
import java.util.stream.*;

public class WriteUpsertRow {

  public static void main(String[] args) {
    var tpuf = TurbopufferOkHttpClient.builder()
      .fromEnv()
      .region("gcp-us-east4") // choose best region: https://turbopuffer.com/docs/regions
      .build();

    var ns = tpuf.namespace("write-upsert-row-example-java");
    // If an error occurs, this call raises a TurbopufferServiceException if a retry was not successful.
    ns.write(
      NamespaceWriteParams.builder()
        .upsertRows(
          List.of(
            Row.builder()
              .put("id", 1)
              .put("vector", List.of(0.1f, 0.1f))
              .put("my-string", "one")
              .put("my-uint", 12)
              .put("my-bool", true)
              .put("my-string-array", List.of("a", "b"))
              .build(),
            Row.builder()
              .put("id", 2)
              .put("vector", List.of(0.2f, 0.2f))
              .put("my-string-array", List.of("b", "d"))
              .build()
          )
        )
        .patchRows(List.of(Row.builder().put("id", 3).put("my-bool", true).build()))
        .addDelete(4)
        .distanceMetric(DistanceMetric.COSINE_DISTANCE)
        .build()
    );
  }
}
import turbopuffer

tpuf = turbopuffer.Turbopuffer(
    region='gcp-us-east4', # choose best region: https://turbopuffer.com/docs/regions
)

ns = tpuf.namespace(f'write-upsert-row-example-py')
# If an error occurs, this call raises a turbopuffer.APIError if a retry was not successful.
ns.write(
    upsert_rows=[
        {
            'id': 1,
            'vector': [0.1, 0.1],
            'my-string': 'one',
            'my-uint': 12,
            'my-bool': True,
            'my-string-array': ['a', 'b']
        },
        {
            'id': 2,
            'vector': [0.2, 0.2],
            'my-string-array': ['b', 'd']
        },
    ],
    patch_rows=[
        {
            'id': 3,
            'my-bool': True
        },
    ],
    deletes=[4],
    distance_metric='cosine_distance'
)
require "turbopuffer"

tpuf = Turbopuffer::Client.new(
  region: "gcp-us-east4", # choose best region: https://turbopuffer.com/docs/regions
)

ns = tpuf.namespace("write-upsert-row-example-rb")
# If an error occurs, this call raises a Turbopuffer::Errors::APIError if a retry was not successful.
ns.write(
  upsert_rows: [
    {
      id: 1,
      vector: [0.1, 0.1],
      'my-string': "one",
      'my-uint': 12,
      'my-bool': true,
      'my-string-array': ["a", "b"],
    },
    {
      id: 2,
      vector: [0.2, 0.2],
      'my-string-array': ["b", "d"],
    },
  ],
  patch_rows: [
    {
      id: 3,
      'my-bool': true,
    },
  ],
  deletes: [4],
  distance_metric: "cosine_distance",
)
use turbopuffer::Client;
use turbopuffer::types::{DistanceMetric, Row};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // The API key is read from TURBOPUFFER_API_KEY. Create one here: https://turbopuffer.com/dashboard
    let client = Client::builder()
        .region("gcp-us-east4") // choose best region: https://turbopuffer.com/docs/regions
        .build()?;

    let ns = client.namespace("write-upsert-row-example-rs");
    // If an error occurs, this call returns a turbopuffer::Error once retries are exhausted.
    ns.write()
        .upsert_rows([
            Row::new(1)
                .vector([0.1, 0.1])
                .insert("my-string", "one")
                .insert("my-uint", 12)
                .insert("my-bool", true)
                .insert("my-string-array", ["a", "b"]),
            Row::new(2)
                .vector([0.2, 0.2])
                .insert("my-string-array", ["b", "d"]),
        ])
        .patch_rows([Row::new(3).insert("my-bool", true)])
        .deletes([4])
        .distance_metric(DistanceMetric::CosineDistance)
        .send()
        .await?;

    Ok(())
}
import { Turbopuffer } from "@turbopuffer/turbopuffer";

const tpuf = new Turbopuffer({
  region: "gcp-us-east4", // choose best region: https://turbopuffer.com/docs/regions
});

const ns = tpuf.namespace(`write-upsert-row-example-ts`);

await ns.write({
  upsert_rows: [
    {
      id: 1,
      vector: [0.1, 0.1],
      "my-string": "one",
      "my-uint": 12,
      "my-bool": true,
      "my-string-array": ["a", "b"],
    },
    {
      id: 2,
      vector: [0.2, 0.2],
      "my-string-array": ["b", "d"],
    }
  ],
  patch_rows: [
    {
      id: 3,
      "my-bool": true,
    }
  ],
  deletes: [4],
  distance_metric: "cosine_distance",
});

Configuring the schema

The schema can be passed on writes to manually configure attribute types and indexing behavior. A few examples where manually configuring the schema is needed:

  • UUID values serialized as strings can be stored in turbopuffer in an optimized format.
  • Enabling full-text search, regex, glob, or fuzzy indexing for string attributes.
  • Disabling indexing/filtering (filterable:false) on an attribute, for a 50% discount and improved indexing performance.

An example of (1), (2), and (3):

# Make a POST request using curl
# choose best region: https://turbopuffer.com/docs/regions
curl https://gcp-us-east4.turbopuffer.com/v2/namespaces/write-schema-example-curl \
  -X POST --fail-with-body \
  -H "Authorization: Bearer $TURBOPUFFER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "upsert_rows": [
    {"id": "769c134d-07b8-4225-954a-b6cc5ffc320c", "vector": [0.1, 0.1], "text": "the fox is quick and brown", "string": "fox", "permissions": ["ee1f7c89-a3aa-43c1-8941-c987ee03e7bc", "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e"]}
  ],
  "distance_metric": "cosine_distance",
  "schema": {
    "id": "uuid",
    "text": {
      "type": "string",
      "full_text_search": true
    },
    "permissions": {
      "type": "[]uuid"
    }
  }
}'

# Response payload
# {
#   "status": "OK"
# }
// dotnet add package Turbopuffer
using System;
using System.Collections.Generic;
using Turbopuffer;
using Turbopuffer.Models.Namespaces;

using var tpuf = new TurbopufferClient
{
    // Pick the right region: https://turbopuffer.com/docs/regions
    Region = "gcp-us-east4",
};

var ns = tpuf.Namespace("write-schema-example-csharp");

await ns.Write(
    new NamespaceWriteParams
    {
        UpsertRows =
        [
            new Row()
                .Set("id", "769c134d-07b8-4225-954a-b6cc5ffc320c")
                .Set("vector", new[] { 0.1f, 0.1f })
                .Set("text", "the fox is quick and brown")
                .Set("string", "fox")
                .Set(
                    "permissions",
                    new[]
                    {
                        "ee1f7c89-a3aa-43c1-8941-c987ee03e7bc",
                        "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e",
                    }
                ),
        ],
        DistanceMetric = DistanceMetric.CosineDistance,
        Schema = new Dictionary<string, AttributeSchemaConfig>
        {
            ["id"] = new AttributeSchemaConfig { Type = "uuid" },
            ["text"] = new AttributeSchemaConfig
            {
                Type = "string",
                // Sets filterable(false), and enables FTS with default settings
                FullTextSearch = true,
            },
            ["permissions"] = new AttributeSchemaConfig
            {
                Type = "[]uuid", // otherwise inferred as slower/more expensive []string
            },
        },
    }
);
package main

import (
	"context"
	"os"

	"github.com/turbopuffer/turbopuffer-go/v2"
	"github.com/turbopuffer/turbopuffer-go/v2/option"
)

func main() {
	ctx := context.Background()
	tpuf := turbopuffer.NewClient(
		option.WithRegion("gcp-us-east4"), // choose best region: https://turbopuffer.com/docs/regions
	)

	ns := tpuf.Namespace("write-schema-example-go")

	_, err := ns.Write(
		ctx,
		turbopuffer.NamespaceWriteParams{
			UpsertRows: []turbopuffer.RowParam{
				{
					"id":          "769c134d-07b8-4225-954a-b6cc5ffc320c",
					"vector":      []float32{0.1, 0.1},
					"text":        "the fox is quick and brown",
					"string":      "fox",
					"permissions": []string{"ee1f7c89-a3aa-43c1-8941-c987ee03e7bc", "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e"},
				},
			},
			DistanceMetric: turbopuffer.DistanceMetricCosineDistance,
			Schema: map[string]turbopuffer.AttributeSchemaParam{
				"id": turbopuffer.AttributeSchemaParamAttributeSchemaConfig("uuid"),
				"text": {AttributeSchemaConfig: &turbopuffer.AttributeSchemaConfigParam{
					Type: "string",
					// sets filterable: false, and enables FTS with default settings
					FullTextSearch: &turbopuffer.FullTextSearchConfigParam{},
				}},
				// Otherwise inferred as slower/more expensive []string
				"permissions": turbopuffer.AttributeSchemaParamAttributeSchemaConfig("[]uuid"),
			},
		},
	)
	if err != nil {
		panic(err)
	}
}
package com.turbopuffer.docs;

import com.turbopuffer.client.okhttp.*;
import com.turbopuffer.models.namespaces.*;
import java.util.*;

public class WriteSchema {

  public static void main(String[] args) {
    var tpuf = TurbopufferOkHttpClient.builder()
      .fromEnv()
      .region("gcp-us-east4") // choose best region: https://turbopuffer.com/docs/regions
      .build();

    var ns = tpuf.namespace("write-schema-example-java");

    ns.write(
      NamespaceWriteParams.builder()
        .addUpsertRow(
          Row.builder()
            .put("id", "769c134d-07b8-4225-954a-b6cc5ffc320c")
            .put("vector", List.of(0.1f, 0.1f))
            .put("text", "the fox is quick and brown")
            .put("string", "fox")
            .put(
              "permissions",
              List.of(
                "ee1f7c89-a3aa-43c1-8941-c987ee03e7bc",
                "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e"
              )
            )
            .build()
        )
        .distanceMetric(DistanceMetric.COSINE_DISTANCE)
        .schema(
          Schema.builder()
            .put("id", AttributeSchemaConfig.builder().type("uuid").build())
            .put(
              "text",
              AttributeSchemaConfig.builder()
                .type("string")
                // Sets filterable(false), and enables FTS with default settings
                .fullTextSearch(FullTextSearchConfig.defaults())
                .build()
            )
            .put(
              "permissions",
              AttributeSchemaConfig.builder()
                .type("[]uuid") // otherwise inferred as slower/more expensive []string
                .build()
            )
            .build()
        )
        .build()
    );
  }
}
import turbopuffer

tpuf = turbopuffer.Turbopuffer(
    region='gcp-us-east4', # choose best region: https://turbopuffer.com/docs/regions
)

ns = tpuf.namespace(f'write-schema-example-py')

ns.write(
    upsert_rows=[
        {
            'id': "769c134d-07b8-4225-954a-b6cc5ffc320c",
            'vector': [0.1, 0.1],
            'text': 'the fox is quick and brown',
            'string': 'fox',
            'permissions': ['ee1f7c89-a3aa-43c1-8941-c987ee03e7bc', '95cdf8be-98a9-4061-8eeb-2702b6bbcb9e']
        },
    ],
    distance_metric='cosine_distance',
    schema={
        'id': 'uuid',
        'text': {
            'type': 'string',
            'full_text_search': True # sets filterable: false, and enables FTS with default settings
        },
        'permissions': {
            'type': '[]uuid', # otherwise inferred as slower/more expensive []string
        }
    }
)
require "turbopuffer"

tpuf = Turbopuffer::Client.new(
  region: "gcp-us-east4", # choose best region: https://turbopuffer.com/docs/regions
)

ns = tpuf.namespace("write-schema-example-rb")

ns.write(
  upsert_rows: [
    {
      id: "769c134d-07b8-4225-954a-b6cc5ffc320c",
      vector: [0.1, 0.1],
      text: "the fox is quick and brown",
      string: "fox",
      permissions: ["ee1f7c89-a3aa-43c1-8941-c987ee03e7bc", "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e"],
    },
  ],
  distance_metric: "cosine_distance",
  schema: {
    id: "uuid",
    text: {
      type: "string",
      full_text_search: true, # sets filterable: false, and enables FTS with default settings
    },
    permissions: {
      type: "[]uuid", # otherwise inferred as slower/more expensive []string
    },
  },
)
use turbopuffer::Client;
use turbopuffer::types::{AttributeSchemaConfig, DistanceMetric, Row};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // The API key is read from TURBOPUFFER_API_KEY. Create one here: https://turbopuffer.com/dashboard
    let client = Client::builder()
        .region("gcp-us-east4") // choose best region: https://turbopuffer.com/docs/regions
        .build()?;

    let ns = client.namespace("write-schema-example-rs");

    ns.write()
        .upsert_rows([Row::new("769c134d-07b8-4225-954a-b6cc5ffc320c")
            .vector([0.1, 0.1])
            .insert("text", "the fox is quick and brown")
            .insert("string", "fox")
            .insert(
                "permissions",
                [
                    "ee1f7c89-a3aa-43c1-8941-c987ee03e7bc",
                    "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e",
                ],
            )])
        .distance_metric(DistanceMetric::CosineDistance)
        .schema([
            ("id", AttributeSchemaConfig::new("uuid")),
            (
                "text",
                // Sets filterable: false, and enables FTS with default settings
                AttributeSchemaConfig::new("string").full_text_search(true),
            ),
            // Otherwise inferred as slower/more expensive []string
            ("permissions", AttributeSchemaConfig::new("[]uuid")),
        ])
        .send()
        .await?;

    Ok(())
}
import { Turbopuffer } from "@turbopuffer/turbopuffer";

const tpuf = new Turbopuffer({
  region: "gcp-us-east4", // choose best region: https://turbopuffer.com/docs/regions
});

const ns = tpuf.namespace(`write-schema-example-ts`);

await ns.write({
  upsert_rows: [
    {
      id: "769c134d-07b8-4225-954a-b6cc5ffc320c",
      vector: [0.1, 0.1],
      text: "the fox is quick and brown",
      string: "fox",
      permissions: ["ee1f7c89-a3aa-43c1-8941-c987ee03e7bc", "95cdf8be-98a9-4061-8eeb-2702b6bbcb9e"],
    },
  ],
  distance_metric: "cosine_distance",
  schema: {
    id: "uuid",
    text: {
      type: "string",
      full_text_search: true, // sets filterable: false, and enables FTS with default settings
    },
    permissions: {
      type: "[]uuid", // otherwise inferred as slower/more expensive []string
    },
  },
});

Column-based writes

Bulk document operations should use a column-oriented layout for best performance. You can pass any combination of upsert_columns, patch_columns, deletes, and delete_by_filter to the write request.

If the same document ID appears multiple times in the request, the request will fail with an HTTP 400 error.

# Make a POST request using curl
# choose best region: https://turbopuffer.com/docs/regions
curl https://gcp-us-east4.turbopuffer.com/v2/namespaces/write-upsert-columns-example-curl \
  -X POST --fail-with-body \
  -H "Authorization: Bearer $TURBOPUFFER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "upsert_columns": {
    "id": [1, 2, 3, 4],
    "vector": [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4]],
    "my-string": ["one", null, "three", "four"],
    "my-uint": [12, null, 84, 39],
    "my-bool": [true, null, false, true],
    "my-string-array": [["a", "b"], ["b", "d"], [], ["c"]]
  },
  "patch_columns": {
    "id": [5, 6],
    "my-bool": [true, false]
  },
  "deletes": [7, 8],
  "distance_metric": "cosine_distance"
 }'

# Response payload
# {
#   "status": "OK"
# }
// dotnet add package Turbopuffer
using System;
using System.Collections.Generic;
using Turbopuffer;
using Turbopuffer.Models.Namespaces;

using var tpuf = new TurbopufferClient
{
    // Pick the right region: https://turbopuffer.com/docs/regions
    Region = "gcp-us-east4",
};

var ns = tpuf.Namespace("write-upsert-columns-example-csharp");
// If an error occurs, this call raises a TurbopufferApiException if a retry was not successful.
await ns.Write(
    new NamespaceWriteParams
    {
        UpsertColumns = new Columns()
            .SetColumn("id", new[] { 1, 2, 3, 4 })
            .SetColumn(
                "vector",
                new[]
                {
                    new[] { 0.1f, 0.1f },
                    new[] { 0.2f, 0.2f },
                    new[] { 0.3f, 0.3f },
                    new[] { 0.4f, 0.4f },
                }
            )
            // For columns that contain nulls, use a nullable element type
            // (null = no value).
            .SetColumn("my-string", new[] { "one", null, "three", "four" })
            .SetColumn("my-uint", new uint?[] { 12, null, 84, 39 })
            .SetColumn("my-bool", new bool?[] { true, null, false, true })
            .SetColumn(
                "my-string-array",
                new string[][]
                {
                    new string[] { "a", "b" },
                    new string[] { "b", "d" },
                    Array.Empty<string>(),
                    new string[] { "c" },
                }
            ),
        PatchColumns = new Columns()
            .SetColumn("id", new[] { 5, 6 })
            .SetColumn("my-bool", new[] { true, false }),
        Deletes = [7L, 8L],
        DistanceMetric = DistanceMetric.CosineDistance,
    }
);
package main

import (
	"context"
	"os"

	"github.com/turbopuffer/turbopuffer-go/v2"
	"github.com/turbopuffer/turbopuffer-go/v2/option"
)

func main() {
	ctx := context.Background()
	tpuf := turbopuffer.NewClient(
		// API tokens are created in the dashboard: https://turbopuffer.com/dashboard
		option.WithAPIKey(os.Getenv("TURBOPUFFER_API_KEY")),
		option.WithRegion("gcp-us-east4"), // choose best region: https://turbopuffer.com/docs/regions
	)

	ns := tpuf.Namespace("write-upsert-columns-example-go")
	// If an error occurs, this call raises an error if a retry was not successful.
	_, err := ns.Write(
		ctx,
		turbopuffer.NamespaceWriteParams{
			UpsertColumns: map[string][]any{
				"id":              {1, 2, 3, 4},
				"vector":          {[]float32{0.1, 0.1}, []float32{0.2, 0.2}, []float32{0.3, 0.3}, []float32{0.4, 0.4}},
				"my-string":       {"one", nil, "three", "four"},
				"my-uint":         {12, nil, 84, 39},
				"my-bool":         {true, nil, false, true},
				"my-string-array": {[]string{"a", "b"}, []string{"b", "d"}, []string{}, []string{"c"}},
			},
			PatchColumns: map[string][]any{
				"id":      {5, 6},
				"my-bool": {true, false},
			},
			Deletes:        []any{7, 8},
			DistanceMetric: turbopuffer.DistanceMetricCosineDistance,
		},
	)
	if err != nil {
		panic(err)
	}
}
package com.turbopuffer.docs;

import com.turbopuffer.client.okhttp.*;
import com.turbopuffer.core.*;
import com.turbopuffer.models.namespaces.*;
import java.util.*;
import java.util.stream.*;

public class WriteUpsertColumns {

  public static void main(String[] args) {
    var tpuf = TurbopufferOkHttpClient.builder()
      .fromEnv()
      .region("gcp-us-east4") // choose best region: https://turbopuffer.com/docs/regions
      .build();

    var ns = tpuf.namespace("write-upsert-columns-example-java");
    // If an error occurs, this call raises a TurbopufferServiceException if a retry was not successful.
    ns.write(
      NamespaceWriteParams.builder()
        .upsertColumns(
          Columns.builder()
            .put("id", List.of(1, 2, 3, 4))
            .put(
              "vector",
              List.of(
                List.of(0.1f, 0.1f),
                List.of(0.2f, 0.2f),
                List.of(0.3f, 0.3f),
                List.of(0.4f, 0.4f)
              )
            )
            .put("my-string", List.of("one", Optional.empty(), "three", "four"))
            .put("my-uint", List.of(12, Optional.empty(), 84, 39))
            .put("my-bool", List.of(true, Optional.empty(), false, true))
            .put(
              "my-string-array",
              List.of(List.of("a", "b"), List.of("b", "d"), List.of(), List.of("c"))
            )
            .build()
        )
        .patchColumns(
          Columns.builder().put("id", List.of(5, 6)).put("my-bool", List.of(true, false)).build()
        )
        .deletes(List.of(7, 8))
        .distanceMetric(DistanceMetric.COSINE_DISTANCE)
        .build()
    );
  }
}
import turbopuffer

tpuf = turbopuffer.Turbopuffer(
    region='gcp-us-east4', # choose best region: https://turbopuffer.com/docs/regions
)

ns = tpuf.namespace(f'write-upsert-columns-example-py')
# If an error occurs, this call raises a turbopuffer.APIError if a retry was not successful.
ns.write(
    upsert_columns={
        'id': [1, 2, 3, 4],
        'vector': [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4]],
        'my-string': ['one', None, 'three', 'four'],
        'my-uint': [12, None, 84, 39],
        'my-bool': [True, None, False, True],
        'my-string-array': [['a', 'b'], ['b', 'd'], [], ['c']]
    },
    patch_columns={
        'id': [5, 6],
        'my-bool': [True, False],
    },
    deletes=[7, 8],
    distance_metric='cosine_distance'
)
require "turbopuffer"

tpuf = Turbopuffer::Client.new(
  region: "gcp-us-east4", # choose best region: https://turbopuffer.com/docs/regions
)

ns = tpuf.namespace("write-upsert-columns-example-rb")
# If an error occurs, this call raises a Turbopuffer::Errors::APIError if a retry was not successful.
ns.write(
  upsert_columns: {
    id: [1, 2, 3, 4],
    vector: [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4]],
    'my-string': ["one", nil, "three", "four"],
    'my-uint': [12, nil, 84, 39],
    'my-bool': [true, nil, false, true],
    'my-string-array': [["a", "b"], ["b", "d"], [], ["c"]],
  },
  patch_columns: {
    id: [5, 6],
    'my-bool': [true, false],
  },
  deletes: [7, 8],
  distance_metric: "cosine_distance",
)
use turbopuffer::Client;
use turbopuffer::types::{Columns, DistanceMetric};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // The API key is read from TURBOPUFFER_API_KEY. Create one here: https://turbopuffer.com/dashboard
    let client = Client::builder()
        .region("gcp-us-east4") // choose best region: https://turbopuffer.com/docs/regions
        .build()?;

    let ns = client.namespace("write-upsert-columns-example-rs");
    // If an error occurs, this call returns a turbopuffer::Error once retries are exhausted.
    ns.write()
        .upsert_columns(
            Columns::new([1, 2, 3, 4])
                .vector([[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4]])
                // None leaves the attribute unset for that document.
                .insert(
                    "my-string",
                    [Some("one"), None, Some("three"), Some("four")],
                )
                .insert("my-uint", [Some(12), None, Some(84), Some(39)])
                .insert("my-bool", [Some(true), None, Some(false), Some(true)])
                .insert(
                    "my-string-array",
                    [vec!["a", "b"], vec!["b", "d"], vec![], vec!["c"]],
                ),
        )
        .patch_columns(Columns::new([5, 6]).insert("my-bool", [true, false]))
        .deletes([7, 8])
        .distance_metric(DistanceMetric::CosineDistance)
        .send()
        .await?;

    Ok(())
}
// $ npm install @turbopuffer/turbopuffer
import { Turbopuffer } from "@turbopuffer/turbopuffer";

const tpuf = new Turbopuffer({
  // API tokens are created in the dashboard: https://turbopuffer.com/dashboard
  apiKey: process.env.TURBOPUFFER_API_KEY,
  region: "gcp-us-east4", // choose best region: https://turbopuffer.com/docs/regions
});

const ns = tpuf.namespace(`write-upsert-columns-example-ts`);

await ns.write({
  upsert_columns: {
    id: [1, 2, 3, 4],
    vector: [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4]],
    "my-string": ["one", null, "three", "four"],
    "my-uint": [12, null, 84, 39],
    "my-bool": [true, null, false, true],
    "my-string-array": [["a", "b"], ["b", "d"], [], ["c"]],
  },
  patch_columns: {
    id: [5, 6],
    "my-bool": [true, false],
  },
  deletes: [7, 8],
  distance_metric: "cosine_distance",
});