> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using LanceDB and Object Storage to generate, persist, and query vector embeddings

*Vector embeddings* turn text, images, and other unstructured data into numerical vectors that you can search by similarity, which is the basis for semantic search and retrieval-augmented generation (RAG).

This tutorial shows you how to run a nearest-neighbor similarity search by using [LanceDB](https://lancedb.com/) with [Object Storage](https://docs.nebius.com/object-storage/index.md) as a persistent vector store. LanceDB writes tables directly to an Object Storage bucket. Each table contains vector embeddings alongside structured metadata, and there is no separate database server to run or manage. Object Storage exposes an [S3-compatible API](https://docs.nebius.com/object-storage/interfaces/s3-api-compatibility.md), so LanceDB connects to it with no additional drivers.

## Costs

In this tutorial, Nebius AI Cloud charges for one resource: [Object Storage](https://docs.nebius.com/object-storage/resources/pricing.md), for the storage that the LanceDB files consume in your bucket.

## Prerequisites

> [tab] Web console
>
> 1. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `editor` role within your tenant or project; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
> 2. Set up Python or Node.js for the LanceDB client that you want to use:
>
>    * Python: [Install Python 3.10](https://www.python.org/downloads/) or later, or use a running [JupyterLab® Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md).
>    * TypeScript: [Install Node.js 22](https://nodejs.org/en/download) or later.

> [tab] CLI
>
> 1. [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.
> 2. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `editor` role within your tenant or project; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
> 3. Set up Python or Node.js for the LanceDB client that you want to use:
>
>    * Python: [Install Python 3.10](https://www.python.org/downloads/) or later, or use a running [JupyterLab® Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md).
>    * TypeScript: [Install Node.js 22](https://nodejs.org/en/download) or later.

> [tab] Terraform
>
> 1. [Install and configure](https://docs.nebius.com/terraform-provider/install.md) the Nebius AI Cloud provider for Terraform.
> 2. [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.
> 3. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `editor` role within your tenant or project; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
> 4. Set up Python or Node.js for the LanceDB client that you want to use:
>
>    * Python: [Install Python 3.10](https://www.python.org/downloads/) or later, or use a running [JupyterLab® Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md).
>    * TypeScript: [Install Node.js 22](https://nodejs.org/en/download) or later.

> [tab] Go SDK
>
> 1. [Install and initialize the Nebius SDK for Go](https://docs.nebius.com/sdk/go/install-auth.md).
> 2. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `editor` role within your tenant or project; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
> 3. Set up Python or Node.js for the LanceDB client that you want to use:
>
>    * Python: [Install Python 3.10](https://www.python.org/downloads/) or later, or use a running [JupyterLab® Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md).
>    * TypeScript: [Install Node.js 22](https://nodejs.org/en/download) or later.

> [tab] Python SDK
>
> 1. [Install and initialize the Nebius SDK for Python](https://docs.nebius.com/sdk/python/install-auth.md).
> 2. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `editor` role within your tenant or project; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
> 3. Set up Python or Node.js for the LanceDB client that you want to use:
>
>    * Python: [Install Python 3.10](https://www.python.org/downloads/) or later, or use a running [JupyterLab® Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md).
>    * TypeScript: [Install Node.js 22](https://nodejs.org/en/download) or later.

> [tab] JavaScript SDK
>
> 1. [Install and initialize the Nebius SDK for JavaScript](https://docs.nebius.com/sdk/javascript/install-auth.md).
> 2. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has at least the `editor` role within your tenant or project; for example, the default `editors` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
> 3. Set up Python or Node.js for the LanceDB client that you want to use:
>
>    * Python: [Install Python 3.10](https://www.python.org/downloads/) or later, or use a running [JupyterLab® Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md).
>    * TypeScript: [Install Node.js 22](https://nodejs.org/en/download) or later.

## Steps

### Create an Object Storage bucket

Create a bucket for the LanceDB data. This tutorial uses the Enhanced Throughput storage class because it's well suited for streaming embeddings or model weights at scale and for latency-sensitive queries. You can use the Standard storage class instead. For a comparison, see [Storage classes in Object Storage](https://docs.nebius.com/object-storage/storage-classes.md).

> [tab] Web console
>
> 1. In the [web console](https://console.nebius.com), go to  **Storage** → **Object Storage**.
> 2. Click **Create resource** → **Bucket**.
> 3. Enter a name for the bucket. The name must be [unique across the region](https://docs.nebius.com/object-storage/overview.md#naming).
> 4. Select the **Enhanced** storage class.
> 5. Click **Create bucket**.

> [tab] CLI
>
> Create the bucket and save its ID to an environment variable:
>
> ```bash theme={null}
> export BUCKET_ID=$(nebius storage bucket create \
>   --name <bucket_name> \
>   --default-storage-class ENHANCED_THROUGHPUT \
>   --format jsonpath='{.metadata.id}')
> ```
>
> In the command, specify:
>
> * `--name`: Bucket name. The name must be [unique across the region](https://docs.nebius.com/object-storage/overview.md#naming).
> * `--default-storage-class`: Storage class of the bucket.

> [tab] Terraform
>
> 1. Create the following configuration:
>
>    ```hcl theme={null}
>    resource "nebius_storage_v1_bucket" "lancedb_data" {
>      name                  = "<bucket_name>"
>      parent_id             = "<project_ID>"
>      default_storage_class = "ENHANCED_THROUGHPUT"
>    }
>    ```
>
>    The file contains the following parameters:
>
>    * `name`: Bucket name. The name must be [unique across the region](https://docs.nebius.com/object-storage/overview.md#naming).
>    * `parent_id`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-terraform).
>    * `default_storage_class`: Storage class of the bucket.
>
> 2. Check that the configuration is correct:
>    ```bash theme={null}
>    terraform validate
>    ```
>
> 3. Apply the changes:
>    ```bash theme={null}
>    terraform apply
>    ```

> [tab] Go SDK
>
> Create the bucket:
>
> ```go theme={null}
> bucketService := sdk.Services().Storage().V1().Bucket()
> bucketOperation, err := bucketService.Create(
>     ctx,
>     &storage.CreateBucketRequest{
>         Metadata: &common.ResourceMetadata{
>             Name: "<bucket_name>",
>         },
>         Spec: &storage.BucketSpec{
>             DefaultStorageClass: storage.
>                 StorageClass_ENHANCED_THROUGHPUT,
>         },
>     },
> )
> if err != nil {
>     return fmt.Errorf("create bucket: %w", err)
> }
> if _, err = bucketOperation.Wait(ctx); err != nil {
>     return fmt.Errorf("wait for bucket creation: %w", err)
> }
> fmt.Println(bucketOperation.ResourceID())
> ```
>
> In the code, specify:
>
> * `Metadata.Name`: Bucket name. The name must be [unique across the region](https://docs.nebius.com/object-storage/overview.md#naming).
> * `Spec.DefaultStorageClass`: Storage class of the bucket.

> [tab] Python SDK
>
> Create the bucket:
>
> ```python theme={null}
> bucket_service = BucketServiceClient(sdk)
> bucket_operation = await bucket_service.create(
>     CreateBucketRequest(
>         metadata=ResourceMetadata(name="<bucket_name>"),
>         spec=BucketSpec(
>             default_storage_class=StorageClass.ENHANCED_THROUGHPUT,
>         ),
>     ),
> )
> await bucket_operation.wait()
> print(bucket_operation.resource_id)
> ```
>
> In the code, specify:
>
> * `metadata.name`: Bucket name. The name must be [unique across the region](https://docs.nebius.com/object-storage/overview.md#naming).
> * `spec.default_storage_class`: Storage class of the bucket.

> [tab] JavaScript SDK
>
> Create the bucket:
>
> ```ts theme={null}
> const bucketService = new BucketService(sdk);
> const bucketOperation = await bucketService.create(
>   CreateBucketRequest.create({
>     metadata: ResourceMetadata.create({
>       name: "<bucket_name>",
>     }),
>     spec: BucketSpec.create({
>       defaultStorageClass: StorageClass.ENHANCED_THROUGHPUT,
>     }),
>   }),
> ).result;
> await bucketOperation.wait();
> console.log(bucketOperation.resourceId());
> ```
>
> In the code, specify:
>
> * `metadata.name`: Bucket name. The name must be [unique across the region](https://docs.nebius.com/object-storage/overview.md#naming).
> * `spec.defaultStorageClass`: Storage class of the bucket.

### Create a service account and grant it access to the bucket

LanceDB works with the bucket on behalf of a service account. Create a dedicated [service account](https://docs.nebius.com/iam/service-accounts/manage.md), put it in its own [group](https://docs.nebius.com/iam/authorization/groups/index.md), and grant that group access to the bucket:

> [tab] Web console
>
> 1. Create a group for the service account:
>
>    1. In the sidebar, go to  **Administration** → **IAM**.
>    2. Click **Create resource** → **Group**.
>    3. In the window that opens, enter `lancedb-access` as the group name and select your project as the scope of the group.
>    4. Click **Create**.
> 2. Create a service account and add it to the group:
>
>    1. Click **Create resource** → **Service account**.
>    2. In the window that opens, enter `lancedb-sa` as the service account name and select the project.
>    3. Click **Create and continue**.
>    4. In the window that opens, find the `lancedb-access` group by its name or ID and click  **Add** next to it.
>    5. Click **Close**.
> 3. Grant the group read and write access to the bucket:
>
>    1. Go to  **Storage** → **Object Storage**, find the bucket, and copy its ID.
>    2. Go to  **Administration** → **IAM**. On the **Groups** tab, open the `lancedb-access` group and switch to the **Access permits** tab.
>    3. Click **Manage permits**.
>    4. In the **Resource** field, paste the bucket ID and press `Enter`.
>    5. Select the `storage.editor` role.
>    6. Click **Save changes**.

> [tab] CLI
>
> 1. Create a service account:
>
>    ```bash theme={null}
>    export SA_ID=$(nebius iam service-account create \
>      --name lancedb-sa \
>      --format jsonpath='{.metadata.id}')
>    ```
>
> 2. Create a group for the service account in your project and add the service account to the group:
>
>    ```bash theme={null}
>    export PROJECT_ID=$(nebius config get parent-id)
>    export GROUP_ID=$(nebius iam group create \
>      --name lancedb-access --parent-id $PROJECT_ID \
>      --format jsonpath='{.metadata.id}')
>    nebius iam group-membership create \
>      --parent-id $GROUP_ID \
>      --member-id $SA_ID
>    ```
>
> 3. Grant the group read and write access to the bucket with a [bucket policy](https://docs.nebius.com/object-storage/buckets/bucket-policy.md):
>
>    ```bash theme={null}
>    nebius storage bucket update --id $BUCKET_ID \
>      --bucket-policy-rules "[{\"paths\":[\"*\"],\"roles\":[\"storage.editor\"],\"group_id\":\"$GROUP_ID\"}]"
>    ```

> [tab] Terraform
>
> 1. Add the following configuration for the service account:
>
>    ```hcl theme={null}
>    resource "nebius_iam_v1_service_account" "lancedb_sa" {
>      name      = "lancedb-sa"
>      parent_id = "<project_ID>"
>    }
>    ```
>
>    In `parent_id`, specify the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-terraform).
>
> 2. Add the following configuration for the group and for the membership of the service account in the group:
>
>    ```hcl theme={null}
>    resource "nebius_iam_v1_group" "lancedb_access" {
>      name      = "lancedb-access"
>      parent_id = "<project_ID>"
>    }
>
>    resource "nebius_iam_v1_group_membership" "lancedb_sa" {
>      parent_id = nebius_iam_v1_group.lancedb_access.id
>      member_id = nebius_iam_v1_service_account.lancedb_sa.id
>    }
>    ```
>
>    In `parent_id` of the group, specify the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-terraform).
>
> 3. Check that the configuration is correct:
>    ```bash theme={null}
>    terraform validate
>    ```
>
> 4. Apply the changes:
>    ```bash theme={null}
>    terraform apply
>    ```
>
> 5. Grant the group read and write access to the bucket with a [bucket policy](https://docs.nebius.com/object-storage/buckets/bucket-policy.md). To do this, add the `bucket_policy` parameter to the configuration of the bucket:
>
>    ```hcl theme={null}
>    resource "nebius_storage_v1_bucket" "lancedb_data" {
>      # ...
>      bucket_policy = {
>        rules = [
>          {
>            paths    = ["*"]
>            roles    = ["storage.editor"]
>            group_id = nebius_iam_v1_group.lancedb_access.id
>          }
>        ]
>      }
>    }
>    ```
>
>    In the configuration, `# ...` stands for the parameters that you set when you [created the bucket](#create-an-object-storage-bucket-terraform).
>
> 6. Check that the configuration is correct:
>    ```bash theme={null}
>    terraform validate
>    ```
>
> 7. Apply the changes:
>    ```bash theme={null}
>    terraform apply
>    ```

> [tab] Go SDK
>
> 1. Create a service account:
>
>    ```go theme={null}
>    accountService := sdk.Services().IAM().V1().ServiceAccount()
>    accountOperation, err := accountService.Create(
>        ctx,
>        &iam.CreateServiceAccountRequest{
>            Metadata: &common.ResourceMetadata{
>                Name: "lancedb-sa",
>            },
>            Spec: &iam.ServiceAccountSpec{},
>        },
>    )
>    if err != nil {
>        return fmt.Errorf("create service account: %w", err)
>    }
>    if _, err = accountOperation.Wait(ctx); err != nil {
>        return fmt.Errorf("wait for service account: %w", err)
>    }
>    fmt.Println(accountOperation.ResourceID())
>    ```
>
> 2. Create a group for the service account in your project and add the service account to the group:
>
>    ```go theme={null}
>    groupService := sdk.Services().IAM().V1().Group()
>    groupOperation, err := groupService.Create(
>        ctx,
>        &iam.CreateGroupRequest{
>            Metadata: &common.ResourceMetadata{
>                Name:     "lancedb-access",
>                ParentId: "<project_ID>",
>            },
>        },
>    )
>    if err != nil {
>        return fmt.Errorf("create group: %w", err)
>    }
>    if _, err = groupOperation.Wait(ctx); err != nil {
>        return fmt.Errorf("wait for group creation: %w", err)
>    }
>    groupID := groupOperation.ResourceID()
>    groupAccountService := sdk.Services().IAM().V1().
>        ServiceAccount()
>    groupAccount, err := groupAccountService.GetByName(
>        ctx,
>        &iam.GetServiceAccountByNameRequest{
>            Name: "lancedb-sa",
>        },
>    )
>    if err != nil {
>        return fmt.Errorf("get service account: %w", err)
>    }
>    groupAccountID := groupAccount.GetMetadata().GetId()
>    if groupAccountID == "" {
>        return fmt.Errorf("service account ID is missing")
>    }
>    groupMembershipService := sdk.Services().IAM().V1().
>        GroupMembership()
>    groupMembershipOperation, err := groupMembershipService.Create(
>        ctx,
>        &iam.CreateGroupMembershipRequest{
>            Metadata: &common.ResourceMetadata{
>                ParentId: groupID,
>            },
>            Spec: &iam.GroupMembershipSpec{
>                MemberId: groupAccountID,
>            },
>        },
>    )
>    if err != nil {
>        return fmt.Errorf("create group membership: %w", err)
>    }
>    if _, err = groupMembershipOperation.Wait(ctx); err != nil {
>        return fmt.Errorf("wait for group membership: %w", err)
>    }
>    fmt.Println(groupID)
>    ```
>
>    In `Metadata.ParentId` of the group, specify the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-go-sdk). The code prints the ID of the group.
>
> 3. Grant the group read and write access to the bucket with a [bucket policy](https://docs.nebius.com/object-storage/buckets/bucket-policy.md):
>
>    ```go theme={null}
>    policyService := sdk.Services().Storage().V1().Bucket()
>    policyBucket, err := policyService.GetByName(
>        ctx,
>        &storage.GetBucketByNameRequest{
>            Name: "<bucket_name>",
>        },
>    )
>    if err != nil {
>        return fmt.Errorf("get bucket: %w", err)
>    }
>    policyBucket.Spec.BucketPolicy = &storage.BucketPolicy{
>        Rules: []*storage.BucketPolicy_Rule{
>            {
>                Paths: []string{"*"},
>                Roles: []string{"storage.editor"},
>                Subject: &storage.BucketPolicy_Rule_GroupId{
>                    GroupId: "<group_ID>",
>                },
>            },
>        },
>    }
>    policyOperation, err := policyService.Update(
>        ctx,
>        &storage.UpdateBucketRequest{
>            Metadata: policyBucket.Metadata,
>            Spec:     policyBucket.Spec,
>        },
>    )
>    if err != nil {
>        return fmt.Errorf("update bucket: %w", err)
>    }
>    if _, err = policyOperation.Wait(ctx); err != nil {
>        return fmt.Errorf("wait for bucket update: %w", err)
>    }
>    ```
>
>    In the code, specify:
>
>    * `Name`: Name of the [bucket you created](#create-an-object-storage-bucket-go-sdk).
>    * `GroupId`: ID of the group that you created.

> [tab] Python SDK
>
> 1. Create a service account:
>
>    ```python theme={null}
>    account_service = ServiceAccountServiceClient(sdk)
>    account_operation = await account_service.create(
>        CreateServiceAccountRequest(
>            metadata=ResourceMetadata(name="lancedb-sa"),
>            spec=ServiceAccountSpec(),
>        ),
>    )
>    await account_operation.wait()
>    print(account_operation.resource_id)
>    ```
>
> 2. Create a group for the service account in your project and add the service account to the group:
>
>    ```python theme={null}
>    group_service = GroupServiceClient(sdk)
>    group_operation = await group_service.create(
>        CreateGroupRequest(
>            metadata=ResourceMetadata(
>                name="lancedb-access",
>                parent_id="<project_ID>",
>            ),
>        ),
>    )
>    await group_operation.wait()
>    group_id = group_operation.resource_id
>    account_service = ServiceAccountServiceClient(sdk)
>    service_account = await account_service.get_by_name(
>        GetServiceAccountByNameRequest(name="lancedb-sa"),
>    )
>    service_account_id = service_account.metadata.id
>    if not service_account_id:
>        raise RuntimeError("service account ID is missing")
>    membership_service = GroupMembershipServiceClient(sdk)
>    membership_operation = await membership_service.create(
>        CreateGroupMembershipRequest(
>            metadata=ResourceMetadata(parent_id=group_id),
>            spec=GroupMembershipSpec(member_id=service_account_id),
>        ),
>    )
>    await membership_operation.wait()
>    print(group_id)
>    ```
>
>    In `metadata.parent_id` of the group, specify the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-python-sdk). The code prints the ID of the group.
>
> 3. Grant the group read and write access to the bucket with a [bucket policy](https://docs.nebius.com/object-storage/buckets/bucket-policy.md):
>
>    ```python theme={null}
>    policy_service = BucketServiceClient(sdk)
>    policy_bucket = await policy_service.get_by_name(
>        GetBucketByNameRequest(name="<bucket_name>"),
>    )
>    policy_bucket.spec.bucket_policy = BucketPolicy(
>        rules=[
>            BucketPolicy__Rule(
>                paths=["*"],
>                roles=["storage.editor"],
>                group_id="<group_ID>",
>            ),
>        ],
>    )
>    policy_operation = await policy_service.update(
>        UpdateBucketRequest(
>            metadata=policy_bucket.metadata,
>            spec=policy_bucket.spec,
>        ),
>    )
>    await policy_operation.wait()
>    ```
>
>    In the code, specify:
>
>    * `name`: Name of the [bucket you created](#create-an-object-storage-bucket-python-sdk).
>    * `group_id`: ID of the group that you created.

> [tab] JavaScript SDK
>
> 1. Create a service account:
>
>    ```ts theme={null}
>    const accountService = new ServiceAccountService(sdk);
>    const accountOperation = await accountService.create(
>      CreateServiceAccountRequest.create({
>        metadata: ResourceMetadata.create({
>          name: "lancedb-sa",
>        }),
>        spec: ServiceAccountSpec.create({}),
>      }),
>    ).result;
>    await accountOperation.wait();
>    console.log(accountOperation.resourceId());
>    ```
>
> 2. Create a group for the service account in your project and add the service account to the group:
>
>    ```ts theme={null}
>    const groupService = new GroupService(sdk);
>    const groupOperation = await groupService.create(
>      CreateGroupRequest.create({
>        metadata: ResourceMetadata.create({
>          name: "lancedb-access",
>          parentId: "<project_ID>",
>        }),
>      }),
>    ).result;
>    await groupOperation.wait();
>    const groupId = groupOperation.resourceId();
>    const groupAccountService = new ServiceAccountService(sdk);
>    const groupAccount = await groupAccountService.getByName(
>      GetServiceAccountByNameRequest.create({
>        name: "lancedb-sa",
>      }),
>    ).result;
>    const groupAccountId = groupAccount.metadata?.id;
>    if (!groupAccountId) {
>      throw new Error("service account ID is missing");
>    }
>    const groupMembershipService =
>      new GroupMembershipService(sdk);
>    const groupMembershipOperation =
>      await groupMembershipService.create(
>        CreateGroupMembershipRequest.create({
>          metadata: ResourceMetadata.create({
>            parentId: groupId,
>          }),
>          spec: GroupMembershipSpec.create({
>            memberId: groupAccountId,
>          }),
>        }),
>      ).result;
>    await groupMembershipOperation.wait();
>    console.log(groupId);
>    ```
>
>    In `metadata.parentId` of the group, specify the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-javascript-sdk). The code prints the ID of the group.
>
> 3. Grant the group read and write access to the bucket with a [bucket policy](https://docs.nebius.com/object-storage/buckets/bucket-policy.md):
>
>    ```ts theme={null}
>    const policyService = new BucketService(sdk);
>    const policyBucket = await policyService.getByName(
>      GetBucketByNameRequest.create({
>        name: "<bucket_name>",
>      }),
>    ).result;
>    policyBucket.spec.bucketPolicy = BucketPolicy.create({
>      rules: [
>        BucketPolicy_Rule.create({
>          paths: ["*"],
>          roles: ["storage.editor"],
>          subject: {
>            $case: "groupId",
>            groupId: "<group_ID>",
>          },
>        }),
>      ],
>    });
>    const policyOperation = await policyService.update(
>      UpdateBucketRequest.create({
>        metadata: policyBucket.metadata,
>        spec: policyBucket.spec,
>      }),
>    ).result;
>    await policyOperation.wait();
>    ```
>
>    In the code, specify:
>
>    * `name`: Name of the [bucket you created](#create-an-object-storage-bucket-javascript-sdk).
>    * `groupId`: ID of the group that you created.

The `storage.editor` role lets the service account read and write objects in the bucket.

### Create an access key

LanceDB authenticates in Object Storage with an [access key](https://docs.nebius.com/iam/service-accounts/access-keys.md) of the service account. Create an access key for the `lancedb-sa` service account that you created:

> [tab] Web console
>
> 1. In the sidebar, go to  **Administration** → **IAM**.
> 2. On the **Service accounts** tab, open the `lancedb-sa` service account.
> 3. On the **Keys** tab, click **Create access key**.
> 4. Copy the key ID and the secret key and save them in a secure place. The web console shows the secret key only once.

> [tab] CLI
>
> ```bash theme={null}
> export ACCESS_KEY_ID=$(nebius iam v2 access-key create \
>   --account-service-account-id $SA_ID \
>   --description 'LanceDB' \
>   --format jsonpath='{.metadata.id}')
> export AWS_ACCESS_KEY_ID=$(nebius iam v2 access-key get \
>   --id $ACCESS_KEY_ID \
>   --format jsonpath='{.status.aws_access_key_id}')
> export AWS_SECRET_ACCESS_KEY=$(nebius iam v2 access-key get \
>   --id $ACCESS_KEY_ID \
>   --format jsonpath='{.status.secret}')
> ```
>
> The commands save the key ID to the `AWS_ACCESS_KEY_ID` environment variable and the secret key to `AWS_SECRET_ACCESS_KEY`. To see a value, run `echo` with the variable; for example, `echo $AWS_ACCESS_KEY_ID`.

> [tab] Terraform
>
> 1. Add the following configuration for the access key:
>
>    ```hcl theme={null}
>    resource "nebius_iam_v2_access_key" "lancedb_key" {
>      parent_id            = "<project_ID>"
>      description          = "LanceDB"
>      secret_delivery_mode = "MYSTERY_BOX"
>      account = {
>        service_account = {
>          id = nebius_iam_v1_service_account.lancedb_sa.id
>        }
>      }
>    }
>
>    output "lancedb_access_key_id" {
>      value = nebius_iam_v2_access_key.lancedb_key.status.aws_access_key_id
>    }
>
>    output "lancedb_secret_id" {
>      value = nebius_iam_v2_access_key.lancedb_key.status.secret_reference_id
>    }
>    ```
>
>    The file contains the following parameters:
>
>    * `parent_id`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-terraform).
>    * `secret_delivery_mode`: How you receive the secret key. With `MYSTERY_BOX`, Nebius AI Cloud saves the secret key to a [SecretStash](https://docs.nebius.com/mysterybox/overview.md) secret instead of returning it to Terraform.
>
>    The outputs return the key ID and the ID of the SecretStash secret.
>
> 2. Check that the configuration is correct:
>    ```bash theme={null}
>    terraform validate
>    ```
>
> 3. Apply the changes:
>    ```bash theme={null}
>    terraform apply
>    ```
>
> 4. Save the key ID and the secret key to environment variables:
>
>    ```bash theme={null}
>    export AWS_ACCESS_KEY_ID=$(terraform output -raw lancedb_access_key_id)
>    export AWS_SECRET_ACCESS_KEY=$(nebius mysterybox payload get \
>      --secret-id $(terraform output -raw lancedb_secret_id) \
>      --format jsonpath='{.data[0].string_value}')
>    ```
>
>    The commands get the key ID from the Terraform output and the secret key from [SecretStash](https://docs.nebius.com/mysterybox/overview.md) with the Nebius AI Cloud CLI.

> [tab] Go SDK
>
> ```go theme={null}
> accessAccountService := sdk.Services().IAM().V1().
>     ServiceAccount()
> accessAccount, err := accessAccountService.GetByName(
>     ctx,
>     &iam.GetServiceAccountByNameRequest{
>         Name: "lancedb-sa",
>     },
> )
> if err != nil {
>     return fmt.Errorf("get service account: %w", err)
> }
> accessAccountID := accessAccount.GetMetadata().GetId()
> if accessAccountID == "" {
>     return fmt.Errorf("service account ID is missing")
> }
> accessKeyAccount := &iam.Account{
>     Type: &iam.Account_ServiceAccount_{
>         ServiceAccount: &iam.Account_ServiceAccount{
>             Id: accessAccountID,
>         },
>     },
> }
> accessKeyService := sdk.Services().IAM().V2().AccessKey()
> accessKeyOperation, err := accessKeyService.Create(
>     ctx,
>     &iamv2.CreateAccessKeyRequest{
>         Spec: &iamv2.AccessKeySpec{
>             Account:     accessKeyAccount,
>             Description: "LanceDB",
>             SecretDeliveryMode: iamv2.
>                 SecretDeliveryMode_INLINE,
>         },
>     },
> )
> if err != nil {
>     return fmt.Errorf("create access key: %w", err)
> }
> if _, err = accessKeyOperation.Wait(ctx); err != nil {
>     return fmt.Errorf("wait for access key: %w", err)
> }
> accessKeyID := accessKeyOperation.ResourceID()
> accessKey, err := accessKeyService.Get(
>     ctx,
>     &iamv2.GetAccessKeyRequest{Id: accessKeyID},
> )
> if err != nil {
>     return fmt.Errorf("get access key: %w", err)
> }
> awsAccessKeyID := accessKey.GetStatus().GetAwsAccessKeyId()
> if awsAccessKeyID == "" {
>     return fmt.Errorf("AWS access key ID is missing")
> }
> accessKeySecret, err := accessKeyService.GetSecret(
>     ctx,
>     &iamv2.GetAccessKeySecretRequest{Id: accessKeyID},
> )
> if err != nil {
>     return fmt.Errorf("get access key secret: %w", err)
> }
> secretAccessKey := accessKeySecret.GetSecret()
> if secretAccessKey == "" {
>     return fmt.Errorf("secret access key is missing")
> }
> fmt.Println(awsAccessKeyID)
> fmt.Println(secretAccessKey)
> ```
>
> The code prints the key ID and then the secret key.

> [tab] Python SDK
>
> ```python theme={null}
> account_service = ServiceAccountServiceClient(sdk)
> service_account = await account_service.get_by_name(
>     GetServiceAccountByNameRequest(name="lancedb-sa"),
> )
> service_account_id = service_account.metadata.id
> if not service_account_id:
>     raise RuntimeError("service account ID is missing")
> access_key_service = AccessKeyServiceClient(sdk)
> access_key_operation = await access_key_service.create(
>     CreateAccessKeyRequest(
>         spec=AccessKeySpec(
>             account=Account(
>                 service_account=Account__ServiceAccount(
>                     id=service_account_id,
>                 ),
>             ),
>             description="LanceDB",
>             secret_delivery_mode=SecretDeliveryMode.INLINE,
>         ),
>     ),
> )
> await access_key_operation.wait()
> access_key_id = access_key_operation.resource_id
> access_key = await access_key_service.get(
>     GetAccessKeyRequest(id=access_key_id),
> )
> aws_access_key_id = access_key.status.aws_access_key_id
> if not aws_access_key_id:
>     raise RuntimeError("AWS access key ID is missing")
> access_key_secret = await access_key_service.get_secret(
>     GetAccessKeySecretRequest(id=access_key_id),
> )
> secret_access_key = access_key_secret.secret
> if not secret_access_key:
>     raise RuntimeError("secret access key is missing")
> print(aws_access_key_id)
> print(secret_access_key)
> ```
>
> The code prints the key ID and then the secret key.

> [tab] JavaScript SDK
>
> ```ts theme={null}
> const accessAccountService = new ServiceAccountService(sdk);
> const accessAccount = await accessAccountService.getByName(
>   GetServiceAccountByNameRequest.create({
>     name: "lancedb-sa",
>   }),
> ).result;
> const accessAccountId = accessAccount.metadata?.id;
> if (!accessAccountId) {
>   throw new Error("service account ID is missing");
> }
> const accessKeyService = new AccessKeyService(sdk);
> const accessKeyOperation = await accessKeyService.create(
>   CreateAccessKeyRequest.create({
>     spec: AccessKeySpec.create({
>       account: Account.create({
>         type: {
>           $case: "serviceAccount",
>           serviceAccount: Account_ServiceAccount.create({
>             id: accessAccountId,
>           }),
>         },
>       }),
>       description: "LanceDB",
>       secretDeliveryMode: SecretDeliveryMode.INLINE,
>     }),
>   }),
> ).result;
> await accessKeyOperation.wait();
> const accessKeyId = accessKeyOperation.resourceId();
> const accessKey = await accessKeyService.get(
>   GetAccessKeyRequest.create({ id: accessKeyId }),
> ).result;
> const awsAccessKeyId = accessKey.status?.awsAccessKeyId;
> if (!awsAccessKeyId) {
>   throw new Error("AWS access key ID is missing");
> }
> const accessKeySecret = await accessKeyService.getSecret(
>   GetAccessKeySecretRequest.create({ id: accessKeyId }),
> ).result;
> const secretAccessKey = accessKeySecret.secret;
> if (!secretAccessKey) {
>   throw new Error("secret access key is missing");
> }
> console.log(awsAccessKeyId);
> console.log(secretAccessKey);
> ```
>
> The code prints the key ID and then the secret key.

### Install LanceDB

Install the LanceDB client for the language that you use:

```bash Python theme={null}
pip install lancedb pandas
```

```bash TypeScript theme={null}
npm install @lancedb/lancedb
```

### Set environment variables

LanceDB reads the access key, the region, and the Object Storage endpoint from environment variables. In the terminal where you run the LanceDB code, set the variables:

```bash theme={null}
export AWS_ACCESS_KEY_ID=<access_key_ID>
export AWS_SECRET_ACCESS_KEY=<secret_access_key>
export AWS_DEFAULT_REGION=<region_ID>
export AWS_ENDPOINT=https://storage.<region_ID>.nebius.cloud
```

The variables contain the following values:

* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`: Key ID and secret key of the access key that you created. If you created the access key by using the CLI or Terraform in the same terminal, both variables are already set.
* `AWS_DEFAULT_REGION`: The [region](https://docs.nebius.com/overview/regions.md) of your project; for example, `eu-north1`.
* `AWS_ENDPOINT`: Object Storage endpoint in the same region.

If you run the LanceDB code in a Jupyter notebook, such as a notebook in a [JupyterLab Devlab](https://docs.nebius.com/serverless/quickstart/devlabs.md), set the variables in a notebook cell with `%env` instead of `export`; for example, `%env AWS_DEFAULT_REGION=<region_ID>`.

### Connect LanceDB to Object Storage

Open a script or a Jupyter notebook and connect LanceDB to your bucket. In the code, replace `<bucket_name>` with the name of the bucket that you created:

```python Python theme={null}
import lancedb

db = lancedb.connect("s3://<bucket_name>/lancedb")
```

```typescript TypeScript theme={null}
import * as lancedb from "@lancedb/lancedb";

const db = await lancedb.connect("s3://<bucket_name>/lancedb");
```

LanceDB takes the connection settings from the environment variables. To set them in the code instead, see [LanceDB storage configuration](https://docs.lancedb.com/storage/configuration).

### Create a table and insert vectors

Create a table with a vector column and a metadata column, then insert a few rows. This tutorial uses random vectors to keep the example self-contained.

> [!TIP]
>
> In a real application, you would generate embeddings by using a model deployed in [Serverless AI](https://docs.nebius.com/serverless/overview.md) or a model that runs locally with [SentenceTransformers](https://sbert.net). For a Serverless AI example, see the tutorial on [Building a RAG electronics store chatbot](https://docs.nebius.com/tutorials/rag.md).

```python Python theme={null}
import numpy as np

data = [
    {"id": 1, "text": "Nebius Object Storage", "vector": np.random.rand(128).tolist()},
    {"id": 2, "text": "LanceDB vector database", "vector": np.random.rand(128).tolist()},
    {"id": 3, "text": "Serverless AI embeddings", "vector": np.random.rand(128).tolist()},
]

table = db.create_table("documents", data=data)
print(f"Table created with {table.count_rows()} rows.")
```

```typescript TypeScript theme={null}
const data = [
  { id: 1, text: "Nebius Object Storage", vector: Array.from({ length: 128 }, Math.random) },
  { id: 2, text: "LanceDB vector database", vector: Array.from({ length: 128 }, Math.random) },
  { id: 3, text: "Serverless AI embeddings", vector: Array.from({ length: 128 }, Math.random) },
];

const table = await db.createTable("documents", data);
console.log(`Table created with ${await table.countRows()} rows.`);
```

LanceDB writes the table as Lance files under `s3://<bucket_name>/lancedb/documents.lance/`. You can verify this in the [web console](https://console.nebius.com): go to  **Storage** → **Object Storage** and open your bucket.

### Run a similarity search

Query the table for the rows nearest to a query vector:

```python Python theme={null}
query_vector = np.random.rand(128).tolist()

results = (
    table.search(query_vector)
         .limit(2)
         .select(["id", "text", "_distance"])
         .to_pandas()
)
print(results)
```

```typescript TypeScript theme={null}
const queryVector = Array.from({ length: 128 }, Math.random);

const results = await table
  .search(queryVector)
  .limit(2)
  .select(["id", "text", "_distance"])
  .toArray();

console.log(results);
```

The output shows the two nearest rows along with their `_distance` scores. Because the data in this example is random, the distances have no semantic meaning — in a real application, vectors would come from an embedding model and low distances would indicate semantic similarity.

### Reconnect to an existing table

LanceDB tables persist in Object Storage. To reopen a table in a later session, set the environment variables again, connect to the bucket, and open the table by its name:

```python Python theme={null}
import lancedb

db = lancedb.connect("s3://<bucket_name>/lancedb")
table = db.open_table("documents")
print(table.count_rows())
```

```typescript TypeScript theme={null}
import * as lancedb from "@lancedb/lancedb";

const db = await lancedb.connect("s3://<bucket_name>/lancedb");
const table = await db.openTable("documents");
console.log(await table.countRows());
```

## How to delete the created resources

The bucket is a chargeable resource. If you no longer need the data, [delete the bucket](https://docs.nebius.com/object-storage/buckets/manage.md#how-to-delete-buckets), so Nebius AI Cloud doesn't charge for it.

## See also

* [LanceDB storage configuration](https://docs.lancedb.com/storage/configuration)
* [About Object Storage](https://docs.nebius.com/object-storage/overview.md)
* [Compatibility of Amazon S3 API with Object Storage](https://docs.nebius.com/object-storage/interfaces/s3-api-compatibility.md)
* [Serverless AI](https://docs.nebius.com/serverless/overview.md)

***

*"Jupyter" and the Jupyter logos are trademarks or registered trademarks of LF Charities, used by Nebius B.V. with permission.*
