lancedb-ray 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lancedb_ray-0.1.0/LICENSE +202 -0
- lancedb_ray-0.1.0/MANIFEST.in +7 -0
- lancedb_ray-0.1.0/PKG-INFO +311 -0
- lancedb_ray-0.1.0/README.md +280 -0
- lancedb_ray-0.1.0/lancedb_ray/__init__.py +47 -0
- lancedb_ray-0.1.0/lancedb_ray/_plan.py +149 -0
- lancedb_ray-0.1.0/lancedb_ray/_retry.py +196 -0
- lancedb_ray-0.1.0/lancedb_ray/connection.py +405 -0
- lancedb_ray-0.1.0/lancedb_ray/datasink.py +524 -0
- lancedb_ray-0.1.0/lancedb_ray/datasource.py +448 -0
- lancedb_ray-0.1.0/lancedb_ray/io.py +946 -0
- lancedb_ray-0.1.0/lancedb_ray/py.typed +0 -0
- lancedb_ray-0.1.0/lancedb_ray.egg-info/PKG-INFO +311 -0
- lancedb_ray-0.1.0/lancedb_ray.egg-info/SOURCES.txt +17 -0
- lancedb_ray-0.1.0/lancedb_ray.egg-info/dependency_links.txt +1 -0
- lancedb_ray-0.1.0/lancedb_ray.egg-info/requires.txt +13 -0
- lancedb_ray-0.1.0/lancedb_ray.egg-info/top_level.txt +1 -0
- lancedb_ray-0.1.0/pyproject.toml +135 -0
- lancedb_ray-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# setuptools' default sdist rules sweep in ``tests/test_*.py`` but not the
|
|
2
|
+
# conftest and fakes they import, which ships a test suite that cannot run.
|
|
3
|
+
# Keep the sdist to the library itself.
|
|
4
|
+
prune tests
|
|
5
|
+
prune benchmarks
|
|
6
|
+
prune examples
|
|
7
|
+
global-exclude *.py[cod]
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lancedb-ray
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Ray Data integration for LanceDB and LanceDB Enterprise
|
|
5
|
+
Author: Justin Miller
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/justinrmiller/lancedb-ray
|
|
8
|
+
Project-URL: Repository, https://github.com/justinrmiller/lancedb-ray
|
|
9
|
+
Keywords: ray,lancedb,lance,vector-database,distributed
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: ray[data]>=2.53.0
|
|
19
|
+
Requires-Dist: lancedb>=0.24.0
|
|
20
|
+
Requires-Dist: lance-ray>=0.5.0
|
|
21
|
+
Requires-Dist: pyarrow>=17.0.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=8.4.0; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-xdist>=3.6.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-timeout>=2.3.0; extra == "dev"
|
|
27
|
+
Requires-Dist: mypy>=1.11.0; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.8.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pandas>=2.0.0; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# lancedb-ray
|
|
33
|
+
|
|
34
|
+
Ray Data integration for [LanceDB](https://lancedb.com) and LanceDB Enterprise.
|
|
35
|
+
|
|
36
|
+
Read and write LanceDB tables as Ray Datasets, using the most parallel strategy each
|
|
37
|
+
backend actually supports.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import lancedb_ray as ldbr
|
|
41
|
+
|
|
42
|
+
# Local / OSS
|
|
43
|
+
ds = ldbr.read_lancedb("embeddings", uri="/data/lancedb")
|
|
44
|
+
ldbr.write_lancedb(ds, "embeddings_copy", uri="/data/lancedb", mode="create")
|
|
45
|
+
|
|
46
|
+
# LanceDB Enterprise / Cloud (API key from LANCEDB_API_KEY)
|
|
47
|
+
ds = ldbr.read_lancedb("embeddings", uri="db://my-database", region="us-east-1")
|
|
48
|
+
ldbr.write_lancedb(ds, "embeddings", uri="db://my-database", mode="upsert", on="id")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Why two strategies
|
|
52
|
+
|
|
53
|
+
LanceDB presents one Python API over two very different systems, and a Ray integration
|
|
54
|
+
that ignores the difference leaves most of the available parallelism on the table:
|
|
55
|
+
|
|
56
|
+
| | Local / OSS (`/path`, `s3://…`) | Cloud / Enterprise (`db://…`) |
|
|
57
|
+
| ---------------------- | --------------------------------- | ---------------------------------- |
|
|
58
|
+
| Underlying storage | A real Lance dataset | Opaque remote service |
|
|
59
|
+
| `to_arrow()` / `to_lance()` | Works | Raises `NotImplementedError` |
|
|
60
|
+
| `optimize()` | Works | Silent no-op (server-managed) |
|
|
61
|
+
| Fragment access | Yes | No |
|
|
62
|
+
| Bulk read primitive | Fragment scan | `take_offsets` / paged queries |
|
|
63
|
+
|
|
64
|
+
So `lancedb-ray` does this:
|
|
65
|
+
|
|
66
|
+
**Reads.** Local tables are read one task per fragment group, with `columns` and `filter`
|
|
67
|
+
pushed down into the scan (delegated to [`lance-ray`](https://github.com/lance-format/lance-ray)).
|
|
68
|
+
Remote tables have no fragments, so the row space is sharded across read tasks —
|
|
69
|
+
positionally via `take_offsets` when there is no filter, and by server-side pagination
|
|
70
|
+
when there is.
|
|
71
|
+
|
|
72
|
+
**Every read pins a table version** before planning shards. A writer landing mid-read
|
|
73
|
+
therefore cannot tear the result: shards planned against 100 rows never observe a
|
|
74
|
+
200-row table.
|
|
75
|
+
|
|
76
|
+
**Writes.** Local append-style writes take the fragment path — workers write Lance
|
|
77
|
+
fragments in parallel and the driver commits them as a **single atomic transaction**, so
|
|
78
|
+
the table advances by exactly one version no matter how many tasks participated. Upserts
|
|
79
|
+
and all Cloud/Enterprise writes go through LanceDB's table API with batching and retry.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
8 Ray blocks → 8 Lance fragments → 1 committed version
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Install
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uv pip install lancedb-ray
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Or the unreleased tip of `main`:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
uv pip install git+https://github.com/justinrmiller/lancedb-ray.git
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or for local development:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
git clone https://github.com/justinrmiller/lancedb-ray.git
|
|
101
|
+
cd lancedb-ray
|
|
102
|
+
uv venv --python 3.12
|
|
103
|
+
make build
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Requires Python 3.12 or newer and Ray 2.53 or newer. CI tests Python 3.12
|
|
107
|
+
against both the newest Ray and the oldest supported one, so an install next to
|
|
108
|
+
an older Ray cluster is tested, not assumed.
|
|
109
|
+
|
|
110
|
+
## API
|
|
111
|
+
|
|
112
|
+
### `read_lancedb(table, *, uri, ...) -> ray.data.Dataset`
|
|
113
|
+
|
|
114
|
+
| Argument | Meaning |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| `columns`, `filter` | Projection and SQL predicate, evaluated server-side |
|
|
117
|
+
| `version` | Table version to pin (defaults to current) |
|
|
118
|
+
| `remote_read_strategy` | `auto` (default), `offsets`, `pagination`, `single` |
|
|
119
|
+
| `batch_size` | Rows per read request — sizes each task's requests remotely, and the Lance scanner's batches locally |
|
|
120
|
+
| `scanner_options` | Extra Lance scanner options for a local read — `use_scalar_index`, `late_materialization`, `with_row_id` |
|
|
121
|
+
| `api_key`, `region`, `host_override` | Cloud/Enterprise connection |
|
|
122
|
+
| `storage_options`, `client_config` | Object-store and HTTP client options |
|
|
123
|
+
| `namespace_client_impl`, `namespace_client_properties` | Lance Namespace resolution |
|
|
124
|
+
|
|
125
|
+
### `write_lancedb(ds, table, *, uri, mode="append", ...) -> None`
|
|
126
|
+
|
|
127
|
+
| Argument | Meaning |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `mode` | `create`, `append`, `overwrite`, `upsert` |
|
|
130
|
+
| `on` | Key column(s) to match on — required for `upsert` |
|
|
131
|
+
| `partition_on_keys` | Hash-partition on `on` before an upsert (default `True`) |
|
|
132
|
+
| `transform_fn` | Per-batch transform applied before writing (e.g. computing embeddings) |
|
|
133
|
+
| `on_batch_error` | `raise` (default) or `skip` |
|
|
134
|
+
| `local_write_strategy` | `auto` (default), `fragment`, `api` |
|
|
135
|
+
| `rows_per_transaction` | Rows Ray bundles per write task = transaction size |
|
|
136
|
+
| `max_rows_per_request` | Optional row ceiling; splits a task into several transactions |
|
|
137
|
+
| `max_bytes_per_request` | Optional ceiling on a request's payload in bytes — the one that bounds a wide schema |
|
|
138
|
+
| `write_parallelism` | Parts the client uploads concurrently within one transaction |
|
|
139
|
+
| `data_storage_version`, `enable_stable_row_ids` | Lance file format and row-ID stability for the fragment path |
|
|
140
|
+
| `when_matched_update_all`, `when_not_matched_insert_all`, `when_not_matched_by_source_delete` | Merge-insert semantics |
|
|
141
|
+
|
|
142
|
+
## Examples
|
|
143
|
+
|
|
144
|
+
Each example lives in its own directory with a README of its own — see
|
|
145
|
+
[`examples/`](https://github.com/justinrmiller/lancedb-ray/tree/main/examples).
|
|
146
|
+
|
|
147
|
+
| Example | What it shows |
|
|
148
|
+
| --- | --- |
|
|
149
|
+
| [`quickstart/`](https://github.com/justinrmiller/lancedb-ray/tree/main/examples/quickstart) | The core guarantees on synthetic data: a write fans out across Ray tasks yet lands as one atomic commit, and reads come back fragment-parallel. No extra dependencies. |
|
|
150
|
+
| [`clip_image_search/`](https://github.com/justinrmiller/lancedb-ray/tree/main/examples/clip_image_search) | A realistic pipeline — scan a directory of JPGs, embed them with CLIP across Ray, write to LanceDB, build a vector index, then search them in plain English from a Streamlit app. |
|
|
151
|
+
| [`vllm_generate_embed/`](https://github.com/justinrmiller/lancedb-ray/tree/main/examples/vllm_generate_embed) | An LLM pipeline — answer prompts with vLLM (or a small local model), embed each answer, write them to LanceDB, then search what the model said by meaning from a Streamlit app. |
|
|
152
|
+
| [`object_storage/`](https://github.com/justinrmiller/lancedb-ray/tree/main/examples/object_storage) | Verify writes to S3-compatible object storage — a Floci emulator in Docker Compose plus a large locally generated dataset, asserting the round trip and the single atomic commit. |
|
|
153
|
+
|
|
154
|
+
## Two traps this library avoids
|
|
155
|
+
|
|
156
|
+
These are easy to get wrong when writing to LanceDB from a distributed engine, and both
|
|
157
|
+
were worth designing around explicitly.
|
|
158
|
+
|
|
159
|
+
### One transaction per task, not one per batch
|
|
160
|
+
|
|
161
|
+
Every LanceDB write is a transaction: it produces a new table version and at least one
|
|
162
|
+
fragment. The obvious way to write a Ray Dataset — issue a write per incoming batch —
|
|
163
|
+
therefore multiplies both. Measured on a 20,480-row append:
|
|
164
|
+
|
|
165
|
+
| Approach | Versions | Fragments |
|
|
166
|
+
| --- | ---: | ---: |
|
|
167
|
+
| One write per 1,024-row batch | 21 | 20 |
|
|
168
|
+
| One write for the whole task | 2 | 1 |
|
|
169
|
+
|
|
170
|
+
Thousands of tiny fragments degrade read performance until compaction catches up, and
|
|
171
|
+
against Cloud/Enterprise the extra requests burn quota and invite rate limiting.
|
|
172
|
+
|
|
173
|
+
So a write task hands **all** of its rows to LanceDB as a single `RecordBatchReader`. The
|
|
174
|
+
client streams that to the service as multiple parts under one upload and commits once, so
|
|
175
|
+
one task is one transaction no matter how many blocks Ray delivered. `rows_per_transaction`
|
|
176
|
+
controls how many rows Ray bundles per task, and therefore how large each transaction is.
|
|
177
|
+
|
|
178
|
+
Local append-style writes skip this path entirely — they write Lance fragments in parallel
|
|
179
|
+
and commit them in a single transaction, so the table advances by exactly one version.
|
|
180
|
+
|
|
181
|
+
### Parallel merge-inserts can silently duplicate keys
|
|
182
|
+
|
|
183
|
+
Two write tasks that each hold one row for the same key will each find the key absent and
|
|
184
|
+
each insert it. Neither task's input is internally ambiguous, so LanceDB accepts both and
|
|
185
|
+
the key ends up in the table twice — with no error:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# key 7 in two concurrent merge_inserts, once each
|
|
189
|
+
# → table now contains id=7 twice
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`write_lancedb` therefore hash-partitions the input on the `on` columns before an upsert,
|
|
193
|
+
so every row for a given key lands in exactly one task. Where a key is genuinely repeated
|
|
194
|
+
in the source, LanceDB then rejects it as an ambiguous merge rather than duplicating it —
|
|
195
|
+
a loud error instead of corrupt data.
|
|
196
|
+
|
|
197
|
+
This costs a shuffle. It changes nothing when the source's keys are already unique (a
|
|
198
|
+
unique key can only occupy one block), so `partition_on_keys=False` skips it when you know
|
|
199
|
+
that to be true.
|
|
200
|
+
|
|
201
|
+
## Other notes and trade-offs
|
|
202
|
+
|
|
203
|
+
- **Appends are at-least-once; upserts are exactly-once.** If LanceDB commits a
|
|
204
|
+
write and the response is lost, no client can distinguish that from a write
|
|
205
|
+
that never landed, so a retry duplicates the batch. The default retry policy
|
|
206
|
+
narrows the window — an append retries only on failures that prove nothing was
|
|
207
|
+
applied, such as a refused connection or a rate-limit rejection, while an
|
|
208
|
+
upsert also retries ambiguous ones like a read timeout because merge-insert is
|
|
209
|
+
idempotent. If you need exactly-once, write with `mode="upsert"` and an `on`
|
|
210
|
+
key; replaying it converges on the same table.
|
|
211
|
+
- **`on_batch_error` defaults to `raise`.** Logging a failed write and continuing lets a
|
|
212
|
+
job report success while having silently lost data. `skip` is available when partial
|
|
213
|
+
completion genuinely is preferable, and dropped rows are counted and warned about.
|
|
214
|
+
- **`rows_per_transaction` sets task memory; the per-request ceilings set payload
|
|
215
|
+
size.** A task holds all of its rows in memory so a failed write can be retried, and it
|
|
216
|
+
materialises them before either ceiling is consulted — so peak worker memory is set by
|
|
217
|
+
`rows_per_transaction` alone. That is the knob to turn down when a task is being
|
|
218
|
+
OOM-killed, and it is worth sizing in bytes rather than rows: 262,144 rows is a few MB
|
|
219
|
+
of scalars but 1.5GB of 1536-dimension embeddings, and unbounded if a row carries an
|
|
220
|
+
image.
|
|
221
|
+
|
|
222
|
+
`max_rows_per_request` and `max_bytes_per_request` bound something narrower — how much
|
|
223
|
+
of that already-materialised data is handed to LanceDB per transaction, and so how much
|
|
224
|
+
the client encodes and uploads at once. Both may be set and the tighter one closes the
|
|
225
|
+
request. Either costs extra transactions.
|
|
226
|
+
|
|
227
|
+
- **`enable_stable_row_ids` is decided at creation.** Stable IDs survive compaction,
|
|
228
|
+
which is what lets a later job address a row it saw earlier. They are off by default
|
|
229
|
+
because they cost an index — but a table written without them cannot be switched over
|
|
230
|
+
without a rewrite, so it is worth deciding up front rather than discovering later.
|
|
231
|
+
- **Local upserts are deliberately not highly parallel.** Concurrent merge-insert against
|
|
232
|
+
a single local dataset contends on the commit lock, so local upsert defaults to
|
|
233
|
+
`concurrency=4` with conflict retry. Remote upserts have no such limit — the service
|
|
234
|
+
serialises for us.
|
|
235
|
+
- **Remote reads default to positional `take_offsets`.** The alternative,
|
|
236
|
+
`remote_read_strategy="pagination"`, measured ~2x faster locally and sends a
|
|
237
|
+
constant-size request (two integers) rather than an explicit list of offsets, and
|
|
238
|
+
neither degraded with offset depth over a 1M-row table. That is local measurement
|
|
239
|
+
though, against storage rather than the service — the positional primitive stays the
|
|
240
|
+
default because it is the one with guaranteed positional semantics. If you are pushing
|
|
241
|
+
volume through Enterprise, `pagination` is worth measuring against your endpoint.
|
|
242
|
+
- **`batch_size` sets round trips, not total payload.** The same offsets are sent either
|
|
243
|
+
way, just in fewer requests, so raising it mostly buys fewer round trips. Left unset it
|
|
244
|
+
uses each backend's own sizing — 50,000 rows per request remotely, and the Lance
|
|
245
|
+
scanner's default locally. Setting it takes precedence over a `batch_size` named in
|
|
246
|
+
`scanner_options`, the same way `columns` and `filter` do.
|
|
247
|
+
- **For a highly selective filter over a large table**, `remote_read_strategy="single"`
|
|
248
|
+
streams the result through one task and often beats sharding it.
|
|
249
|
+
- **API keys should come from `LANCEDB_API_KEY`** rather than the `api_key` argument, so
|
|
250
|
+
the secret stays out of Ray task definitions and logs. The connection spec's `repr`
|
|
251
|
+
redacts it either way.
|
|
252
|
+
|
|
253
|
+
## Tuning
|
|
254
|
+
|
|
255
|
+
Most of the cost of a large job is inside Lance's native core, not this library, and that
|
|
256
|
+
core is configured by environment variables rather than by arguments. They have to be set
|
|
257
|
+
on the Ray **workers**, so put them in the runtime environment rather than only in the
|
|
258
|
+
driver's shell:
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
ray.init(runtime_env={"env_vars": {"LANCE_IO_THREADS": "128"}})
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
| Variable | What it controls |
|
|
265
|
+
| --- | --- |
|
|
266
|
+
| `LANCE_IO_THREADS` | Concurrent read requests to storage. Raising it toward the core count helps a large scan against S3, where the default leaves the link idle. |
|
|
267
|
+
| `LANCE_UPLOAD_CONCURRENCY` | Concurrent multipart upload streams. The write-side counterpart, and the first thing to raise if the fragment path is not saturating your bandwidth. |
|
|
268
|
+
| `LANCE_INITIAL_UPLOAD_SIZE` | Starting multipart part size, in bytes. Larger parts mean fewer API calls on a big write and more memory per stream. Lance grows the part size as an upload progresses, so this only sets where it starts. |
|
|
269
|
+
|
|
270
|
+
Two things worth knowing beyond the knobs:
|
|
271
|
+
|
|
272
|
+
- **Lance is tuned for random access by default.** Point lookups, vector search and
|
|
273
|
+
selective column reads are what the defaults optimise for. A scan-heavy ETL job is the
|
|
274
|
+
case that benefits from raising the two thread counts above.
|
|
275
|
+
- **Fixed-size lists for vectors, blob encoding for large binaries.** A vector column
|
|
276
|
+
stored as a fixed-size list compresses better and takes the SIMD path; large binary
|
|
277
|
+
payloads stored with Lance's blob encoding are not read unless a query touches them.
|
|
278
|
+
Both are properties of the schema you write, so they are decided before this library
|
|
279
|
+
sees the data.
|
|
280
|
+
|
|
281
|
+
These are Lance-core knobs, so the same settings apply to
|
|
282
|
+
[`lance-spark`](https://github.com/lance-format/lance-spark), whose
|
|
283
|
+
[performance guide](https://lance.org/integrations/spark) covers them in more depth
|
|
284
|
+
along with the JVM-only options.
|
|
285
|
+
|
|
286
|
+
## Development
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
make build # install with dev dependencies
|
|
290
|
+
make test # pytest with branch coverage (gate: 95%)
|
|
291
|
+
make lint # ruff check + format check + mypy
|
|
292
|
+
make fix # auto-fix and format
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Tests cover both backends. The Cloud/Enterprise paths run against an in-repo fake that
|
|
296
|
+
mirrors the real remote API surface — including its restrictions — so `db://` code is
|
|
297
|
+
exercised deterministically with no network. To additionally validate against the real
|
|
298
|
+
service:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
LANCEDB_URI=db://your-db LANCEDB_API_KEY=... pytest -m enterprise
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
305
|
+
`fix:` cuts a patch release, `feat:` a minor one, and the version in
|
|
306
|
+
`pyproject.toml` is written by automation rather than by hand. See
|
|
307
|
+
[RELEASING.md](https://github.com/justinrmiller/lancedb-ray/blob/main/RELEASING.md).
|
|
308
|
+
|
|
309
|
+
## License
|
|
310
|
+
|
|
311
|
+
Apache-2.0
|