Elffuss BraidHub

kikocis/lancedb public

main · 24.9 KiBRenderedRawPermalink
1# Configuring cloud storage
2
3<!-- TODO: When we add documentation for how to configure other storage types
4 we can change the name to a more general "Configuring storage" -->
5
6When using LanceDB OSS, you can choose where to store your data. The tradeoffs between different storage options are discussed in the [storage concepts guide](../concepts/storage.md). This guide shows how to configure LanceDB to use different storage options.
7
8## Object Stores
9
10LanceDB OSS supports object stores such as AWS S3 (and compatible stores), Azure Blob Store, and Google Cloud Storage. Which object store to use is determined by the URI scheme of the dataset path. `s3://` is used for AWS S3, `az://` is used for Azure Blob Storage, and `gs://` is used for Google Cloud Storage. These URIs are passed to the `connect` function:
11
12=== "Python"
13
14 AWS S3:
15
16 ```python
17 import lancedb
18 db = lancedb.connect("s3://bucket/path")
19 ```
20
21 Google Cloud Storage:
22
23 ```python
24 import lancedb
25 db = lancedb.connect("gs://bucket/path")
26 ```
27
28 Azure Blob Storage:
29
30 ```python
31 import lancedb
32 db = lancedb.connect("az://bucket/path")
33 ```
34
35=== "TypeScript"
36
37 === "@lancedb/lancedb"
38
39 AWS S3:
40
41 ```ts
42 import * as lancedb from "@lancedb/lancedb";
43 const db = await lancedb.connect("s3://bucket/path");
44 ```
45
46 Google Cloud Storage:
47
48 ```ts
49 import * as lancedb from "@lancedb/lancedb";
50 const db = await lancedb.connect("gs://bucket/path");
51 ```
52
53 Azure Blob Storage:
54
55 ```ts
56 import * as lancedb from "@lancedb/lancedb";
57 const db = await lancedb.connect("az://bucket/path");
58 ```
59
60
61 === "vectordb (deprecated)"
62
63 AWS S3:
64
65 ```ts
66 const lancedb = require("lancedb");
67 const db = await lancedb.connect("s3://bucket/path");
68 ```
69
70 Google Cloud Storage:
71
72 ```ts
73 const lancedb = require("lancedb");
74 const db = await lancedb.connect("gs://bucket/path");
75 ```
76
77 Azure Blob Storage:
78
79 ```ts
80 const lancedb = require("lancedb");
81 const db = await lancedb.connect("az://bucket/path");
82 ```
83
84In most cases, when running in the respective cloud and permissions are set up correctly, no additional configuration is required. When running outside of the respective cloud, authentication credentials must be provided. Credentials and other configuration options can be set in two ways: first, by setting environment variables. And second, by passing a `storage_options` object to the `connect` function. For example, to increase the request timeout to 60 seconds, you can set the `TIMEOUT` environment variable to `60s`:
85
86```bash
87export TIMEOUT=60s
88```
89
90!!! note "`storage_options` availability"
91
92 The `storage_options` parameter is only available in Python *async* API and JavaScript API.
93 It is not yet supported in the Python synchronous API.
94
95If you only want this to apply to one particular connection, you can pass the `storage_options` argument when opening the connection:
96
97=== "Python"
98
99 ```python
100 import lancedb
101 db = await lancedb.connect_async(
102 "s3://bucket/path",
103 storage_options={"timeout": "60s"}
104 )
105 ```
106
107=== "TypeScript"
108
109 === "@lancedb/lancedb"
110
111 ```ts
112 import * as lancedb from "@lancedb/lancedb";
113
114 const db = await lancedb.connect("s3://bucket/path", {
115 storageOptions: {timeout: "60s"}
116 });
117 ```
118
119 === "vectordb (deprecated)"
120
121 ```ts
122 const lancedb = require("lancedb");
123 const db = await lancedb.connect("s3://bucket/path", {
124 storageOptions: {timeout: "60s"}
125 });
126 ```
127
128Getting even more specific, you can set the `timeout` for only a particular table:
129
130=== "Python"
131
132 <!-- skip-test -->
133 ```python
134 import lancedb
135 db = await lancedb.connect_async("s3://bucket/path")
136 table = await db.create_table(
137 "table",
138 [{"a": 1, "b": 2}],
139 storage_options={"timeout": "60s"}
140 )
141 ```
142
143=== "TypeScript"
144
145 === "@lancedb/lancedb"
146
147 <!-- skip-test -->
148 ```ts
149 import * as lancedb from "@lancedb/lancedb";
150 const db = await lancedb.connect("s3://bucket/path");
151 const table = db.createTable(
152 "table",
153 [{ a: 1, b: 2}],
154 {storageOptions: {timeout: "60s"}}
155 );
156 ```
157
158 === "vectordb (deprecated)"
159
160 <!-- skip-test -->
161 ```ts
162 const lancedb = require("lancedb");
163 const db = await lancedb.connect("s3://bucket/path");
164 const table = db.createTable(
165 "table",
166 [{ a: 1, b: 2}],
167 {storageOptions: {timeout: "60s"}}
168 );
169 ```
170
171!!! info "Storage option casing"
172
173 The storage option keys are case-insensitive. So `connect_timeout` and `CONNECT_TIMEOUT` are the same setting. Usually lowercase is used in the `storage_options` argument and uppercase is used for environment variables. In the `lancedb` Node package, the keys can also be provided in `camelCase` capitalization. For example, `connectTimeout` is equivalent to `connect_timeout`.
174
175### General configuration
176
177There are several options that can be set for all object stores, mostly related to network client configuration.
178
179<!-- from here: https://docs.rs/object_store/latest/object_store/enum.ClientConfigKey.html -->
180
181| Key | Description |
182|----------------------------|--------------------------------------------------------------------------------------------------|
183| `allow_http` | Allow non-TLS, i.e. non-HTTPS connections. Default: `False`. |
184| `allow_invalid_certificates`| Skip certificate validation on HTTPS connections. Default: `False`. |
185| `connect_timeout` | Timeout for only the connect phase of a Client. Default: `5s`. |
186| `timeout` | Timeout for the entire request, from connection until the response body has finished. Default: `30s`. |
187| `user_agent` | User agent string to use in requests. |
188| `proxy_url` | URL of a proxy server to use for requests. Default: `None`. |
189| `proxy_ca_certificate` | PEM-formatted CA certificate for proxy connections. |
190| `proxy_excludes` | List of hosts that bypass the proxy. This is a comma-separated list of domains and IP masks. Any subdomain of the provided domain will be bypassed. For example, `example.com, 192.168.1.0/24` would bypass `https://api.example.com`, `https://www.example.com`, and any IP in the range `192.168.1.0/24`. |
191
192### AWS S3
193
194To configure credentials for AWS S3, you can use the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN` keys. Region can also be set, but it is not mandatory when using AWS.
195These can be set as environment variables or passed in the `storage_options` parameter:
196
197=== "Python"
198
199 ```python
200 import lancedb
201 db = await lancedb.connect_async(
202 "s3://bucket/path",
203 storage_options={
204 "aws_access_key_id": "my-access-key",
205 "aws_secret_access_key": "my-secret-key",
206 "aws_session_token": "my-session-token",
207 }
208 )
209 ```
210
211=== "TypeScript"
212
213 === "@lancedb/lancedb"
214
215 ```ts
216 import * as lancedb from "@lancedb/lancedb";
217 const db = await lancedb.connect(
218 "s3://bucket/path",
219 {
220 storageOptions: {
221 awsAccessKeyId: "my-access-key",
222 awsSecretAccessKey: "my-secret-key",
223 awsSessionToken: "my-session-token",
224 }
225 }
226 );
227 ```
228
229 === "vectordb (deprecated)"
230
231 ```ts
232 const lancedb = require("lancedb");
233 const db = await lancedb.connect(
234 "s3://bucket/path",
235 {
236 storageOptions: {
237 awsAccessKeyId: "my-access-key",
238 awsSecretAccessKey: "my-secret-key",
239 awsSessionToken: "my-session-token",
240 }
241 }
242 );
243 ```
244
245Alternatively, if you are using AWS SSO, you can use the `AWS_PROFILE` and `AWS_DEFAULT_REGION` environment variables.
246
247The following keys can be used as both environment variables or keys in the `storage_options` parameter:
248
249| Key | Description |
250|------------------------------------|------------------------------------------------------------------------------------------------------|
251| `aws_region` / `region` | The AWS region the bucket is in. This can be automatically detected when using AWS S3, but must be specified for S3-compatible stores. |
252| `aws_access_key_id` / `access_key_id` | The AWS access key ID to use. |
253| `aws_secret_access_key` / `secret_access_key` | The AWS secret access key to use. |
254| `aws_session_token` / `session_token` | The AWS session token to use. |
255| `aws_endpoint` / `endpoint` | The endpoint to use for S3-compatible stores. |
256| `aws_virtual_hosted_style_request` / `virtual_hosted_style_request` | Whether to use virtual hosted-style requests, where the bucket name is part of the endpoint. Meant to be used with `aws_endpoint`. Default: `False`. |
257| `aws_s3_express` / `s3_express` | Whether to use S3 Express One Zone endpoints. Default: `False`. See more details below. |
258| `aws_server_side_encryption` | The server-side encryption algorithm to use. Must be one of `"AES256"`, `"aws:kms"`, or `"aws:kms:dsse"`. Default: `None`. |
259| `aws_sse_kms_key_id` | The KMS key ID to use for server-side encryption. If set, `aws_server_side_encryption` must be `"aws:kms"` or `"aws:kms:dsse"`. |
260| `aws_sse_bucket_key_enabled` | Whether to use bucket keys for server-side encryption. |
261
262!!! tip "Automatic cleanup for failed writes"
263
264 LanceDB uses [multi-part uploads](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html) when writing data to S3 in order to maximize write speed. LanceDB will abort these uploads when it shuts down gracefully, such as when cancelled by keyboard interrupt. However, in the rare case that LanceDB crashes, it is possible that some data will be left lingering in your account. To cleanup this data, we recommend (as AWS themselves do) that you setup a lifecycle rule to delete in-progress uploads after 7 days. See the AWS guide:
265
266 **[Configuring a bucket lifecycle configuration to delete incomplete multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html)**
267
268#### AWS IAM Permissions
269
270If a bucket is private, then an IAM policy must be specified to allow access to it. For many development scenarios, using broad permissions such as a PowerUser account is more than sufficient for working with LanceDB. However, in many production scenarios, you may wish to have as narrow as possible permissions.
271
272For **read and write access**, LanceDB will need a policy such as:
273
274```json
275{
276 "Version": "2012-10-17",
277 "Statement": [
278 {
279 "Effect": "Allow",
280 "Action": [
281 "s3:PutObject",
282 "s3:GetObject",
283 "s3:DeleteObject",
284 ],
285 "Resource": "arn:aws:s3:::<bucket>/<prefix>/*"
286 },
287 {
288 "Effect": "Allow",
289 "Action": [
290 "s3:ListBucket",
291 "s3:GetBucketLocation"
292 ],
293 "Resource": "arn:aws:s3:::<bucket>",
294 "Condition": {
295 "StringLike": {
296 "s3:prefix": [
297 "<prefix>/*"
298 ]
299 }
300 }
301 }
302 ]
303}
304```
305
306For **read-only access**, LanceDB will need a policy such as:
307
308```json
309{
310 "Version": "2012-10-17",
311 "Statement": [
312 {
313 "Effect": "Allow",
314 "Action": [
315 "s3:GetObject",
316 ],
317 "Resource": "arn:aws:s3:::<bucket>/<prefix>/*"
318 },
319 {
320 "Effect": "Allow",
321 "Action": [
322 "s3:ListBucket",
323 "s3:GetBucketLocation"
324 ],
325 "Resource": "arn:aws:s3:::<bucket>",
326 "Condition": {
327 "StringLike": {
328 "s3:prefix": [
329 "<prefix>/*"
330 ]
331 }
332 }
333 }
334 ]
335}
336```
337
338#### DynamoDB Commit Store for concurrent writes
339
340By default, S3 does not support concurrent writes. Having two or more processes
341writing to the same table at the same time can lead to data corruption. This is
342because S3, unlike other object stores, does not have any atomic put or copy
343operation.
344
345To enable concurrent writes, you can configure LanceDB to use a DynamoDB table
346as a commit store. This table will be used to coordinate writes between
347different processes. To enable this feature, you must modify your connection
348URI to use the `s3+ddb` scheme and add a query parameter `ddbTableName` with the
349name of the table to use.
350
351=== "Python"
352
353 ```python
354 import lancedb
355 db = await lancedb.connect_async(
356 "s3+ddb://bucket/path?ddbTableName=my-dynamodb-table",
357 )
358 ```
359
360=== "JavaScript"
361
362 ```javascript
363 const lancedb = require("lancedb");
364
365 const db = await lancedb.connect(
366 "s3+ddb://bucket/path?ddbTableName=my-dynamodb-table",
367 );
368 ```
369
370The DynamoDB table must be created with the following schema:
371
372- Hash key: `base_uri` (string)
373- Range key: `version` (number)
374
375You can create this programmatically with:
376
377=== "Python"
378
379 <!-- skip-test -->
380 ```python
381 import boto3
382
383 dynamodb = boto3.client("dynamodb")
384 table = dynamodb.create_table(
385 TableName=table_name,
386 KeySchema=[
387 {"AttributeName": "base_uri", "KeyType": "HASH"},
388 {"AttributeName": "version", "KeyType": "RANGE"},
389 ],
390 AttributeDefinitions=[
391 {"AttributeName": "base_uri", "AttributeType": "S"},
392 {"AttributeName": "version", "AttributeType": "N"},
393 ],
394 ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
395 )
396 ```
397
398=== "JavaScript"
399
400 <!-- skip-test -->
401 ```javascript
402 import {
403 CreateTableCommand,
404 DynamoDBClient,
405 } from "@aws-sdk/client-dynamodb";
406
407 const dynamodb = new DynamoDBClient({
408 region: CONFIG.awsRegion,
409 credentials: {
410 accessKeyId: CONFIG.awsAccessKeyId,
411 secretAccessKey: CONFIG.awsSecretAccessKey,
412 },
413 endpoint: CONFIG.awsEndpoint,
414 });
415 const command = new CreateTableCommand({
416 TableName: table_name,
417 AttributeDefinitions: [
418 {
419 AttributeName: "base_uri",
420 AttributeType: "S",
421 },
422 {
423 AttributeName: "version",
424 AttributeType: "N",
425 },
426 ],
427 KeySchema: [
428 { AttributeName: "base_uri", KeyType: "HASH" },
429 { AttributeName: "version", KeyType: "RANGE" },
430 ],
431 ProvisionedThroughput: {
432 ReadCapacityUnits: 1,
433 WriteCapacityUnits: 1,
434 },
435 });
436 await client.send(command);
437 ```
438
439
440#### S3-compatible stores
441
442LanceDB can also connect to S3-compatible stores, such as MinIO. To do so, you must specify both region and endpoint:
443
444=== "Python"
445
446 ```python
447 import lancedb
448 db = await lancedb.connect_async(
449 "s3://bucket/path",
450 storage_options={
451 "region": "us-east-1",
452 "endpoint": "http://minio:9000",
453 }
454 )
455 ```
456
457=== "TypeScript"
458
459 === "@lancedb/lancedb"
460
461 ```ts
462 import * as lancedb from "@lancedb/lancedb";
463 const db = await lancedb.connect(
464 "s3://bucket/path",
465 {
466 storageOptions: {
467 region: "us-east-1",
468 endpoint: "http://minio:9000",
469 }
470 }
471 );
472 ```
473
474 === "vectordb (deprecated)"
475
476 ```ts
477 const lancedb = require("lancedb");
478 const db = await lancedb.connect(
479 "s3://bucket/path",
480 {
481 storageOptions: {
482 region: "us-east-1",
483 endpoint: "http://minio:9000",
484 }
485 }
486 );
487 ```
488
489This can also be done with the ``AWS_ENDPOINT`` and ``AWS_DEFAULT_REGION`` environment variables.
490
491!!! tip "Local servers"
492
493 For local development, the server often has a `http` endpoint rather than a
494 secure `https` endpoint. In this case, you must also set the `ALLOW_HTTP`
495 environment variable to `true` to allow non-TLS connections, or pass the
496 storage option `allow_http` as `true`. If you do not do this, you will get
497 an error like `URL scheme is not allowed`.
498
499#### S3 Express
500
501LanceDB supports [S3 Express One Zone](https://aws.amazon.com/s3/storage-classes/express-one-zone/) endpoints, but requires additional infrastructure configuration for the compute service, such as EC2 or Lambda. Please refer to [Networking requirements for S3 Express One Zone](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-networking.html).
502
503To configure LanceDB to use an S3 Express endpoint, you must set the storage option `s3_express`. The bucket name in your table URI should **include the suffix**.
504
505=== "Python"
506
507 ```python
508 import lancedb
509 db = await lancedb.connect_async(
510 "s3://my-bucket--use1-az4--x-s3/path",
511 storage_options={
512 "region": "us-east-1",
513 "s3_express": "true",
514 }
515 )
516 ```
517
518=== "TypeScript"
519
520 === "@lancedb/lancedb"
521
522 ```ts
523 import * as lancedb from "@lancedb/lancedb";
524 const db = await lancedb.connect(
525 "s3://my-bucket--use1-az4--x-s3/path",
526 {
527 storageOptions: {
528 region: "us-east-1",
529 s3Express: "true",
530 }
531 }
532 );
533 ```
534
535 === "vectordb (deprecated)"
536
537 ```ts
538 const lancedb = require("lancedb");
539 const db = await lancedb.connect(
540 "s3://my-bucket--use1-az4--x-s3/path",
541 {
542 storageOptions: {
543 region: "us-east-1",
544 s3Express: "true",
545 }
546 }
547 );
548 ```
549
550### Google Cloud Storage
551
552GCS credentials are configured by setting the `GOOGLE_SERVICE_ACCOUNT` environment variable to the path of a JSON file containing the service account credentials. Alternatively, you can pass the path to the JSON file in the `storage_options`:
553
554=== "Python"
555
556 <!-- skip-test -->
557 ```python
558 import lancedb
559 db = await lancedb.connect_async(
560 "gs://my-bucket/my-database",
561 storage_options={
562 "service_account": "path/to/service-account.json",
563 }
564 )
565 ```
566
567=== "TypeScript"
568
569 === "@lancedb/lancedb"
570
571 ```ts
572 import * as lancedb from "@lancedb/lancedb";
573 const db = await lancedb.connect(
574 "gs://my-bucket/my-database",
575 {
576 storageOptions: {
577 serviceAccount: "path/to/service-account.json",
578 }
579 }
580 );
581 ```
582
583 === "vectordb (deprecated)"
584
585 ```ts
586 const lancedb = require("lancedb");
587 const db = await lancedb.connect(
588 "gs://my-bucket/my-database",
589 {
590 storageOptions: {
591 serviceAccount: "path/to/service-account.json",
592 }
593 }
594 );
595 ```
596
597!!! info "HTTP/2 support"
598
599 By default, GCS uses HTTP/1 for communication, as opposed to HTTP/2. This improves maximum throughput significantly. However, if you wish to use HTTP/2 for some reason, you can set the environment variable `HTTP1_ONLY` to `false`.
600
601The following keys can be used as both environment variables or keys in the `storage_options` parameter:
602<!-- source: https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html -->
603
604| Key | Description |
605|---------------------------------------|----------------------------------------------|
606| ``google_service_account`` / `service_account` | Path to the service account JSON file. |
607| ``google_service_account_key`` | The serialized service account key. |
608| ``google_application_credentials`` | Path to the application credentials. |
609
610### Azure Blob Storage
611
612Azure Blob Storage credentials can be configured by setting the `AZURE_STORAGE_ACCOUNT_NAME`and `AZURE_STORAGE_ACCOUNT_KEY` environment variables. Alternatively, you can pass the account name and key in the `storage_options` parameter:
613
614=== "Python"
615
616 <!-- skip-test -->
617 ```python
618 import lancedb
619 db = await lancedb.connect_async(
620 "az://my-container/my-database",
621 storage_options={
622 account_name: "some-account",
623 account_key: "some-key",
624 }
625 )
626 ```
627
628=== "TypeScript"
629
630 === "@lancedb/lancedb"
631
632 ```ts
633 import * as lancedb from "@lancedb/lancedb";
634 const db = await lancedb.connect(
635 "az://my-container/my-database",
636 {
637 storageOptions: {
638 accountName: "some-account",
639 accountKey: "some-key",
640 }
641 }
642 );
643 ```
644
645 === "vectordb (deprecated)"
646
647 ```ts
648 const lancedb = require("lancedb");
649 const db = await lancedb.connect(
650 "az://my-container/my-database",
651 {
652 storageOptions: {
653 accountName: "some-account",
654 accountKey: "some-key",
655 }
656 }
657 );
658 ```
659
660These keys can be used as both environment variables or keys in the `storage_options` parameter:
661
662<!-- source: https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html -->
663
664| Key | Description |
665|---------------------------------------|--------------------------------------------------------------------------------------------------|
666| ``azure_storage_account_name`` | The name of the azure storage account. |
667| ``azure_storage_account_key`` | The serialized service account key. |
668| ``azure_client_id`` | Service principal client id for authorizing requests. |
669| ``azure_client_secret`` | Service principal client secret for authorizing requests. |
670| ``azure_tenant_id`` | Tenant id used in oauth flows. |
671| ``azure_storage_sas_key`` | Shared access signature. The signature is expected to be percent-encoded, much like they are provided in the azure storage explorer or azure portal. |
672| ``azure_storage_token`` | Bearer token. |
673| ``azure_storage_use_emulator`` | Use object store with azurite storage emulator. |
674| ``azure_endpoint`` | Override the endpoint used to communicate with blob storage. |
675| ``azure_use_fabric_endpoint`` | Use object store with url scheme account.dfs.fabric.microsoft.com. |
676| ``azure_msi_endpoint`` | Endpoint to request a imds managed identity token. |
677| ``azure_object_id`` | Object id for use with managed identity authentication. |
678| ``azure_msi_resource_id`` | Msi resource id for use with managed identity authentication. |
679| ``azure_federated_token_file`` | File containing token for Azure AD workload identity federation. |
680| ``azure_use_azure_cli`` | Use azure cli for acquiring access token. |
681| ``azure_disable_tagging`` | Disables tagging objects. This can be desirable if not supported by the backing store. |
682
683<!-- TODO: demonstrate how to configure networked file systems for optimal performance -->