mirror of
https://github.com/lancedb/lancedb.git
synced 2026-08-28 17:08:43 +00:00
Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b5158f62ab | |||
| ec21e37040 | |||
| 6ba80a960c | |||
| 11f24b1df4 | |||
| 2ba7407dc3 | |||
| 607e556927 | |||
| 564e5d0d56 | |||
| dd5cb4d805 | |||
| dbc3687c7b | |||
| ec80acb668 | |||
| fc44535cee | |||
| 4048150fdd | |||
| 2922c171f7 | |||
| c5f9efefe9 | |||
| f4c668e244 | |||
| b1cfe6edb1 | |||
| 001237c7a4 | |||
| 369b10a377 | |||
| 1c3cd1d918 | |||
| 9707966943 | |||
| 62fe413a52 | |||
| 1493ece3de | |||
| e6444ecc05 | |||
| cc0139c136 | |||
| b20696ef9c | |||
| 772bdeced8 | |||
| c1a3fa7f51 | |||
| 0ba82873c5 | |||
| 3af51541a0 | |||
| 2c06a48bd8 | |||
| ac8b28c010 | |||
| 173f889d2a | |||
| 03b52e5877 | |||
| 798e5364fb | |||
| f1f34dfdd3 | |||
| 123c921c4f | |||
| 99a68db78c | |||
| 9e73d440a3 | |||
| 3956d9dbfa | |||
| 16e1967efc | |||
| 27dd92c67e | |||
| 9e2e711c7a | |||
| c3176a47ce | |||
| 191e9eed8d | |||
| 7357d63e87 | |||
| 624a75edf7 | |||
| c7ea91f3ea | |||
| 8e24dd3828 | |||
| f79dc017c4 | |||
| e6ae93f52a | |||
| 3dd9c598e9 | |||
| 9e26bf3fba | |||
| 93354baf34 | |||
| 05602ec7d5 | |||
| e3b472c212 | |||
| a6418b6cb9 | |||
| dd2b11eda2 | |||
| 5a1015ba72 | |||
| 48945d0658 | |||
| 77208fd464 | |||
| b505dc1315 | |||
| 7dfdfe6401 | |||
| 4dc2d9a0f2 | |||
| 1ad6ce3a4e |
@@ -0,0 +1,222 @@
|
|||||||
|
name: Check doc links
|
||||||
|
|
||||||
|
# Checking external links is inherently noisy: third-party sites rate-limit
|
||||||
|
# automated clients, reject non-browser user agents, and go down temporarily.
|
||||||
|
# Blocking pull requests on that trades a lot of false failures for very little
|
||||||
|
# signal, so this runs on a schedule and reports findings in a single tracking
|
||||||
|
# issue instead of failing anyone's build.
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 7 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# The report lives in one repository-global issue, so runs must not overlap: a
|
||||||
|
# lookup racing a create produces duplicate issues, and a healthy run closing
|
||||||
|
# the issue while a failing run only rewrites its body would leave a broken
|
||||||
|
# report closed. The group is deliberately ref-independent so that a manual
|
||||||
|
# dispatch serializes against the scheduled run.
|
||||||
|
concurrency:
|
||||||
|
group: docs-link-check
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
env:
|
||||||
|
REPORT_TITLE: "Docs link checker report"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
scan:
|
||||||
|
name: Scan links
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
# lychee-action is pinned by SHA, but its wrapper downloads the lychee
|
||||||
|
# release tarball at run time without verifying a digest, and hands the
|
||||||
|
# resulting binary a GitHub token. Release assets remain replaceable, so
|
||||||
|
# that binary is confined to a job whose token can only read public
|
||||||
|
# content; everything that writes runs in the report job below.
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
outputs:
|
||||||
|
exit_code: ${{ steps.lychee.outputs.exit_code }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
# workflow_dispatch can run from any ref, but the report is
|
||||||
|
# repository-global. Always measure the default branch so a manual
|
||||||
|
# run from a topic branch cannot close a report that main warrants,
|
||||||
|
# or overwrite it with branch-only findings.
|
||||||
|
ref: ${{ github.event.repository.default_branch }}
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Check links
|
||||||
|
id: lychee
|
||||||
|
uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2.9.0
|
||||||
|
with:
|
||||||
|
# Restricted to http(s) on purpose. Much of docs/src is generated
|
||||||
|
# API reference (the js/ tree comes from `npm run docs` in nodejs)
|
||||||
|
# and the hand-written pages use mkdocstrings cross-references and
|
||||||
|
# nav-relative paths that only resolve in the site mkdocs builds,
|
||||||
|
# not in this checkout, so relative links would be reported as
|
||||||
|
# broken on every run.
|
||||||
|
args: >-
|
||||||
|
--scheme https
|
||||||
|
--scheme http
|
||||||
|
--no-progress
|
||||||
|
--max-retries 3
|
||||||
|
--timeout 20
|
||||||
|
'docs/src/**/*.md'
|
||||||
|
format: json
|
||||||
|
output: ./lychee/out.json
|
||||||
|
jobSummary: false
|
||||||
|
# The report, not a red build, is the signal for broken links. The
|
||||||
|
# validation step below still fails the run if the check itself
|
||||||
|
# breaks.
|
||||||
|
fail: false
|
||||||
|
|
||||||
|
- name: Validate report
|
||||||
|
# lychee does not reserve exit code 2 for broken links: its CLI
|
||||||
|
# parser also exits 2 on an invalid option, before any link was
|
||||||
|
# checked or any report written. Only a parseable report whose
|
||||||
|
# counts agree with the exit code counts as a link verdict; anything
|
||||||
|
# else fails here, and the report job below is skipped entirely, so
|
||||||
|
# the tracking issue is never touched. Exit 2 covers timeouts as
|
||||||
|
# well as errors, and a timed-out host is exactly the transient
|
||||||
|
# unavailability this report exists to surface, so both count as
|
||||||
|
# findings. Requiring total > 0 also catches a glob that silently
|
||||||
|
# stopped matching any file.
|
||||||
|
if: steps.lychee.outputs.exit_code == 0 || steps.lychee.outputs.exit_code == 2
|
||||||
|
env:
|
||||||
|
EXIT_CODE: ${{ steps.lychee.outputs.exit_code }}
|
||||||
|
run: |
|
||||||
|
jq -e --argjson code "$EXIT_CODE" '
|
||||||
|
(.total > 0) and
|
||||||
|
(if $code == 0
|
||||||
|
then .errors == 0 and .timeouts == 0
|
||||||
|
and (.error_map | length == 0) and (.timeout_map | length == 0)
|
||||||
|
else (.errors + .timeouts) > 0
|
||||||
|
and ((.error_map | length) + (.timeout_map | length)) > 0
|
||||||
|
end)
|
||||||
|
' ./lychee/out.json
|
||||||
|
|
||||||
|
- name: Upload report
|
||||||
|
if: steps.lychee.outputs.exit_code == 2
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: link-report
|
||||||
|
path: ./lychee/out.json
|
||||||
|
retention-days: 7
|
||||||
|
|
||||||
|
report:
|
||||||
|
name: Update report issue
|
||||||
|
needs: scan
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
# Deliberately no checkout: this job needs the report artifact and the
|
||||||
|
# issues API, not the repository contents.
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
env:
|
||||||
|
EXIT_CODE: ${{ needs.scan.outputs.exit_code }}
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
steps:
|
||||||
|
- name: Classify checker result
|
||||||
|
# lychee exits 0 when every link resolves and 2 when links fail,
|
||||||
|
# both already cross-checked against the report by the scan job's
|
||||||
|
# validation step. Anything else (1 runtime, 3 bad config) means the
|
||||||
|
# check never produced a link verdict, which must surface as a failed
|
||||||
|
# run rather than be published as "broken documentation links".
|
||||||
|
run: |
|
||||||
|
case "$EXIT_CODE" in
|
||||||
|
0|2)
|
||||||
|
echo "lychee exit code $EXIT_CODE"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "::error::lychee exited with '$EXIT_CODE': the link check did not complete. Leaving the report issue untouched."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
- name: Find existing report issue
|
||||||
|
id: report
|
||||||
|
# Matched on title alone, and through search rather than a listing:
|
||||||
|
# the issue action applies labels in a separate call after creating the
|
||||||
|
# issue, so a label filter misses a half-created report, and this
|
||||||
|
# repository has far more open issues than one listing page holds.
|
||||||
|
# Closed issues are included because a healthy run closes the report:
|
||||||
|
# an open-only lookup would forget that identity and the next failing
|
||||||
|
# run would open a duplicate. The oldest match stays the canonical
|
||||||
|
# report and is reopened below when links break again.
|
||||||
|
run: |
|
||||||
|
match=$(gh issue list --repo "$GITHUB_REPOSITORY" --state all \
|
||||||
|
--search "in:title \"$REPORT_TITLE\" author:app/github-actions" \
|
||||||
|
--limit 50 --json number,title,state \
|
||||||
|
--jq "[.[] | select(.title == \"$REPORT_TITLE\")] | sort_by(.number) | first // empty")
|
||||||
|
echo "number=$(jq -r '.number // empty' <<<"$match")" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "state=$(jq -r '.state // empty' <<<"$match")" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Download report
|
||||||
|
if: env.EXIT_CODE == 2
|
||||||
|
uses: actions/download-artifact@v8
|
||||||
|
with:
|
||||||
|
name: link-report
|
||||||
|
path: ./lychee
|
||||||
|
|
||||||
|
- name: Compose report
|
||||||
|
if: env.EXIT_CODE == 2
|
||||||
|
run: |
|
||||||
|
run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
|
||||||
|
{
|
||||||
|
echo "Broken documentation links found by [\`$GITHUB_WORKFLOW\`]($run_url)."
|
||||||
|
echo
|
||||||
|
echo "This issue is rewritten by every scheduled run and closed automatically once all links resolve."
|
||||||
|
echo
|
||||||
|
echo "Entries can be false positives: some sites rate-limit or block automated clients while working fine in a browser. Confirm before editing the docs, and add persistent offenders to \`--exclude\` in \`.github/workflows/docs-link-check.yml\`."
|
||||||
|
echo
|
||||||
|
# Timeouts are reported alongside errors: entries land in
|
||||||
|
# timeout_map with a status text instead of an HTTP code.
|
||||||
|
jq -r '
|
||||||
|
"\(.errors) of \(.total) links failed, \(.timeouts) timed out.",
|
||||||
|
"",
|
||||||
|
([(.error_map | to_entries[]), (.timeout_map | to_entries[])]
|
||||||
|
| group_by(.key)[] |
|
||||||
|
"### Errors in \(.[0].key)",
|
||||||
|
"",
|
||||||
|
(map(.value[])[] | "* [\(.status.code // .status.text // "ERR")] <\(.url)> — \(.status.details // .status.text // "unknown error")"),
|
||||||
|
"")
|
||||||
|
' ./lychee/out.json
|
||||||
|
} > ./lychee/issue.md
|
||||||
|
|
||||||
|
- name: Reopen report issue
|
||||||
|
# A healthy run closes the report, and the issue action below only
|
||||||
|
# rewrites the body of whatever number it is given. Without an
|
||||||
|
# explicit reopen, the 2 -> 0 -> 2 sequence would keep rewriting a
|
||||||
|
# closed issue while links are broken. A CLOSED state implies the
|
||||||
|
# lookup found a canonical issue, so no separate emptiness check.
|
||||||
|
if: env.EXIT_CODE == 2 && steps.report.outputs.state == 'CLOSED'
|
||||||
|
env:
|
||||||
|
ISSUE_NUMBER: ${{ steps.report.outputs.number }}
|
||||||
|
run: |
|
||||||
|
run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
|
||||||
|
gh issue reopen "$ISSUE_NUMBER" --repo "$GITHUB_REPOSITORY" \
|
||||||
|
--comment "Broken documentation links found again in [the latest run]($run_url)."
|
||||||
|
|
||||||
|
- name: Report broken links
|
||||||
|
if: env.EXIT_CODE == 2
|
||||||
|
uses: peter-evans/create-issue-from-file@fca9117c27cdc29c6c4db3b86c48e4115a786710 # v6.0.0
|
||||||
|
with:
|
||||||
|
# Empty on the first failing run, which creates the issue; afterwards
|
||||||
|
# the same issue is updated in place.
|
||||||
|
issue-number: ${{ steps.report.outputs.number }}
|
||||||
|
title: ${{ env.REPORT_TITLE }}
|
||||||
|
content-filepath: ./lychee/issue.md
|
||||||
|
labels: documentation
|
||||||
|
|
||||||
|
- name: Close report issue once links are healthy
|
||||||
|
# An OPEN state implies the lookup found a canonical issue; a report
|
||||||
|
# that is already closed needs nothing.
|
||||||
|
if: env.EXIT_CODE == 0 && steps.report.outputs.state == 'OPEN'
|
||||||
|
env:
|
||||||
|
ISSUE_NUMBER: ${{ steps.report.outputs.number }}
|
||||||
|
run: |
|
||||||
|
run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
|
||||||
|
gh issue close "$ISSUE_NUMBER" --repo "$GITHUB_REPOSITORY" \
|
||||||
|
--comment "All documentation links resolved in [the latest run]($run_url)."
|
||||||
@@ -296,16 +296,18 @@ jobs:
|
|||||||
cargo update -p aws-types --precise 1.3.9
|
cargo update -p aws-types --precise 1.3.9
|
||||||
cargo update -p aws-sigv4 --precise 1.3.5
|
cargo update -p aws-sigv4 --precise 1.3.5
|
||||||
cargo update -p aws-credential-types --precise 1.2.8
|
cargo update -p aws-credential-types --precise 1.2.8
|
||||||
cargo update -p aws-smithy-checksums --precise 0.63.9
|
# aws-smithy-checksums must stay at or above 0.63.13: OpenDAL's S3
|
||||||
|
# service needs crc-fast ~1.9, and older releases pin it to ~1.3.
|
||||||
|
cargo update -p aws-smithy-checksums --precise 0.63.13
|
||||||
cargo update -p aws-smithy-runtime --precise 1.9.3
|
cargo update -p aws-smithy-runtime --precise 1.9.3
|
||||||
cargo update -p aws-smithy-http --precise 0.62.4
|
cargo update -p aws-smithy-http --precise 0.62.6
|
||||||
cargo update -p aws-smithy-eventstream --precise 0.60.12
|
cargo update -p aws-smithy-eventstream --precise 0.60.14
|
||||||
cargo update -p aws-smithy-http-client --precise 1.1.3
|
cargo update -p aws-smithy-http-client --precise 1.1.3
|
||||||
cargo update -p aws-smithy-observability --precise 0.1.4
|
cargo update -p aws-smithy-observability --precise 0.1.4
|
||||||
cargo update -p aws-smithy-query --precise 0.60.8
|
cargo update -p aws-smithy-query --precise 0.60.8
|
||||||
cargo update -p aws-smithy-runtime-api --precise 1.9.1
|
cargo update -p aws-smithy-runtime-api --precise 1.9.3
|
||||||
cargo update -p aws-smithy-async --precise 1.2.6
|
cargo update -p aws-smithy-async --precise 1.2.7
|
||||||
cargo update -p aws-smithy-types --precise 1.3.5
|
cargo update -p aws-smithy-types --precise 1.3.6
|
||||||
cargo update -p aws-smithy-xml --precise 0.60.11
|
cargo update -p aws-smithy-xml --precise 0.60.11
|
||||||
cargo update -p home --precise 0.5.9
|
cargo update -p home --precise 0.5.9
|
||||||
- name: cargo +${{ matrix.msrv }} check
|
- name: cargo +${{ matrix.msrv }} check
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ Python bindings changes:
|
|||||||
* Should use `LOOP.run()` to call the corresponding `AsyncTable` method.
|
* Should use `LOOP.run()` to call the corresponding `AsyncTable` method.
|
||||||
6. Add concrete sync method to `RemoteTable` class in `python/python/lancedb/remote/table.py`.
|
6. Add concrete sync method to `RemoteTable` class in `python/python/lancedb/remote/table.py`.
|
||||||
7. Add unit test in `python/tests/test_table.py`.
|
7. Add unit test in `python/tests/test_table.py`.
|
||||||
|
8. If you added a new public class or module-level function (not just a method on an
|
||||||
|
existing class), expose it in the API reference. See "Python API reference" below.
|
||||||
|
|
||||||
TypeScript bindings changes:
|
TypeScript bindings changes:
|
||||||
|
|
||||||
@@ -103,6 +105,33 @@ TypeScript bindings changes:
|
|||||||
5. Add test in `nodejs/__test__/table.test.ts`.
|
5. Add test in `nodejs/__test__/table.test.ts`.
|
||||||
6. Run `npm run docs` to generate TypeScript documentation.
|
6. Run `npm run docs` to generate TypeScript documentation.
|
||||||
|
|
||||||
|
## Python API reference
|
||||||
|
|
||||||
|
`docs/src/python/python.md` is the entire Python API reference. It is maintained by
|
||||||
|
hand, and anything not listed there is not rendered at all, so new public classes and
|
||||||
|
module-level functions have to be added explicitly. How depends on the module:
|
||||||
|
|
||||||
|
* `lancedb.index`, `lancedb.embeddings`, `lancedb.remote`, and `lancedb.rerankers` are
|
||||||
|
rendered by a single directive each, driven by the module's `__all__`. Add the new
|
||||||
|
name to `__all__` and it appears; forget, and it is silently omitted.
|
||||||
|
* Everything else (`lancedb`, `lancedb.table`, `lancedb.query`, `lancedb.db`, ...) is
|
||||||
|
listed symbol by symbol. Add a `::: lancedb.<module>.<Name>` line to the matching
|
||||||
|
section, and remember that the page separates synchronous and asynchronous APIs.
|
||||||
|
|
||||||
|
Deliberately undocumented: concrete implementations reached through an abstract base
|
||||||
|
(`LanceTable`, `LanceDBConnection`, `RemoteDBConnection`), query base classes already
|
||||||
|
covered by `inherited_members`, and internal helpers.
|
||||||
|
|
||||||
|
Cross-references in docstrings use mkdocstrings syntax, `[text][lancedb.table.Table]`.
|
||||||
|
Plain relative links such as `[Table](Table)` do not resolve. To check your work:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pip install -r docs/requirements.txt
|
||||||
|
cd docs && PYTHONPATH=. mkdocs build
|
||||||
|
```
|
||||||
|
|
||||||
|
The docs site only builds on pushes to `main`, so this is not covered by PR CI.
|
||||||
|
|
||||||
## Review Guidelines
|
## Review Guidelines
|
||||||
|
|
||||||
Please consider the following when reviewing code contributions.
|
Please consider the following when reviewing code contributions.
|
||||||
|
|||||||
Generated
+322
-302
File diff suppressed because it is too large
Load Diff
+15
-15
@@ -13,20 +13,20 @@ categories = ["database-implementations"]
|
|||||||
rust-version = "1.91.0"
|
rust-version = "1.91.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
lance = { "version" = "=10.0.0-beta.5", default-features = false, "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance = { "version" = "=11.0.0-beta.2", default-features = false, "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-core = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-core = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-datagen = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-datagen = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-file = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-file = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-io = { "version" = "=10.0.0-beta.5", default-features = false, "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-io = { "version" = "=11.0.0-beta.2", default-features = false, "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-index = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-index = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-linalg = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-linalg = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-namespace = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-namespace = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-namespace-impls = { "version" = "=10.0.0-beta.5", default-features = false, "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-namespace-impls = { "version" = "=11.0.0-beta.2", default-features = false, "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-table = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-table = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-testing = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-testing = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-datafusion = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-datafusion = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-encoding = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-encoding = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
lance-arrow = { "version" = "=10.0.0-beta.5", "tag" = "v10.0.0-beta.5", "git" = "https://github.com/lance-format/lance.git" }
|
lance-arrow = { "version" = "=11.0.0-beta.2", "tag" = "v11.0.0-beta.2", "git" = "https://github.com/lance-format/lance.git" }
|
||||||
ahash = "0.8"
|
ahash = "0.8"
|
||||||
# Note that this one does not include pyarrow
|
# Note that this one does not include pyarrow
|
||||||
arrow = { version = "58.0.0", optional = false }
|
arrow = { version = "58.0.0", optional = false }
|
||||||
@@ -52,7 +52,7 @@ env_logger = "0.11"
|
|||||||
half = { "version" = "2.7.1", default-features = false, features = [
|
half = { "version" = "2.7.1", default-features = false, features = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
] }
|
] }
|
||||||
futures = "0"
|
futures = "0.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
metrics = "0.24"
|
metrics = "0.24"
|
||||||
metrics-util = "0.19"
|
metrics-util = "0.19"
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ plugins:
|
|||||||
paths: [../python/python]
|
paths: [../python/python]
|
||||||
options:
|
options:
|
||||||
docstring_style: numpy
|
docstring_style: numpy
|
||||||
|
docstring_options:
|
||||||
|
# Attributes documented in a `Parameters` section, and pydantic
|
||||||
|
# dataclasses whose `__init__` griffe cannot see statically, both
|
||||||
|
# trip this check. It reports nothing actionable here.
|
||||||
|
warn_unknown_params: false
|
||||||
heading_level: 3
|
heading_level: 3
|
||||||
show_signature_annotations: true
|
show_signature_annotations: true
|
||||||
show_root_heading: true
|
show_root_heading: true
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Contributing to LanceDB Typescript
|
# Contributing to LanceDB Typescript
|
||||||
|
|
||||||
This document outlines the process for contributing to LanceDB Typescript.
|
This document outlines the process for contributing to LanceDB Typescript.
|
||||||
For general contribution guidelines, see [CONTRIBUTING.md](../CONTRIBUTING.md).
|
For general contribution guidelines, see [CONTRIBUTING.md](https://github.com/lancedb/lancedb/blob/main/CONTRIBUTING.md).
|
||||||
|
|
||||||
## Project layout
|
## Project layout
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,27 @@ the underlying connection has been closed.
|
|||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
|
### cancelJob()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
abstract cancelJob(jobId): Promise<boolean>
|
||||||
|
```
|
||||||
|
|
||||||
|
Request cancellation of a server-side job by id.
|
||||||
|
|
||||||
|
Resolves to true if the server accepted the cancellation, false if no
|
||||||
|
such job exists. Cancelling an already-terminal job is a no-op success.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
* **jobId**: `string`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<`boolean`>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### cloneTable()
|
### cloneTable()
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
@@ -365,6 +386,26 @@ Drop an existing table.
|
|||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
### getJob()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
abstract getJob(jobId): Promise<null | JobDescription>
|
||||||
|
```
|
||||||
|
|
||||||
|
Describe a single server-side job by id.
|
||||||
|
|
||||||
|
Resolves to `null` when the server has no such job.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
* **jobId**: `string`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<`null` \| [`JobDescription`](../interfaces/JobDescription.md)>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### isOpen()
|
### isOpen()
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
@@ -379,6 +420,62 @@ Return true if the connection has not been closed
|
|||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
### job()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
abstract job(jobId): Job
|
||||||
|
```
|
||||||
|
|
||||||
|
A [Job](Job.md) handle for a server-side job by id.
|
||||||
|
|
||||||
|
The handle is constructed without a server round trip; an unknown id
|
||||||
|
surfaces when the handle is used. Dropping the handle has no effect on
|
||||||
|
the job itself.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
* **jobId**: `string`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
[`Job`](Job.md)
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### jobHistory()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
abstract jobHistory(jobId?): Promise<Table<any>>
|
||||||
|
```
|
||||||
|
|
||||||
|
The lifecycle event history of a server-side job, as an Arrow table.
|
||||||
|
|
||||||
|
Lists history across all jobs when `jobId` is omitted.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
* **jobId?**: `string`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<`Table`<`any`>>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### listJobs()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
abstract listJobs(): Promise<JobInfo[]>
|
||||||
|
```
|
||||||
|
|
||||||
|
List server-side jobs across the database's tables.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<[`JobInfo`](../interfaces/JobInfo.md)[]>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### listNamespaces()
|
### listNamespaces()
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
[@lancedb/lancedb](../globals.md) / Job
|
||||||
|
|
||||||
|
# Class: Job
|
||||||
|
|
||||||
|
A handle to an operation that may still be running.
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
|
||||||
|
### new Job()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Job(): Job
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
[`Job`](Job.md)
|
||||||
|
|
||||||
|
## Accessors
|
||||||
|
|
||||||
|
### id
|
||||||
|
|
||||||
|
```ts
|
||||||
|
get id(): null | string
|
||||||
|
```
|
||||||
|
|
||||||
|
Identifies the operation on the server that is running it. Operations
|
||||||
|
that run in this process have no server id. The value is opaque.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`null` \| `string`
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
### cancel()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
cancel(): Promise<void>
|
||||||
|
```
|
||||||
|
|
||||||
|
Request cancellation. Cancelling a finished operation is a no-op.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<`void`>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### status()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
status(): Promise<string>
|
||||||
|
```
|
||||||
|
|
||||||
|
The operation's current lifecycle state: "running", "finished",
|
||||||
|
"failed", or "cancelled".
|
||||||
|
|
||||||
|
A point snapshot; unlike [Job.wait](Job.md#wait) it does not block or reject
|
||||||
|
on a terminal failure state. States a newer server reports that this
|
||||||
|
client version does not know pass through as-is.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<`string`>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### wait()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
wait(): Promise<void>
|
||||||
|
```
|
||||||
|
|
||||||
|
Wait until the operation reaches a terminal state.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<`void`>
|
||||||
@@ -295,6 +295,29 @@ await table.createIndex("my_float_col");
|
|||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
### createIndexAsync()
|
||||||
|
|
||||||
|
```ts
|
||||||
|
abstract createIndexAsync(column, options?): Promise<Job>
|
||||||
|
```
|
||||||
|
|
||||||
|
Create an index, returning a handle to the indexing job.
|
||||||
|
|
||||||
|
The job may already be complete when returned; callers must not assume
|
||||||
|
the index exists until [Job.wait](Job.md#wait) resolves.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
* **column**: `string`
|
||||||
|
|
||||||
|
* **options?**: `Partial`<[`IndexOptions`](../interfaces/IndexOptions.md)>
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`<[`Job`](Job.md)>
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### currentBranch()
|
### currentBranch()
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
- [Connection](classes/Connection.md)
|
- [Connection](classes/Connection.md)
|
||||||
- [HeaderProvider](classes/HeaderProvider.md)
|
- [HeaderProvider](classes/HeaderProvider.md)
|
||||||
- [Index](classes/Index.md)
|
- [Index](classes/Index.md)
|
||||||
|
- [Job](classes/Job.md)
|
||||||
- [MakeArrowTableOptions](classes/MakeArrowTableOptions.md)
|
- [MakeArrowTableOptions](classes/MakeArrowTableOptions.md)
|
||||||
- [MatchQuery](classes/MatchQuery.md)
|
- [MatchQuery](classes/MatchQuery.md)
|
||||||
- [MergeInsertBuilder](classes/MergeInsertBuilder.md)
|
- [MergeInsertBuilder](classes/MergeInsertBuilder.md)
|
||||||
@@ -88,6 +89,9 @@
|
|||||||
- [IvfFlatOptions](interfaces/IvfFlatOptions.md)
|
- [IvfFlatOptions](interfaces/IvfFlatOptions.md)
|
||||||
- [IvfPqOptions](interfaces/IvfPqOptions.md)
|
- [IvfPqOptions](interfaces/IvfPqOptions.md)
|
||||||
- [IvfRqOptions](interfaces/IvfRqOptions.md)
|
- [IvfRqOptions](interfaces/IvfRqOptions.md)
|
||||||
|
- [JobDescription](interfaces/JobDescription.md)
|
||||||
|
- [JobFailureInfo](interfaces/JobFailureInfo.md)
|
||||||
|
- [JobInfo](interfaces/JobInfo.md)
|
||||||
- [ListNamespacesOptions](interfaces/ListNamespacesOptions.md)
|
- [ListNamespacesOptions](interfaces/ListNamespacesOptions.md)
|
||||||
- [ListNamespacesResponse](interfaces/ListNamespacesResponse.md)
|
- [ListNamespacesResponse](interfaces/ListNamespacesResponse.md)
|
||||||
- [LsmWriteSpec](interfaces/LsmWriteSpec.md)
|
- [LsmWriteSpec](interfaces/LsmWriteSpec.md)
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
[@lancedb/lancedb](../globals.md) / JobDescription
|
||||||
|
|
||||||
|
# Interface: JobDescription
|
||||||
|
|
||||||
|
A described job from `Connection.getJob`.
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### creationMs
|
||||||
|
|
||||||
|
```ts
|
||||||
|
creationMs: number;
|
||||||
|
```
|
||||||
|
|
||||||
|
When the job was created, in milliseconds since the epoch.
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### failure?
|
||||||
|
|
||||||
|
```ts
|
||||||
|
optional failure: JobFailureInfo;
|
||||||
|
```
|
||||||
|
|
||||||
|
Why the job failed, when the job is failed and the server reports a
|
||||||
|
reason.
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### jobId
|
||||||
|
|
||||||
|
```ts
|
||||||
|
jobId: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### jobType
|
||||||
|
|
||||||
|
```ts
|
||||||
|
jobType: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### specJson?
|
||||||
|
|
||||||
|
```ts
|
||||||
|
optional specJson: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
The job-type-specific specification as a JSON string, when present.
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### state
|
||||||
|
|
||||||
|
```ts
|
||||||
|
state: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
Lifecycle state: "running", "finished", "failed", or "cancelled".
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
[@lancedb/lancedb](../globals.md) / JobFailureInfo
|
||||||
|
|
||||||
|
# Interface: JobFailureInfo
|
||||||
|
|
||||||
|
The server's account of why a job failed.
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### message?
|
||||||
|
|
||||||
|
```ts
|
||||||
|
optional message: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### phase?
|
||||||
|
|
||||||
|
```ts
|
||||||
|
optional phase: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### retryable?
|
||||||
|
|
||||||
|
```ts
|
||||||
|
optional retryable: boolean;
|
||||||
|
```
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
[**@lancedb/lancedb**](../README.md) • **Docs**
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
[@lancedb/lancedb](../globals.md) / JobInfo
|
||||||
|
|
||||||
|
# Interface: JobInfo
|
||||||
|
|
||||||
|
A row from `Connection.listJobs`: one server-side job.
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### createdAtMillis
|
||||||
|
|
||||||
|
```ts
|
||||||
|
createdAtMillis: number;
|
||||||
|
```
|
||||||
|
|
||||||
|
When the job was created, in milliseconds since the epoch.
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### jobId
|
||||||
|
|
||||||
|
```ts
|
||||||
|
jobId: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
The job id -- what `Connection.getJob` and `Connection.cancelJob`
|
||||||
|
accept.
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### jobType
|
||||||
|
|
||||||
|
```ts
|
||||||
|
jobType: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### state
|
||||||
|
|
||||||
|
```ts
|
||||||
|
state: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
Lifecycle state: "running", "finished", "failed", or "cancelled".
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### table
|
||||||
|
|
||||||
|
```ts
|
||||||
|
table: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
The table the job runs against, without URI or namespace.
|
||||||
+114
-49
@@ -26,6 +26,18 @@ is also an [asynchronous API client](#connections-asynchronous).
|
|||||||
|
|
||||||
::: lancedb.db.DBConnection
|
::: lancedb.db.DBConnection
|
||||||
|
|
||||||
|
::: lancedb.Session
|
||||||
|
|
||||||
|
## Namespaces (Synchronous)
|
||||||
|
|
||||||
|
A namespace-backed connection resolves tables through a
|
||||||
|
[Lance namespace](https://lance-format.github.io/lance-namespace/) service instead of
|
||||||
|
listing a storage directory.
|
||||||
|
|
||||||
|
::: lancedb.connect_namespace
|
||||||
|
|
||||||
|
::: lancedb.namespace.LanceNamespaceDBConnection
|
||||||
|
|
||||||
## Tables (Synchronous)
|
## Tables (Synchronous)
|
||||||
|
|
||||||
::: lancedb.table.Table
|
::: lancedb.table.Table
|
||||||
@@ -34,8 +46,12 @@ is also an [asynchronous API client](#connections-asynchronous).
|
|||||||
|
|
||||||
::: lancedb.table.FragmentSummaryStats
|
::: lancedb.table.FragmentSummaryStats
|
||||||
|
|
||||||
|
::: lancedb.table.TableStatistics
|
||||||
|
|
||||||
::: lancedb.table.Tags
|
::: lancedb.table.Tags
|
||||||
|
|
||||||
|
::: lancedb.table.Branches
|
||||||
|
|
||||||
## Expressions
|
## Expressions
|
||||||
|
|
||||||
Type-safe expression builder for filters and projections. Use these instead
|
Type-safe expression builder for filters and projections. Use these instead
|
||||||
@@ -62,29 +78,46 @@ of raw SQL strings with [where][lancedb.query.LanceQueryBuilder.where] and
|
|||||||
|
|
||||||
::: lancedb.query.LanceHybridQueryBuilder
|
::: lancedb.query.LanceHybridQueryBuilder
|
||||||
|
|
||||||
|
::: lancedb.query.LanceEmptyQueryBuilder
|
||||||
|
|
||||||
|
::: lancedb.query.LanceTakeQueryBuilder
|
||||||
|
|
||||||
|
## Full text queries
|
||||||
|
|
||||||
|
Structured full text queries can be passed to
|
||||||
|
[Table.search][lancedb.table.Table.search] or
|
||||||
|
[AsyncTable.search][lancedb.table.AsyncTable.search] in place of a query string,
|
||||||
|
and combined with [BooleanQuery][lancedb.query.BooleanQuery].
|
||||||
|
|
||||||
|
::: lancedb.query.FullTextQuery
|
||||||
|
|
||||||
|
::: lancedb.query.MatchQuery
|
||||||
|
|
||||||
|
::: lancedb.query.PhraseQuery
|
||||||
|
|
||||||
|
::: lancedb.query.BoostQuery
|
||||||
|
|
||||||
|
::: lancedb.query.MultiMatchQuery
|
||||||
|
|
||||||
|
::: lancedb.query.BooleanQuery
|
||||||
|
|
||||||
|
::: lancedb.query.FullTextOperator
|
||||||
|
|
||||||
|
::: lancedb.query.Occur
|
||||||
|
|
||||||
## Embeddings
|
## Embeddings
|
||||||
|
|
||||||
::: lancedb.embeddings.registry.EmbeddingFunctionRegistry
|
::: lancedb.embeddings
|
||||||
|
options:
|
||||||
::: lancedb.embeddings.base.EmbeddingFunctionConfig
|
show_root_heading: false
|
||||||
|
show_root_toc_entry: false
|
||||||
::: lancedb.embeddings.base.EmbeddingFunction
|
|
||||||
|
|
||||||
::: lancedb.embeddings.base.TextEmbeddingFunction
|
|
||||||
|
|
||||||
::: lancedb.embeddings.sentence_transformers.SentenceTransformerEmbeddings
|
|
||||||
|
|
||||||
::: lancedb.embeddings.openai.OpenAIEmbeddings
|
|
||||||
|
|
||||||
::: lancedb.embeddings.open_clip.OpenClipEmbeddings
|
|
||||||
|
|
||||||
## Remote configuration
|
## Remote configuration
|
||||||
|
|
||||||
::: lancedb.remote.ClientConfig
|
::: lancedb.remote
|
||||||
|
options:
|
||||||
::: lancedb.remote.TimeoutConfig
|
show_root_heading: false
|
||||||
|
show_root_toc_entry: false
|
||||||
::: lancedb.remote.RetryConfig
|
|
||||||
|
|
||||||
## Context
|
## Context
|
||||||
|
|
||||||
@@ -122,7 +155,22 @@ tokens = list(lancedb.tokenize("acme makes searchable data",
|
|||||||
custom_stop_words=["acme"]))
|
custom_stop_words=["acme"]))
|
||||||
```
|
```
|
||||||
|
|
||||||
::: lancedb.index.FTS
|
::: lancedb.tokenize
|
||||||
|
|
||||||
|
::: lancedb.FtsToken
|
||||||
|
|
||||||
|
## Blobs
|
||||||
|
|
||||||
|
Blob columns store large binary values out of line so they can be read lazily
|
||||||
|
instead of being materialized with the rest of the row.
|
||||||
|
|
||||||
|
::: lancedb.blob
|
||||||
|
|
||||||
|
::: lancedb.BlobType
|
||||||
|
|
||||||
|
::: lancedb._blob.BlobFile
|
||||||
|
options:
|
||||||
|
show_root_full_path: false
|
||||||
|
|
||||||
## Utilities
|
## Utilities
|
||||||
|
|
||||||
@@ -130,6 +178,14 @@ tokens = list(lancedb.tokenize("acme makes searchable data",
|
|||||||
|
|
||||||
::: lancedb.merge.LanceMergeInsertBuilder
|
::: lancedb.merge.LanceMergeInsertBuilder
|
||||||
|
|
||||||
|
::: lancedb.otel.instrument_lancedb_metrics
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
::: lancedb.exceptions.MissingValueError
|
||||||
|
|
||||||
|
::: lancedb.exceptions.MissingColumnError
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
## Pydantic
|
## Pydantic
|
||||||
@@ -138,19 +194,30 @@ tokens = list(lancedb.tokenize("acme makes searchable data",
|
|||||||
|
|
||||||
::: lancedb.pydantic.vector
|
::: lancedb.pydantic.vector
|
||||||
|
|
||||||
|
::: lancedb.pydantic.Vector
|
||||||
|
|
||||||
|
::: lancedb.pydantic.MultiVector
|
||||||
|
|
||||||
::: lancedb.pydantic.LanceModel
|
::: lancedb.pydantic.LanceModel
|
||||||
|
|
||||||
|
## PyTorch
|
||||||
|
|
||||||
|
::: lancedb.streaming.StreamingDataset
|
||||||
|
|
||||||
|
::: lancedb.permutation.permutation_builder
|
||||||
|
|
||||||
|
::: lancedb.permutation.PermutationBuilder
|
||||||
|
|
||||||
|
::: lancedb.permutation.Permutation
|
||||||
|
|
||||||
|
::: lancedb.permutation.Transforms
|
||||||
|
|
||||||
## Reranking
|
## Reranking
|
||||||
|
|
||||||
::: lancedb.rerankers.linear_combination.LinearCombinationReranker
|
::: lancedb.rerankers
|
||||||
|
options:
|
||||||
::: lancedb.rerankers.cohere.CohereReranker
|
show_root_heading: false
|
||||||
|
show_root_toc_entry: false
|
||||||
::: lancedb.rerankers.colbert.ColbertReranker
|
|
||||||
|
|
||||||
::: lancedb.rerankers.cross_encoder.CrossEncoderReranker
|
|
||||||
|
|
||||||
::: lancedb.rerankers.openai.OpenaiReranker
|
|
||||||
|
|
||||||
## Connections (Asynchronous)
|
## Connections (Asynchronous)
|
||||||
|
|
||||||
@@ -161,6 +228,12 @@ can be used to create, list, or open tables.
|
|||||||
|
|
||||||
::: lancedb.db.AsyncConnection
|
::: lancedb.db.AsyncConnection
|
||||||
|
|
||||||
|
## Namespaces (Asynchronous)
|
||||||
|
|
||||||
|
::: lancedb.connect_namespace_async
|
||||||
|
|
||||||
|
::: lancedb.namespace.AsyncLanceNamespaceDBConnection
|
||||||
|
|
||||||
## Tables (Asynchronous)
|
## Tables (Asynchronous)
|
||||||
|
|
||||||
Table hold your actual data as a collection of records / rows.
|
Table hold your actual data as a collection of records / rows.
|
||||||
@@ -169,32 +242,20 @@ Table hold your actual data as a collection of records / rows.
|
|||||||
|
|
||||||
::: lancedb.table.AsyncTags
|
::: lancedb.table.AsyncTags
|
||||||
|
|
||||||
|
::: lancedb.table.AsyncBranches
|
||||||
|
|
||||||
## Indices (Asynchronous)
|
## Indices (Asynchronous)
|
||||||
|
|
||||||
Indices can be created on a table to speed up queries. This section
|
Indices can be created on a table to speed up queries. This section
|
||||||
lists the indices that LanceDb supports.
|
lists the indices that LanceDb supports.
|
||||||
|
|
||||||
::: lancedb.index.BTree
|
::: lancedb.index
|
||||||
|
options:
|
||||||
::: lancedb.index.Bitmap
|
show_root_heading: false
|
||||||
|
show_root_toc_entry: false
|
||||||
::: lancedb.index.LabelList
|
# `lang_mapping` is defined in the module rather than imported, so it is
|
||||||
|
# picked up despite not being in `__all__`. It is an internal lookup table.
|
||||||
::: lancedb.index.FTS
|
filters: ["!^_", "!^lang_mapping$"]
|
||||||
|
|
||||||
::: lancedb.index.IvfPq
|
|
||||||
|
|
||||||
::: lancedb.index.HnswPq
|
|
||||||
|
|
||||||
::: lancedb.index.HnswSq
|
|
||||||
|
|
||||||
::: lancedb.index.IvfFlat
|
|
||||||
|
|
||||||
::: lancedb.index.IvfSq
|
|
||||||
|
|
||||||
::: lancedb.index.IvfRq
|
|
||||||
|
|
||||||
::: lancedb.index.HnswFlat
|
|
||||||
|
|
||||||
::: lancedb.table.IndexStatistics
|
::: lancedb.table.IndexStatistics
|
||||||
|
|
||||||
@@ -222,3 +283,7 @@ rows nearest to a query vector and can be created with the
|
|||||||
::: lancedb.query.AsyncHybridQuery
|
::: lancedb.query.AsyncHybridQuery
|
||||||
options:
|
options:
|
||||||
inherited_members: true
|
inherited_members: true
|
||||||
|
|
||||||
|
::: lancedb.query.AsyncTakeQuery
|
||||||
|
options:
|
||||||
|
inherited_members: true
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<arrow.version>15.0.0</arrow.version>
|
<arrow.version>15.0.0</arrow.version>
|
||||||
<lance-core.version>10.0.0-beta.5</lance-core.version>
|
<lance-core.version>11.0.0-beta.2</lance-core.version>
|
||||||
<spotless.skip>false</spotless.skip>
|
<spotless.skip>false</spotless.skip>
|
||||||
<spotless.version>2.30.0</spotless.version>
|
<spotless.version>2.30.0</spotless.version>
|
||||||
<spotless.java.googlejavaformat.version>1.7</spotless.java.googlejavaformat.version>
|
<spotless.java.googlejavaformat.version>1.7</spotless.java.googlejavaformat.version>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Contributing to LanceDB Typescript
|
# Contributing to LanceDB Typescript
|
||||||
|
|
||||||
This document outlines the process for contributing to LanceDB Typescript.
|
This document outlines the process for contributing to LanceDB Typescript.
|
||||||
For general contribution guidelines, see [CONTRIBUTING.md](../CONTRIBUTING.md).
|
For general contribution guidelines, see [CONTRIBUTING.md](https://github.com/lancedb/lancedb/blob/main/CONTRIBUTING.md).
|
||||||
|
|
||||||
## Project layout
|
## Project layout
|
||||||
|
|
||||||
|
|||||||
@@ -197,6 +197,35 @@ describe.each([arrow15, arrow16, arrow17, arrow18])(
|
|||||||
expect(table.getChild("d")?.toJSON()).toEqual([9n, 10n, null]);
|
expect(table.getChild("d")?.toJSON()).toEqual([9n, 10n, null]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("will use a provided FixedSizeList schema with typed array values", function () {
|
||||||
|
const schema = new Schema([
|
||||||
|
new Field("text", new Utf8(), false),
|
||||||
|
new Field(
|
||||||
|
"vector",
|
||||||
|
new FixedSizeList(3, new Field("item", new Float32(), false)),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const table = makeArrowTable(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: "foo",
|
||||||
|
vector: new Float32Array([1, 2, 3]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ schema },
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(table.getChild("text")?.toJSON()).toEqual(["foo"]);
|
||||||
|
expect(
|
||||||
|
table
|
||||||
|
.getChild("vector")
|
||||||
|
?.toJSON()
|
||||||
|
.map((value) => value.toJSON()),
|
||||||
|
).toEqual([[1, 2, 3]]);
|
||||||
|
});
|
||||||
|
|
||||||
it("will assume the column `vector` is FixedSizeList<Float32> by default", async function () {
|
it("will assume the column `vector` is FixedSizeList<Float32> by default", async function () {
|
||||||
const schema = new Schema([
|
const schema = new Schema([
|
||||||
new Field("a", new Float(Precision.DOUBLE), true),
|
new Field("a", new Float(Precision.DOUBLE), true),
|
||||||
|
|||||||
@@ -11,8 +11,11 @@ import {
|
|||||||
Float16,
|
Float16,
|
||||||
Float32,
|
Float32,
|
||||||
Float64,
|
Float64,
|
||||||
|
Int32,
|
||||||
Schema,
|
Schema,
|
||||||
Utf8,
|
Utf8,
|
||||||
|
fromDataToBuffer,
|
||||||
|
tableFromIPC,
|
||||||
} from "../lancedb/arrow";
|
} from "../lancedb/arrow";
|
||||||
import { EmbeddingFunction, LanceSchema } from "../lancedb/embedding";
|
import { EmbeddingFunction, LanceSchema } from "../lancedb/embedding";
|
||||||
import { getRegistry, register } from "../lancedb/embedding/registry";
|
import { getRegistry, register } from "../lancedb/embedding/registry";
|
||||||
@@ -184,6 +187,63 @@ describe("embedding functions", () => {
|
|||||||
const vector0 = JSON.parse(JSON.stringify(arr[0].vector));
|
const vector0 = JSON.parse(JSON.stringify(arr[0].vector));
|
||||||
expect(vector0).toEqual([1, 2, 3]);
|
expect(vector0).toEqual([1, 2, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should append generated vectors to a non-nullable schema", async () => {
|
||||||
|
@register("non_nullable_schema_test")
|
||||||
|
class MockEmbeddingFunction extends EmbeddingFunction<string> {
|
||||||
|
ndims() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
embeddingDataType(): Float {
|
||||||
|
return new Float64();
|
||||||
|
}
|
||||||
|
async computeSourceEmbeddings(data: string[]) {
|
||||||
|
return data.map(() => [1, 2, 3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema = new Schema([
|
||||||
|
new Field("id", new Int32()),
|
||||||
|
new Field("text", new Utf8()),
|
||||||
|
new Field("type", new Utf8()),
|
||||||
|
new Field(
|
||||||
|
"vector",
|
||||||
|
new FixedSizeList(3, new Field("item", new Float64())),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
const func = new MockEmbeddingFunction();
|
||||||
|
const db = await connect(tmpDir.name);
|
||||||
|
const table = await db.createEmptyTable("test_non_nullable", schema, {
|
||||||
|
embeddingFunction: {
|
||||||
|
function: func,
|
||||||
|
sourceColumn: "text",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ id: 1, text: "Carrot", type: "vegetable" },
|
||||||
|
{ id: 2, text: "Apple", type: "fruit" },
|
||||||
|
];
|
||||||
|
const buffer = await fromDataToBuffer(
|
||||||
|
data,
|
||||||
|
undefined,
|
||||||
|
await table.schema(),
|
||||||
|
);
|
||||||
|
const generatedTable = tableFromIPC(buffer);
|
||||||
|
const vectorField = generatedTable.schema.fields.find(
|
||||||
|
(field) => field.name === "vector",
|
||||||
|
);
|
||||||
|
expect(vectorField?.nullable).toBe(false);
|
||||||
|
|
||||||
|
await table.add(data);
|
||||||
|
|
||||||
|
const rows = await table.query().toArray();
|
||||||
|
expect(rows).toHaveLength(2);
|
||||||
|
for (const row of rows) {
|
||||||
|
expect([...row.vector]).toEqual([1, 2, 3]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("should error when appending to a table with an unregistered embedding function", async () => {
|
it("should error when appending to a table with an unregistered embedding function", async () => {
|
||||||
@register("mock")
|
@register("mock")
|
||||||
class MockEmbeddingFunction extends EmbeddingFunction<string> {
|
class MockEmbeddingFunction extends EmbeddingFunction<string> {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
import packageJson = require("../package.json");
|
||||||
|
|
||||||
|
describe("package metadata", () => {
|
||||||
|
it("requires Node.js type declarations compatible with the runtime", () => {
|
||||||
|
expect(packageJson.engines.node).toBe(">= 18");
|
||||||
|
expect(packageJson.peerDependencies["@types/node"]).toBe(">=18");
|
||||||
|
expect(packageJson.peerDependenciesMeta["@types/node"]).toEqual({
|
||||||
|
optional: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -110,6 +110,81 @@ describe("Query outputSchema", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Search pagination", () => {
|
||||||
|
let tmpDir: tmp.DirResult;
|
||||||
|
let table: Table;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
tmpDir = tmp.dirSync({ unsafeCleanup: true });
|
||||||
|
const db = await connect(tmpDir.name);
|
||||||
|
const schema = new Schema([
|
||||||
|
new Field("id", new Int64(), false),
|
||||||
|
new Field("text", new Utf8(), false),
|
||||||
|
new Field(
|
||||||
|
"vector",
|
||||||
|
new FixedSizeList(2, new Field("item", new Float32())),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
const data = makeArrowTable(
|
||||||
|
[
|
||||||
|
{ id: 1n, text: "common", vector: [0, 0] },
|
||||||
|
{ id: 2n, text: "common common", vector: [1, 1] },
|
||||||
|
{ id: 3n, text: "common common common", vector: [2, 2] },
|
||||||
|
{ id: 4n, text: "common common common common", vector: [3, 3] },
|
||||||
|
],
|
||||||
|
{ schema },
|
||||||
|
);
|
||||||
|
table = await db.createTable("test", data);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
tmpDir.removeCallback();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("applies offset after the vector search limit", async () => {
|
||||||
|
const allResults = await table
|
||||||
|
.vectorSearch([0, 0])
|
||||||
|
.select(["id"])
|
||||||
|
.limit(4)
|
||||||
|
.toArray();
|
||||||
|
const secondPage = await table
|
||||||
|
.vectorSearch([0, 0])
|
||||||
|
.select(["id"])
|
||||||
|
.limit(2)
|
||||||
|
.offset(2)
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
expect(allResults).toHaveLength(4);
|
||||||
|
expect(secondPage).toHaveLength(2);
|
||||||
|
expect(secondPage.map((row) => row.id)).toEqual(
|
||||||
|
allResults.slice(2, 4).map((row) => row.id),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("applies offset after the full-text search limit", async () => {
|
||||||
|
await table.createIndex("text", { config: Index.fts() });
|
||||||
|
|
||||||
|
const allResults = await table
|
||||||
|
.search("common", "fts")
|
||||||
|
.select(["id"])
|
||||||
|
.limit(4)
|
||||||
|
.toArray();
|
||||||
|
const secondPage = await table
|
||||||
|
.search("common", "fts")
|
||||||
|
.select(["id"])
|
||||||
|
.limit(2)
|
||||||
|
.offset(2)
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
expect(allResults).toHaveLength(4);
|
||||||
|
expect(secondPage).toHaveLength(2);
|
||||||
|
expect(secondPage.map((row) => row.id)).toEqual(
|
||||||
|
allResults.slice(2, 4).map((row) => row.id),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Query orderBy", () => {
|
describe("Query orderBy", () => {
|
||||||
let tmpDir: tmp.DirResult;
|
let tmpDir: tmp.DirResult;
|
||||||
let table: Table;
|
let table: Table;
|
||||||
|
|||||||
@@ -170,6 +170,38 @@ describe("remote connection", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("surfaces JSON server errors from remote table operations", async () => {
|
||||||
|
await withMockDatabase(
|
||||||
|
(req, res) => {
|
||||||
|
const path = req.url ?? "";
|
||||||
|
if (path.endsWith("/describe/")) {
|
||||||
|
res.writeHead(200, { "Content-Type": "application/json" }).end(
|
||||||
|
JSON.stringify({
|
||||||
|
name: "broken_table",
|
||||||
|
version: 1,
|
||||||
|
schema: { fields: [] },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.endsWith("/count_rows/")) {
|
||||||
|
res
|
||||||
|
.writeHead(400, { "Content-Type": "application/json" })
|
||||||
|
.end(JSON.stringify({ error: "count rows failed" }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.writeHead(404).end();
|
||||||
|
},
|
||||||
|
async (db) => {
|
||||||
|
const table = await db.openTable("broken_table");
|
||||||
|
|
||||||
|
await expect(table.countRows()).rejects.toThrow("count rows failed");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("should pass on requested extra headers", async () => {
|
it("should pass on requested extra headers", async () => {
|
||||||
await withMockDatabase(
|
await withMockDatabase(
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
@@ -877,3 +909,96 @@ describe("remote connection", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("remote connection jobs surface", () => {
|
||||||
|
it("lists, describes, cancels, and reads history", async () => {
|
||||||
|
const { tableFromArrays, tableToIPC } = await import("apache-arrow");
|
||||||
|
const eventsTable = tableFromArrays({ state: ["created", "succeeded"] });
|
||||||
|
const eventsBody = Buffer.from(tableToIPC(eventsTable, "stream"));
|
||||||
|
|
||||||
|
await withMockDatabase(
|
||||||
|
(req, res) => {
|
||||||
|
let body = "";
|
||||||
|
req.on("data", (chunk) => {
|
||||||
|
body += chunk;
|
||||||
|
});
|
||||||
|
req.on("end", () => {
|
||||||
|
const payload = body.length > 0 ? JSON.parse(body) : {};
|
||||||
|
if (req.url === "/v1/jobs/list") {
|
||||||
|
if (payload["page_token"] === undefined) {
|
||||||
|
res
|
||||||
|
.writeHead(200, { "Content-Type": "application/json" })
|
||||||
|
.end(
|
||||||
|
'{"jobs": [{"job_id": "job-1", "table": "t1", ' +
|
||||||
|
'"job_type": "create_index", "state": "in_progress", ' +
|
||||||
|
'"created_at_millis": 1000}], "page_token": "next"}',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
res
|
||||||
|
.writeHead(200, { "Content-Type": "application/json" })
|
||||||
|
.end(
|
||||||
|
'{"jobs": [{"job_id": "job-2", "table": "t2", ' +
|
||||||
|
'"job_type": "create_index", "state": "succeeded", ' +
|
||||||
|
'"created_at_millis": 2000}]}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (req.url === "/v1/jobs/describe") {
|
||||||
|
if (payload["job_id"] !== "job-1") {
|
||||||
|
res.writeHead(404).end("no such job");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res
|
||||||
|
.writeHead(200, { "Content-Type": "application/json" })
|
||||||
|
.end(
|
||||||
|
'{"job_id": "job-1", "job_type": "create_index", ' +
|
||||||
|
'"job_state": "FAILED", "creation_ms": 1000, ' +
|
||||||
|
'"spec": {"column": "vec"}, "failure": {"phase": "execute", ' +
|
||||||
|
'"message": "worker died", "retryable": true}}',
|
||||||
|
);
|
||||||
|
} else if (req.url === "/v1/jobs/cancel") {
|
||||||
|
if (payload["job_id"] !== "job-1") {
|
||||||
|
res.writeHead(404).end("no such job");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res
|
||||||
|
.writeHead(200, { "Content-Type": "application/json" })
|
||||||
|
.end('{"job_id": "job-1"}');
|
||||||
|
} else if (req.url === "/v1/jobs/query_events") {
|
||||||
|
res
|
||||||
|
.writeHead(200, {
|
||||||
|
"Content-Type": "application/vnd.apache.arrow.stream",
|
||||||
|
})
|
||||||
|
.end(eventsBody);
|
||||||
|
} else {
|
||||||
|
res.writeHead(404).end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async (db) => {
|
||||||
|
const jobs = await db.listJobs();
|
||||||
|
expect(jobs.map((job) => job.jobId)).toEqual(["job-1", "job-2"]);
|
||||||
|
expect(jobs[0].state).toEqual("running");
|
||||||
|
expect(jobs[1].state).toEqual("finished");
|
||||||
|
|
||||||
|
const description = await db.getJob("job-1");
|
||||||
|
expect(description?.state).toEqual("failed");
|
||||||
|
expect(JSON.parse(description?.specJson ?? "")).toEqual({
|
||||||
|
column: "vec",
|
||||||
|
});
|
||||||
|
expect(description?.failure?.message).toEqual("worker died");
|
||||||
|
expect(await db.getJob("missing")).toBeNull();
|
||||||
|
|
||||||
|
expect(await db.cancelJob("job-1")).toBe(true);
|
||||||
|
expect(await db.cancelJob("missing")).toBe(false);
|
||||||
|
|
||||||
|
const history = await db.jobHistory("job-1");
|
||||||
|
expect(history.numRows).toEqual(2);
|
||||||
|
|
||||||
|
const job = db.job("job-1");
|
||||||
|
expect(job.id).toEqual("job-1");
|
||||||
|
expect(await job.status()).toEqual("failed");
|
||||||
|
await expect(job.wait()).rejects.toThrow("worker died");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -86,6 +86,44 @@ describe.each([arrow15, arrow16, arrow17, arrow18])(
|
|||||||
await expect(table.countRows()).resolves.toBe(3);
|
await expect(table.countRows()).resolves.toBe(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should support a foreign Float64 vector schema end to end", async () => {
|
||||||
|
const conn = await connect(tmpDir.name);
|
||||||
|
const schema = new arrow.Schema([
|
||||||
|
new arrow.Field("resource_id", new arrow.Int32(), false),
|
||||||
|
new arrow.Field(
|
||||||
|
"vector",
|
||||||
|
new arrow.FixedSizeList(
|
||||||
|
3,
|
||||||
|
new arrow.Field("value", new arrow.Float64(), true),
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
// biome-ignore lint/style/useNamingConvention: matches the reported schema
|
||||||
|
resource_id: 0,
|
||||||
|
vector: [0.1, 0.1, 0.1],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const resources = await conn.createTable("resources", data, { schema });
|
||||||
|
|
||||||
|
const existing = await resources
|
||||||
|
.query()
|
||||||
|
.where("resource_id = 0")
|
||||||
|
.limit(1)
|
||||||
|
.toArray();
|
||||||
|
expect(existing).toHaveLength(1);
|
||||||
|
|
||||||
|
const matched = await resources
|
||||||
|
.search(Float64Array.from(data[0].vector))
|
||||||
|
.limit(1)
|
||||||
|
.toArray();
|
||||||
|
expect(matched).toHaveLength(1);
|
||||||
|
expect(matched[0]["resource_id"]).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it("should support branches", async () => {
|
it("should support branches", async () => {
|
||||||
await table.add([{ id: 1 }]);
|
await table.add([{ id: 1 }]);
|
||||||
expect(await table.countRows()).toBe(1);
|
expect(await table.countRows()).toBe(1);
|
||||||
@@ -851,7 +889,11 @@ describe("When creating an index", () => {
|
|||||||
afterEach(() => tmpDir.removeCallback());
|
afterEach(() => tmpDir.removeCallback());
|
||||||
|
|
||||||
it("should create a vector index on vector columns", async () => {
|
it("should create a vector index on vector columns", async () => {
|
||||||
await tbl.createIndex("vec");
|
const job = await tbl.createIndexAsync("vec");
|
||||||
|
expect(job.id).toBeNull();
|
||||||
|
await job.wait();
|
||||||
|
// Cancelling a job that already finished succeeds and does nothing.
|
||||||
|
await job.cancel();
|
||||||
|
|
||||||
// check index directory
|
// check index directory
|
||||||
const indexDir = path.join(tmpDir.name, "test.lance", "_indices");
|
const indexDir = path.join(tmpDir.name, "test.lance", "_indices");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
import { tableFromIPC } from "apache-arrow";
|
||||||
import {
|
import {
|
||||||
Data,
|
Data,
|
||||||
SchemaLike,
|
SchemaLike,
|
||||||
@@ -20,6 +21,9 @@ import type {
|
|||||||
CreateNamespaceResponse,
|
CreateNamespaceResponse,
|
||||||
DescribeNamespaceResponse,
|
DescribeNamespaceResponse,
|
||||||
DropNamespaceResponse,
|
DropNamespaceResponse,
|
||||||
|
Job,
|
||||||
|
JobDescription,
|
||||||
|
JobInfo,
|
||||||
ListNamespacesResponse,
|
ListNamespacesResponse,
|
||||||
} from "./native";
|
} from "./native";
|
||||||
export type {
|
export type {
|
||||||
@@ -436,6 +440,40 @@ export abstract class Connection {
|
|||||||
newName: string,
|
newName: string,
|
||||||
options?: RenameTableOptions,
|
options?: RenameTableOptions,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Job} handle for a server-side job by id.
|
||||||
|
*
|
||||||
|
* The handle is constructed without a server round trip; an unknown id
|
||||||
|
* surfaces when the handle is used. Dropping the handle has no effect on
|
||||||
|
* the job itself.
|
||||||
|
*/
|
||||||
|
abstract job(jobId: string): Job;
|
||||||
|
|
||||||
|
/** List server-side jobs across the database's tables. */
|
||||||
|
abstract listJobs(): Promise<JobInfo[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describe a single server-side job by id.
|
||||||
|
*
|
||||||
|
* Resolves to `null` when the server has no such job.
|
||||||
|
*/
|
||||||
|
abstract getJob(jobId: string): Promise<JobDescription | null>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request cancellation of a server-side job by id.
|
||||||
|
*
|
||||||
|
* Resolves to true if the server accepted the cancellation, false if no
|
||||||
|
* such job exists. Cancelling an already-terminal job is a no-op success.
|
||||||
|
*/
|
||||||
|
abstract cancelJob(jobId: string): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The lifecycle event history of a server-side job, as an Arrow table.
|
||||||
|
*
|
||||||
|
* Lists history across all jobs when `jobId` is omitted.
|
||||||
|
*/
|
||||||
|
abstract jobHistory(jobId?: string): Promise<ArrowTable>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hideconstructor */
|
/** @hideconstructor */
|
||||||
@@ -722,6 +760,30 @@ export class LocalConnection extends Connection {
|
|||||||
options?.newNamespacePath,
|
options?.newNamespacePath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
job(jobId: string): Job {
|
||||||
|
return this.inner.job(jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async listJobs(): Promise<JobInfo[]> {
|
||||||
|
return this.inner.listJobs();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getJob(jobId: string): Promise<JobDescription | null> {
|
||||||
|
return this.inner.getJob(jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async cancelJob(jobId: string): Promise<boolean> {
|
||||||
|
return this.inner.cancelJob(jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async jobHistory(jobId?: string): Promise<ArrowTable> {
|
||||||
|
const buf = await this.inner.jobHistory(jobId);
|
||||||
|
if (buf.length === 0) {
|
||||||
|
return new ArrowTable();
|
||||||
|
}
|
||||||
|
return tableFromIPC(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -85,7 +85,13 @@ export {
|
|||||||
RenameTableOptions,
|
RenameTableOptions,
|
||||||
} from "./connection";
|
} from "./connection";
|
||||||
|
|
||||||
export { Session } from "./native.js";
|
export {
|
||||||
|
Job,
|
||||||
|
JobDescription,
|
||||||
|
JobFailureInfo,
|
||||||
|
JobInfo,
|
||||||
|
Session,
|
||||||
|
} from "./native.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ExecutableQuery,
|
ExecutableQuery,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
DropColumnsResult,
|
DropColumnsResult,
|
||||||
IndexConfig,
|
IndexConfig,
|
||||||
IndexStatistics,
|
IndexStatistics,
|
||||||
|
Job,
|
||||||
Branches as NativeBranches,
|
Branches as NativeBranches,
|
||||||
OptimizeStats,
|
OptimizeStats,
|
||||||
TableStatistics,
|
TableStatistics,
|
||||||
@@ -358,6 +359,17 @@ export abstract class Table {
|
|||||||
options?: Partial<IndexOptions>,
|
options?: Partial<IndexOptions>,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an index, returning a handle to the indexing job.
|
||||||
|
*
|
||||||
|
* The job may already be complete when returned; callers must not assume
|
||||||
|
* the index exists until {@link Job.wait} resolves.
|
||||||
|
*/
|
||||||
|
abstract createIndexAsync(
|
||||||
|
column: string,
|
||||||
|
options?: Partial<IndexOptions>,
|
||||||
|
): Promise<Job>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop an index from the table.
|
* Drop an index from the table.
|
||||||
*
|
*
|
||||||
@@ -940,6 +952,22 @@ export class LocalTable extends Table {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async createIndexAsync(
|
||||||
|
column: string,
|
||||||
|
options?: Partial<IndexOptions>,
|
||||||
|
): Promise<Job> {
|
||||||
|
// biome-ignore lint/suspicious/noExplicitAny: skip
|
||||||
|
const nativeIndex = (options?.config as any)?.inner;
|
||||||
|
return await this.inner.createIndexAsync(
|
||||||
|
nativeIndex,
|
||||||
|
column,
|
||||||
|
options?.replace,
|
||||||
|
options?.waitTimeoutSeconds,
|
||||||
|
options?.name,
|
||||||
|
options?.train,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async dropIndex(name: string): Promise<void> {
|
async dropIndex(name: string): Promise<void> {
|
||||||
await this.inner.dropIndex(name);
|
await this.inner.dropIndex(name);
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+6
@@ -55,7 +55,13 @@
|
|||||||
"openai": "4.29.2"
|
"openai": "4.29.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
"@types/node": ">=18",
|
||||||
"apache-arrow": ">=15.0.0 <=18.1.0"
|
"apache-arrow": ">=15.0.0 <=18.1.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/node": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@aws-crypto/crc32": {
|
"node_modules/@aws-crypto/crc32": {
|
||||||
|
|||||||
@@ -101,6 +101,12 @@
|
|||||||
"openai": "4.29.2"
|
"openai": "4.29.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
"@types/node": ">=18",
|
||||||
"apache-arrow": ">=15.0.0 <=18.1.0"
|
"apache-arrow": ">=15.0.0 <=18.1.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/node": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,6 +340,69 @@ impl Connection {
|
|||||||
self.get_inner()?.drop_all_tables(&ns).await.default_error()
|
self.get_inner()?.drop_all_tables(&ns).await.default_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A `Job` handle for a server-side job by id.
|
||||||
|
///
|
||||||
|
/// The handle is constructed without a server round trip; an unknown id
|
||||||
|
/// surfaces when the handle is used.
|
||||||
|
#[napi]
|
||||||
|
pub fn job(&self, job_id: String) -> napi::Result<crate::job::Job> {
|
||||||
|
let job = self.get_inner()?.job(job_id).default_error()?;
|
||||||
|
Ok(crate::job::Job::new(job))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List server-side jobs across the database's tables.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn list_jobs(&self) -> napi::Result<Vec<crate::job::JobInfo>> {
|
||||||
|
let jobs = self.get_inner()?.list_jobs().await.default_error()?;
|
||||||
|
Ok(jobs.into_iter().map(Into::into).collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Describe a single server-side job by id. `null` when the server has
|
||||||
|
/// no such job.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn get_job(
|
||||||
|
&self,
|
||||||
|
job_id: String,
|
||||||
|
) -> napi::Result<Option<crate::job::JobDescription>> {
|
||||||
|
let description = self.get_inner()?.get_job(&job_id).await.default_error()?;
|
||||||
|
Ok(description.map(Into::into))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Request cancellation of a server-side job by id. Returns true if the
|
||||||
|
/// server accepted the cancellation, false if no such job exists.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn cancel_job(&self, job_id: String) -> napi::Result<bool> {
|
||||||
|
self.get_inner()?.cancel_job(&job_id).await.default_error()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The lifecycle event history of a server-side job (all jobs when
|
||||||
|
/// `job_id` is null), as an Arrow IPC stream buffer. Empty when there is
|
||||||
|
/// no history.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn job_history(&self, job_id: Option<String>) -> napi::Result<Buffer> {
|
||||||
|
let batches = self
|
||||||
|
.get_inner()?
|
||||||
|
.job_history(job_id.as_deref())
|
||||||
|
.await
|
||||||
|
.default_error()?;
|
||||||
|
let Some(first) = batches.first() else {
|
||||||
|
return Ok(Buffer::from(Vec::<u8>::new()));
|
||||||
|
};
|
||||||
|
let mut out = Vec::new();
|
||||||
|
let mut writer = arrow_ipc::writer::StreamWriter::try_new(&mut out, &first.schema())
|
||||||
|
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
|
||||||
|
for batch in &batches {
|
||||||
|
writer
|
||||||
|
.write(batch)
|
||||||
|
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
|
||||||
|
}
|
||||||
|
writer
|
||||||
|
.finish()
|
||||||
|
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
|
||||||
|
drop(writer);
|
||||||
|
Ok(Buffer::from(out))
|
||||||
|
}
|
||||||
|
|
||||||
#[napi(catch_unwind)]
|
#[napi(catch_unwind)]
|
||||||
/// Describe a namespace and return its properties.
|
/// Describe a namespace and return its properties.
|
||||||
pub async fn describe_namespace(
|
pub async fn describe_namespace(
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use napi_derive::napi;
|
||||||
|
|
||||||
|
use crate::error::NapiErrorExt;
|
||||||
|
|
||||||
|
/// A handle to an operation that may still be running.
|
||||||
|
#[napi]
|
||||||
|
pub struct Job {
|
||||||
|
inner: Arc<lancedb::Job>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Job {
|
||||||
|
pub(crate) fn new(inner: lancedb::Job) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: Arc::new(inner),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
impl Job {
|
||||||
|
/// Identifies the operation on the server that is running it. Operations
|
||||||
|
/// that run in this process have no server id. The value is opaque.
|
||||||
|
#[napi(getter)]
|
||||||
|
pub fn id(&self) -> Option<String> {
|
||||||
|
self.inner.id().map(str::to_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The operation's current lifecycle state: "running", "finished",
|
||||||
|
/// "failed", or "cancelled".
|
||||||
|
///
|
||||||
|
/// A point snapshot; unlike {@link Job.wait} it does not block or reject
|
||||||
|
/// on a terminal failure state. States a newer server reports that this
|
||||||
|
/// client version does not know pass through as-is.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn status(&self) -> napi::Result<String> {
|
||||||
|
self.inner.status().await.default_error()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wait until the operation reaches a terminal state.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn wait(&self) -> napi::Result<()> {
|
||||||
|
self.inner.wait().await.default_error()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Request cancellation. Cancelling a finished operation is a no-op.
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn cancel(&self) -> napi::Result<()> {
|
||||||
|
self.inner.cancel().await.default_error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row from `Connection.listJobs`: one server-side job.
|
||||||
|
#[napi(object)]
|
||||||
|
pub struct JobInfo {
|
||||||
|
/// The job id -- what `Connection.getJob` and `Connection.cancelJob`
|
||||||
|
/// accept.
|
||||||
|
pub job_id: String,
|
||||||
|
/// The table the job runs against, without URI or namespace.
|
||||||
|
pub table: String,
|
||||||
|
pub job_type: String,
|
||||||
|
/// Lifecycle state: "running", "finished", "failed", or "cancelled".
|
||||||
|
pub state: String,
|
||||||
|
/// When the job was created, in milliseconds since the epoch.
|
||||||
|
pub created_at_millis: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<lancedb::database::JobInfo> for JobInfo {
|
||||||
|
fn from(info: lancedb::database::JobInfo) -> Self {
|
||||||
|
Self {
|
||||||
|
job_id: info.job_id,
|
||||||
|
table: info.table,
|
||||||
|
job_type: info.job_type,
|
||||||
|
state: info.state,
|
||||||
|
created_at_millis: info.created_at_millis,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The server's account of why a job failed.
|
||||||
|
#[napi(object)]
|
||||||
|
pub struct JobFailureInfo {
|
||||||
|
pub phase: Option<String>,
|
||||||
|
pub message: Option<String>,
|
||||||
|
pub retryable: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A described job from `Connection.getJob`.
|
||||||
|
#[napi(object)]
|
||||||
|
pub struct JobDescription {
|
||||||
|
pub job_id: String,
|
||||||
|
pub job_type: String,
|
||||||
|
/// Lifecycle state: "running", "finished", "failed", or "cancelled".
|
||||||
|
pub state: String,
|
||||||
|
/// When the job was created, in milliseconds since the epoch.
|
||||||
|
pub creation_ms: i64,
|
||||||
|
/// The job-type-specific specification as a JSON string, when present.
|
||||||
|
pub spec_json: Option<String>,
|
||||||
|
/// Why the job failed, when the job is failed and the server reports a
|
||||||
|
/// reason.
|
||||||
|
pub failure: Option<JobFailureInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<lancedb::database::JobDescription> for JobDescription {
|
||||||
|
fn from(description: lancedb::database::JobDescription) -> Self {
|
||||||
|
Self {
|
||||||
|
job_id: description.job_id,
|
||||||
|
job_type: description.job_type,
|
||||||
|
state: description.state,
|
||||||
|
creation_ms: description.creation_ms,
|
||||||
|
spec_json: (!description.spec.is_null()).then(|| description.spec.to_string()),
|
||||||
|
failure: description.failure.map(|failure| JobFailureInfo {
|
||||||
|
phase: failure.phase,
|
||||||
|
message: failure.message,
|
||||||
|
retryable: failure.retryable,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ mod error;
|
|||||||
mod header;
|
mod header;
|
||||||
mod index;
|
mod index;
|
||||||
mod iterator;
|
mod iterator;
|
||||||
|
mod job;
|
||||||
pub mod merge;
|
pub mod merge;
|
||||||
pub mod otel;
|
pub mod otel;
|
||||||
pub mod permutation;
|
pub mod permutation;
|
||||||
|
|||||||
+39
-2
@@ -168,6 +168,39 @@ impl Table {
|
|||||||
builder.execute().await.default_error()
|
builder.execute().await.default_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[napi(catch_unwind)]
|
||||||
|
pub async fn create_index_async(
|
||||||
|
&self,
|
||||||
|
index: Option<&Index>,
|
||||||
|
column: String,
|
||||||
|
replace: Option<bool>,
|
||||||
|
wait_timeout_s: Option<i64>,
|
||||||
|
name: Option<String>,
|
||||||
|
train: Option<bool>,
|
||||||
|
) -> napi::Result<crate::job::Job> {
|
||||||
|
let lancedb_index = if let Some(index) = index {
|
||||||
|
index.consume()?
|
||||||
|
} else {
|
||||||
|
lancedb::index::Index::Auto
|
||||||
|
};
|
||||||
|
let mut builder = self.inner_ref()?.create_index(&[column], lancedb_index);
|
||||||
|
if let Some(replace) = replace {
|
||||||
|
builder = builder.replace(replace);
|
||||||
|
}
|
||||||
|
if let Some(timeout) = wait_timeout_s {
|
||||||
|
builder =
|
||||||
|
builder.wait_timeout(std::time::Duration::from_secs(timeout.try_into().unwrap()));
|
||||||
|
}
|
||||||
|
if let Some(name) = name {
|
||||||
|
builder = builder.name(name);
|
||||||
|
}
|
||||||
|
if let Some(train) = train {
|
||||||
|
builder = builder.train(train);
|
||||||
|
}
|
||||||
|
let job = builder.execute_async().await.default_error()?;
|
||||||
|
Ok(crate::job::Job::new(job))
|
||||||
|
}
|
||||||
|
|
||||||
#[napi(catch_unwind)]
|
#[napi(catch_unwind)]
|
||||||
pub async fn drop_index(&self, index_name: String) -> napi::Result<()> {
|
pub async fn drop_index(&self, index_name: String) -> napi::Result<()> {
|
||||||
self.inner_ref()?
|
self.inner_ref()?
|
||||||
@@ -306,7 +339,9 @@ impl Table {
|
|||||||
let transforms = NewColumnTransform::SqlExpressions(transforms);
|
let transforms = NewColumnTransform::SqlExpressions(transforms);
|
||||||
let res = self
|
let res = self
|
||||||
.inner_ref()?
|
.inner_ref()?
|
||||||
.add_columns(transforms, None)
|
.add_columns()
|
||||||
|
.transform(transforms)
|
||||||
|
.execute()
|
||||||
.await
|
.await
|
||||||
.default_error()?;
|
.default_error()?;
|
||||||
Ok(res.into())
|
Ok(res.into())
|
||||||
@@ -323,7 +358,9 @@ impl Table {
|
|||||||
let transforms = NewColumnTransform::AllNulls(schema);
|
let transforms = NewColumnTransform::AllNulls(schema);
|
||||||
let res = self
|
let res = self
|
||||||
.inner_ref()?
|
.inner_ref()?
|
||||||
.add_columns(transforms, None)
|
.add_columns()
|
||||||
|
.transform(transforms)
|
||||||
|
.execute()
|
||||||
.await
|
.await
|
||||||
.default_error()?;
|
.default_error()?;
|
||||||
Ok(res.into())
|
Ok(res.into())
|
||||||
|
|||||||
+2
-2
@@ -26,7 +26,7 @@ lance-namespace-impls.workspace = true
|
|||||||
lance-io.workspace = true
|
lance-io.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
pyo3 = { version = "0.28", features = ["extension-module", "abi3-py39", "chrono"] }
|
pyo3 = { version = "0.28", features = ["extension-module", "abi3-py310", "chrono"] }
|
||||||
chrono = { version = "0.4", default-features = false, features = ["clock"] }
|
chrono = { version = "0.4", default-features = false, features = ["clock"] }
|
||||||
pyo3-async-runtimes = { version = "0.28", features = [
|
pyo3-async-runtimes = { version = "0.28", features = [
|
||||||
"attributes",
|
"attributes",
|
||||||
@@ -43,7 +43,7 @@ libc = "0.2"
|
|||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
pyo3-build-config = { version = "0.28", features = [
|
pyo3-build-config = { version = "0.28", features = [
|
||||||
"extension-module",
|
"extension-module",
|
||||||
"abi3-py39",
|
"abi3-py310",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ tests = [
|
|||||||
"pytest-asyncio>=0.21",
|
"pytest-asyncio>=0.21",
|
||||||
"duckdb>=0.9.0",
|
"duckdb>=0.9.0",
|
||||||
"pytz>=2023.3",
|
"pytz>=2023.3",
|
||||||
"polars>=0.19, <=1.3.0",
|
"polars>=0.19, <=1.32.3",
|
||||||
"pyarrow<25",
|
"pyarrow<25",
|
||||||
"pyarrow-stubs>=16.0",
|
"pyarrow-stubs>=16.0",
|
||||||
"pylance==9.0.0rc1",
|
"pylance==9.0.0rc1",
|
||||||
@@ -140,6 +140,7 @@ include = [
|
|||||||
"python/lancedb/remote/errors.py",
|
"python/lancedb/remote/errors.py",
|
||||||
"python/lancedb/embeddings/__init__.py",
|
"python/lancedb/embeddings/__init__.py",
|
||||||
"python/lancedb/_lancedb.pyi",
|
"python/lancedb/_lancedb.pyi",
|
||||||
|
"python/type_tests/connect.py",
|
||||||
]
|
]
|
||||||
exclude = ["python/tests/"]
|
exclude = ["python/tests/"]
|
||||||
pythonVersion = "3.13"
|
pythonVersion = "3.13"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from .remote import ClientConfig
|
|||||||
from .remote.db import RemoteDBConnection
|
from .remote.db import RemoteDBConnection
|
||||||
from .expr import Expr, col, lit, func
|
from .expr import Expr, col, lit, func
|
||||||
from .schema import blob, vector, BlobType
|
from .schema import blob, vector, BlobType
|
||||||
|
from .job import AsyncJob, Job
|
||||||
from .table import AsyncTable, Table
|
from .table import AsyncTable, Table
|
||||||
from .types import BaseTokenizerType
|
from .types import BaseTokenizerType
|
||||||
from ._lancedb import Session
|
from ._lancedb import Session
|
||||||
@@ -500,6 +501,7 @@ __all__ = [
|
|||||||
"connect_namespace",
|
"connect_namespace",
|
||||||
"connect_namespace_async",
|
"connect_namespace_async",
|
||||||
"AsyncConnection",
|
"AsyncConnection",
|
||||||
|
"AsyncJob",
|
||||||
"AsyncLanceNamespaceDBConnection",
|
"AsyncLanceNamespaceDBConnection",
|
||||||
"AsyncTable",
|
"AsyncTable",
|
||||||
"FtsToken",
|
"FtsToken",
|
||||||
@@ -513,6 +515,7 @@ __all__ = [
|
|||||||
"BlobType",
|
"BlobType",
|
||||||
"vector",
|
"vector",
|
||||||
"DBConnection",
|
"DBConnection",
|
||||||
|
"Job",
|
||||||
"LanceDBConnection",
|
"LanceDBConnection",
|
||||||
"LanceNamespaceDBConnection",
|
"LanceNamespaceDBConnection",
|
||||||
"RemoteDBConnection",
|
"RemoteDBConnection",
|
||||||
|
|||||||
@@ -14,14 +14,10 @@ import pyarrow as pa
|
|||||||
from .expr import Expr
|
from .expr import Expr
|
||||||
from .schema import blob_v2_column_paths
|
from .schema import blob_v2_column_paths
|
||||||
from .types import BlobMode, QueryProjection, QueryProjectionSpec
|
from .types import BlobMode, QueryProjection, QueryProjectionSpec
|
||||||
from .util import get_uri_scheme
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from _typeshed import WriteableBuffer
|
from _typeshed import WriteableBuffer
|
||||||
|
|
||||||
from .remote.table import RemoteTable
|
|
||||||
from .table import AsyncTable, Table
|
|
||||||
|
|
||||||
BLOB_MODE_TO_HANDLING = {
|
BLOB_MODE_TO_HANDLING = {
|
||||||
"lazy": "blobs_descriptions",
|
"lazy": "blobs_descriptions",
|
||||||
"bytes": "all_binary",
|
"bytes": "all_binary",
|
||||||
@@ -104,22 +100,6 @@ def validate_blob_mode(blob_mode: BlobMode) -> None:
|
|||||||
raise ValueError(f"blob_mode must be one of {modes}, got {blob_mode!r}")
|
raise ValueError(f"blob_mode must be one of {modes}, got {blob_mode!r}")
|
||||||
|
|
||||||
|
|
||||||
def supports_blob_auto_row_id(table: Table | AsyncTable | RemoteTable) -> bool:
|
|
||||||
"""Blob auto row-id applies to native tables, not LanceDB Cloud."""
|
|
||||||
from .remote.table import RemoteTable
|
|
||||||
|
|
||||||
if isinstance(table, RemoteTable):
|
|
||||||
return False
|
|
||||||
|
|
||||||
inner = getattr(table, "_inner", None)
|
|
||||||
if inner is not None:
|
|
||||||
uri = inner.database().uri
|
|
||||||
if isinstance(uri, str) and get_uri_scheme(uri) == "db":
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def projection_includes_blob_column(
|
def projection_includes_blob_column(
|
||||||
projection: QueryProjection,
|
projection: QueryProjection,
|
||||||
blob_columns: Iterable[str],
|
blob_columns: Iterable[str],
|
||||||
@@ -164,16 +144,14 @@ def v2_projection_needs_row_id(
|
|||||||
|
|
||||||
|
|
||||||
def blob_auto_row_id_for_scan(
|
def blob_auto_row_id_for_scan(
|
||||||
table: Table | AsyncTable | RemoteTable,
|
|
||||||
schema: pa.Schema,
|
schema: pa.Schema,
|
||||||
projection: QueryProjection,
|
projection: QueryProjection,
|
||||||
*,
|
*,
|
||||||
with_row_id: bool | None,
|
with_row_id: bool | None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
"""Auto row-id only applies when the caller said nothing about row ids."""
|
||||||
if with_row_id is not None:
|
if with_row_id is not None:
|
||||||
return False
|
return False
|
||||||
if not supports_blob_auto_row_id(table):
|
|
||||||
return False
|
|
||||||
return v2_projection_needs_row_id(schema, projection, with_row_id=False)
|
return v2_projection_needs_row_id(schema, projection, with_row_id=False)
|
||||||
|
|
||||||
|
|
||||||
@@ -186,6 +164,11 @@ def finalize_blob_query_table(
|
|||||||
) -> pa.Table:
|
) -> pa.Table:
|
||||||
if user_requested_row_id or not blob_auto_row_id:
|
if user_requested_row_id or not blob_auto_row_id:
|
||||||
return tbl
|
return tbl
|
||||||
|
if "_rowid" not in tbl.column_names:
|
||||||
|
# A backend that ignores the row-id request leaves nothing to stash. Hand
|
||||||
|
# back the projection as-is so fetch_blobs raises the error that names the
|
||||||
|
# ways to supply row ids, rather than failing here about a hidden column.
|
||||||
|
return tbl
|
||||||
return stash_auto_row_ids(tbl, blob_paths)
|
return stash_auto_row_ids(tbl, blob_paths)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,13 @@ class Connection(object):
|
|||||||
start_after: Optional[str],
|
start_after: Optional[str],
|
||||||
limit: Optional[int],
|
limit: Optional[int],
|
||||||
) -> list[str]: ... # Deprecated: Use list_tables instead
|
) -> list[str]: ... # Deprecated: Use list_tables instead
|
||||||
|
def job(self, job_id: str) -> Job: ...
|
||||||
|
async def list_jobs(self) -> List[JobInfo]: ...
|
||||||
|
async def get_job(self, job_id: str) -> Optional[JobDescription]: ...
|
||||||
|
async def cancel_job(self, job_id: str) -> bool: ...
|
||||||
|
async def job_history(
|
||||||
|
self, job_id: Optional[str] = None
|
||||||
|
) -> List[pa.RecordBatch]: ...
|
||||||
async def create_table(
|
async def create_table(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
@@ -209,6 +216,47 @@ class BlobFile:
|
|||||||
def read_range(self, offset: int, length: int) -> bytes: ...
|
def read_range(self, offset: int, length: int) -> bytes: ...
|
||||||
def read_up_to(self, length: int) -> bytes: ...
|
def read_up_to(self, length: int) -> bytes: ...
|
||||||
|
|
||||||
|
class Job:
|
||||||
|
@property
|
||||||
|
def id(self) -> Optional[str]: ...
|
||||||
|
async def status(self) -> str: ...
|
||||||
|
async def wait(self) -> None: ...
|
||||||
|
async def cancel(self) -> None: ...
|
||||||
|
|
||||||
|
class JobInfo:
|
||||||
|
@property
|
||||||
|
def job_id(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def table(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def job_type(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def state(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def created_at_millis(self) -> int: ...
|
||||||
|
|
||||||
|
class JobFailureInfo:
|
||||||
|
@property
|
||||||
|
def phase(self) -> Optional[str]: ...
|
||||||
|
@property
|
||||||
|
def message(self) -> Optional[str]: ...
|
||||||
|
@property
|
||||||
|
def retryable(self) -> Optional[bool]: ...
|
||||||
|
|
||||||
|
class JobDescription:
|
||||||
|
@property
|
||||||
|
def job_id(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def job_type(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def state(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def creation_ms(self) -> int: ...
|
||||||
|
@property
|
||||||
|
def spec_json(self) -> Optional[str]: ...
|
||||||
|
@property
|
||||||
|
def failure(self) -> Optional[JobFailureInfo]: ...
|
||||||
|
|
||||||
class Table:
|
class Table:
|
||||||
def name(self) -> str: ...
|
def name(self) -> str: ...
|
||||||
def __repr__(self) -> str: ...
|
def __repr__(self) -> str: ...
|
||||||
@@ -248,6 +296,28 @@ class Table:
|
|||||||
name: Optional[str],
|
name: Optional[str],
|
||||||
train: Optional[bool],
|
train: Optional[bool],
|
||||||
): ...
|
): ...
|
||||||
|
async def create_index_async(
|
||||||
|
self,
|
||||||
|
column: str,
|
||||||
|
index: Union[
|
||||||
|
IvfFlat,
|
||||||
|
IvfSq,
|
||||||
|
IvfPq,
|
||||||
|
HnswPq,
|
||||||
|
HnswSq,
|
||||||
|
HnswFlat,
|
||||||
|
BTree,
|
||||||
|
Bitmap,
|
||||||
|
LabelList,
|
||||||
|
Fm,
|
||||||
|
FTS,
|
||||||
|
],
|
||||||
|
replace: Optional[bool],
|
||||||
|
wait_timeout: Optional[object],
|
||||||
|
*,
|
||||||
|
name: Optional[str],
|
||||||
|
train: Optional[bool],
|
||||||
|
) -> Job: ...
|
||||||
async def list_versions(self) -> List[Dict[str, Any]]: ...
|
async def list_versions(self) -> List[Dict[str, Any]]: ...
|
||||||
async def version(self) -> int: ...
|
async def version(self) -> int: ...
|
||||||
async def checkout(self, version: Union[int, str]): ...
|
async def checkout(self, version: Union[int, str]): ...
|
||||||
|
|||||||
+185
-10
@@ -45,6 +45,7 @@ from lance_namespace.errors import NamespaceNotEmptyError, TableNotFoundError
|
|||||||
|
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from ._lancedb import connect as lancedb_connect # type: ignore
|
from ._lancedb import connect as lancedb_connect # type: ignore
|
||||||
|
from .job import AsyncJob, Job
|
||||||
from .table import (
|
from .table import (
|
||||||
AsyncTable,
|
AsyncTable,
|
||||||
LanceTable,
|
LanceTable,
|
||||||
@@ -63,6 +64,7 @@ if TYPE_CHECKING:
|
|||||||
from .pydantic import LanceModel
|
from .pydantic import LanceModel
|
||||||
|
|
||||||
from ._lancedb import Connection as LanceDbConnection
|
from ._lancedb import Connection as LanceDbConnection
|
||||||
|
from ._lancedb import JobDescription, JobInfo
|
||||||
from .common import DATA, URI
|
from .common import DATA, URI
|
||||||
from .embeddings import EmbeddingFunctionConfig
|
from .embeddings import EmbeddingFunctionConfig
|
||||||
from ._lancedb import Session
|
from ._lancedb import Session
|
||||||
@@ -178,6 +180,51 @@ class DBConnection(EnforceOverrides):
|
|||||||
"Namespace operations are not supported for this connection type"
|
"Namespace operations are not supported for this connection type"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def namespace_exists(self, namespace_id: List[str]) -> bool:
|
||||||
|
"""Check if a namespace exists.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
namespace_id: List[str]
|
||||||
|
The namespace identifier to check.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
True if the namespace exists, False otherwise.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
NotImplementedError
|
||||||
|
If the connection type does not support namespace operations.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(
|
||||||
|
"Namespace operations are not supported for this connection type"
|
||||||
|
)
|
||||||
|
|
||||||
|
def table_exists(self, table_id: List[str]) -> bool:
|
||||||
|
"""Check if a table exists.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
table_id: List[str]
|
||||||
|
The table identifier to check (full path including namespace
|
||||||
|
segments and table name).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
True if the table exists, False otherwise.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
NotImplementedError
|
||||||
|
If the connection type does not support namespace operations.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(
|
||||||
|
"Namespace operations are not supported for this connection type"
|
||||||
|
)
|
||||||
|
|
||||||
def list_tables(
|
def list_tables(
|
||||||
self,
|
self,
|
||||||
namespace_path: Optional[List[str]] = None,
|
namespace_path: Optional[List[str]] = None,
|
||||||
@@ -359,7 +406,7 @@ class DBConnection(EnforceOverrides):
|
|||||||
|
|
||||||
Data is converted to Arrow before being written to disk. For maximum
|
Data is converted to Arrow before being written to disk. For maximum
|
||||||
control over how data is saved, either provide the PyArrow schema to
|
control over how data is saved, either provide the PyArrow schema to
|
||||||
convert to or else provide a [PyArrow Table](pyarrow.Table) directly.
|
convert to or else provide a [PyArrow Table][pyarrow.Table] directly.
|
||||||
|
|
||||||
>>> import pyarrow as pa
|
>>> import pyarrow as pa
|
||||||
>>> custom_schema = pa.schema([
|
>>> custom_schema = pa.schema([
|
||||||
@@ -563,6 +610,46 @@ class DBConnection(EnforceOverrides):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError("serialize is not supported for this connection type")
|
raise NotImplementedError("serialize is not supported for this connection type")
|
||||||
|
|
||||||
|
def job(self, job_id: str) -> Job:
|
||||||
|
"""A [Job][lancedb.job.Job] handle for a server-side job by id.
|
||||||
|
|
||||||
|
The handle is constructed without a server round trip; an unknown id
|
||||||
|
surfaces when the handle is used. Dropping the handle has no effect
|
||||||
|
on the job itself.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError("job is not supported for this connection type")
|
||||||
|
|
||||||
|
def list_jobs(self) -> List[JobInfo]:
|
||||||
|
"""List server-side jobs across the database's tables."""
|
||||||
|
raise NotImplementedError("list_jobs is not supported for this connection type")
|
||||||
|
|
||||||
|
def get_job(self, job_id: str) -> Optional[JobDescription]:
|
||||||
|
"""Describe a single server-side job by id.
|
||||||
|
|
||||||
|
Returns None when the server has no such job.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError("get_job is not supported for this connection type")
|
||||||
|
|
||||||
|
def cancel_job(self, job_id: str) -> bool:
|
||||||
|
"""Request cancellation of a server-side job by id.
|
||||||
|
|
||||||
|
Returns True if the server accepted the cancellation, False if no
|
||||||
|
such job exists. Cancelling an already-terminal job is a no-op
|
||||||
|
success.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(
|
||||||
|
"cancel_job is not supported for this connection type"
|
||||||
|
)
|
||||||
|
|
||||||
|
def job_history(self, job_id: Optional[str] = None) -> List[pa.RecordBatch]:
|
||||||
|
"""The lifecycle event history of a server-side job, as Arrow batches.
|
||||||
|
|
||||||
|
Lists history across all jobs when `job_id` is None.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError(
|
||||||
|
"job_history is not supported for this connection type"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LanceDBConnection(DBConnection):
|
class LanceDBConnection(DBConnection):
|
||||||
"""
|
"""
|
||||||
@@ -620,6 +707,9 @@ class LanceDBConnection(DBConnection):
|
|||||||
self._namespace_client_properties = namespace_client_properties
|
self._namespace_client_properties = namespace_client_properties
|
||||||
if _inner is not None:
|
if _inner is not None:
|
||||||
self._conn = _inner
|
self._conn = _inner
|
||||||
|
# Native-derived wrappers resolve this in their async reconstruction
|
||||||
|
# path so construction never synchronously re-enters LOOP.
|
||||||
|
self._read_consistency_interval = read_consistency_interval
|
||||||
self._cached_namespace_client = None
|
self._cached_namespace_client = None
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -669,11 +759,14 @@ class LanceDBConnection(DBConnection):
|
|||||||
# storage_options. Also, this class really shouldn't be holding any state
|
# storage_options. Also, this class really shouldn't be holding any state
|
||||||
# beyond _conn.
|
# beyond _conn.
|
||||||
self._conn = AsyncConnection(LOOP.run(do_connect()))
|
self._conn = AsyncConnection(LOOP.run(do_connect()))
|
||||||
|
# Keep property access synchronous so debugger introspection cannot wait on
|
||||||
|
# the background loop while that thread is suspended at a breakpoint.
|
||||||
|
self._read_consistency_interval = read_consistency_interval
|
||||||
self._cached_namespace_client: Optional[LanceNamespace] = None
|
self._cached_namespace_client: Optional[LanceNamespace] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def read_consistency_interval(self) -> Optional[timedelta]:
|
def read_consistency_interval(self) -> Optional[timedelta]:
|
||||||
return LOOP.run(self._conn.get_read_consistency_interval())
|
return self._read_consistency_interval
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self) -> Optional[Session]:
|
def session(self) -> Optional[Session]:
|
||||||
@@ -684,15 +777,19 @@ class LanceDBConnection(DBConnection):
|
|||||||
return self._conn.uri
|
return self._conn.uri
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_inner(cls, inner: LanceDbConnection):
|
def from_inner(
|
||||||
return cls(None, _inner=inner)
|
cls,
|
||||||
|
inner: LanceDbConnection,
|
||||||
|
read_consistency_interval: Optional[timedelta],
|
||||||
|
):
|
||||||
|
return cls(
|
||||||
|
None,
|
||||||
|
read_consistency_interval=read_consistency_interval,
|
||||||
|
_inner=inner,
|
||||||
|
)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
val = f"{self.__class__.__name__}(uri={self._conn.uri!r}"
|
return f"{self.__class__.__name__}(uri={self._conn.uri!r})"
|
||||||
if self.read_consistency_interval is not None:
|
|
||||||
val += f", read_consistency_interval={repr(self.read_consistency_interval)}"
|
|
||||||
val += ")"
|
|
||||||
return val
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def serialize(self) -> str:
|
def serialize(self) -> str:
|
||||||
@@ -1129,6 +1226,47 @@ class LanceDBConnection(DBConnection):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@override
|
||||||
|
def job(self, job_id: str) -> Job:
|
||||||
|
"""A [Job][lancedb.job.Job] handle for a server-side job by id.
|
||||||
|
|
||||||
|
The handle is constructed without a server round trip; an unknown id
|
||||||
|
surfaces when the handle is used. Dropping the handle has no effect
|
||||||
|
on the job itself.
|
||||||
|
"""
|
||||||
|
return Job(self._conn.job(job_id))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def list_jobs(self) -> List[JobInfo]:
|
||||||
|
"""List server-side jobs across the database's tables."""
|
||||||
|
return LOOP.run(self._conn.list_jobs())
|
||||||
|
|
||||||
|
@override
|
||||||
|
def get_job(self, job_id: str) -> Optional[JobDescription]:
|
||||||
|
"""Describe a single server-side job by id.
|
||||||
|
|
||||||
|
Returns None when the server has no such job.
|
||||||
|
"""
|
||||||
|
return LOOP.run(self._conn.get_job(job_id))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def cancel_job(self, job_id: str) -> bool:
|
||||||
|
"""Request cancellation of a server-side job by id.
|
||||||
|
|
||||||
|
Returns True if the server accepted the cancellation, False if no
|
||||||
|
such job exists. Cancelling an already-terminal job is a no-op
|
||||||
|
success.
|
||||||
|
"""
|
||||||
|
return LOOP.run(self._conn.cancel_job(job_id))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def job_history(self, job_id: Optional[str] = None) -> List[pa.RecordBatch]:
|
||||||
|
"""The lifecycle event history of a server-side job, as Arrow batches.
|
||||||
|
|
||||||
|
Lists history across all jobs when `job_id` is None.
|
||||||
|
"""
|
||||||
|
return LOOP.run(self._conn.job_history(job_id))
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def namespace_client(self) -> LanceNamespace:
|
def namespace_client(self) -> LanceNamespace:
|
||||||
"""Get the equivalent namespace client for this connection.
|
"""Get the equivalent namespace client for this connection.
|
||||||
@@ -1529,7 +1667,7 @@ class AsyncConnection(object):
|
|||||||
|
|
||||||
Data is converted to Arrow before being written to disk. For maximum
|
Data is converted to Arrow before being written to disk. For maximum
|
||||||
control over how data is saved, either provide the PyArrow schema to
|
control over how data is saved, either provide the PyArrow schema to
|
||||||
convert to or else provide a [PyArrow Table](pyarrow.Table) directly.
|
convert to or else provide a [PyArrow Table][pyarrow.Table] directly.
|
||||||
|
|
||||||
>>> import pyarrow as pa
|
>>> import pyarrow as pa
|
||||||
>>> custom_schema = pa.schema([
|
>>> custom_schema = pa.schema([
|
||||||
@@ -1838,6 +1976,43 @@ class AsyncConnection(object):
|
|||||||
namespace_path = []
|
namespace_path = []
|
||||||
await self._inner.drop_all_tables(namespace_path=namespace_path)
|
await self._inner.drop_all_tables(namespace_path=namespace_path)
|
||||||
|
|
||||||
|
def job(self, job_id: str) -> AsyncJob:
|
||||||
|
"""An [AsyncJob][lancedb.job.AsyncJob] handle for a server-side job
|
||||||
|
by id.
|
||||||
|
|
||||||
|
The handle is constructed without a server round trip; an unknown id
|
||||||
|
surfaces when the handle is used. Dropping the handle has no effect
|
||||||
|
on the job itself.
|
||||||
|
"""
|
||||||
|
return AsyncJob(self._inner.job(job_id))
|
||||||
|
|
||||||
|
async def list_jobs(self) -> List[JobInfo]:
|
||||||
|
"""List server-side jobs across the database's tables."""
|
||||||
|
return await self._inner.list_jobs()
|
||||||
|
|
||||||
|
async def get_job(self, job_id: str) -> Optional[JobDescription]:
|
||||||
|
"""Describe a single server-side job by id.
|
||||||
|
|
||||||
|
Returns None when the server has no such job.
|
||||||
|
"""
|
||||||
|
return await self._inner.get_job(job_id)
|
||||||
|
|
||||||
|
async def cancel_job(self, job_id: str) -> bool:
|
||||||
|
"""Request cancellation of a server-side job by id.
|
||||||
|
|
||||||
|
Returns True if the server accepted the cancellation, False if no
|
||||||
|
such job exists. Cancelling an already-terminal job is a no-op
|
||||||
|
success.
|
||||||
|
"""
|
||||||
|
return await self._inner.cancel_job(job_id)
|
||||||
|
|
||||||
|
async def job_history(self, job_id: Optional[str] = None) -> List[pa.RecordBatch]:
|
||||||
|
"""The lifecycle event history of a server-side job, as Arrow batches.
|
||||||
|
|
||||||
|
Lists history across all jobs when `job_id` is None.
|
||||||
|
"""
|
||||||
|
return await self._inner.job_history(job_id)
|
||||||
|
|
||||||
async def namespace_client(self) -> LanceNamespace:
|
async def namespace_client(self) -> LanceNamespace:
|
||||||
"""Get the equivalent namespace client for this connection.
|
"""Get the equivalent namespace client for this connection.
|
||||||
|
|
||||||
|
|||||||
@@ -21,3 +21,32 @@ from .watsonx import WatsonxEmbeddings
|
|||||||
from .voyageai import VoyageAIEmbeddingFunction
|
from .voyageai import VoyageAIEmbeddingFunction
|
||||||
from .colpali import ColPaliEmbeddings
|
from .colpali import ColPaliEmbeddings
|
||||||
from .siglip import SigLipEmbeddings
|
from .siglip import SigLipEmbeddings
|
||||||
|
|
||||||
|
# The API reference renders this package with a single mkdocstrings directive,
|
||||||
|
# which only picks up names listed here. New embedding functions must be added
|
||||||
|
# to both the imports above and this list, or they will silently go undocumented.
|
||||||
|
__all__ = [
|
||||||
|
"EmbeddingFunction",
|
||||||
|
"EmbeddingFunctionConfig",
|
||||||
|
"TextEmbeddingFunction",
|
||||||
|
"EmbeddingFunctionRegistry",
|
||||||
|
"get_registry",
|
||||||
|
"register",
|
||||||
|
"SentenceTransformerEmbeddings",
|
||||||
|
"OpenAIEmbeddings",
|
||||||
|
"OpenClipEmbeddings",
|
||||||
|
"BedRockText",
|
||||||
|
"CohereEmbeddingFunction",
|
||||||
|
"GeminiText",
|
||||||
|
"GteEmbeddings",
|
||||||
|
"InstructorEmbeddingFunction",
|
||||||
|
"JinaEmbeddings",
|
||||||
|
"OllamaEmbeddings",
|
||||||
|
"TransformersEmbeddingFunction",
|
||||||
|
"ColbertEmbeddings",
|
||||||
|
"VoyageAIEmbeddingFunction",
|
||||||
|
"WatsonxEmbeddings",
|
||||||
|
"ColPaliEmbeddings",
|
||||||
|
"ImageBindEmbeddings",
|
||||||
|
"SigLipEmbeddings",
|
||||||
|
]
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ class CohereEmbeddingFunction(TextEmbeddingFunction):
|
|||||||
query_input_type : str, default "search_query"
|
query_input_type : str, default "search_query"
|
||||||
The input type for the query column in the database
|
The input type for the query column in the database
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
Cohere supports following input types:
|
Cohere supports following input types:
|
||||||
|
|
||||||
| Input Type | Description |
|
| Input Type | Description |
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ class InstructorEmbeddingFunction(TextEmbeddingFunction):
|
|||||||
|
|
||||||
@weak_lru(maxsize=1)
|
@weak_lru(maxsize=1)
|
||||||
def ndims(self):
|
def ndims(self):
|
||||||
model = self.get_model()
|
return len(self.generate_embeddings([[self.source_instruction, "foo"]])[0])
|
||||||
return model.encode("foo").shape[0]
|
|
||||||
|
|
||||||
def compute_query_embeddings(self, query: str, *args, **kwargs) -> List[np.array]:
|
def compute_query_embeddings(self, query: str, *args, **kwargs) -> List[np.array]:
|
||||||
return self.generate_embeddings([[self.query_instruction, query]])
|
return self.generate_embeddings([[self.query_instruction, query]])
|
||||||
|
|||||||
@@ -23,3 +23,15 @@ class MissingColumnError(KeyError):
|
|||||||
return (
|
return (
|
||||||
f"Error: Column '{self.column_name}' does not exist in the DataFrame object"
|
f"Error: Column '{self.column_name}' does not exist in the DataFrame object"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class JobFailedError(RuntimeError):
|
||||||
|
"""Exception raised when an asynchronous job reaches the failed state."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class JobCancelledError(RuntimeError):
|
||||||
|
"""Exception raised when an asynchronous job was cancelled."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ class HnswPq:
|
|||||||
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
|
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
|
||||||
l2 norm is 1), then dot distance is equivalent to the cosine distance.
|
l2 norm is 1), then dot distance is equivalent to the cosine distance.
|
||||||
|
|
||||||
num_partitions, default sqrt(num_rows)
|
num_partitions: int, default sqrt(num_rows)
|
||||||
|
|
||||||
The number of IVF partitions to create.
|
The number of IVF partitions to create.
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ class HnswPq:
|
|||||||
will require too much memory. Each partition becomes its own HNSW graph, so
|
will require too much memory. Each partition becomes its own HNSW graph, so
|
||||||
setting this value higher reduces the peak memory use of training.
|
setting this value higher reduces the peak memory use of training.
|
||||||
|
|
||||||
num_sub_vectors, default is vector dimension / 16
|
num_sub_vectors: int, default is vector dimension / 16
|
||||||
|
|
||||||
Number of sub-vectors of PQ.
|
Number of sub-vectors of PQ.
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ class HnswPq:
|
|||||||
This value controls how much the sub-vectors are compressed. The more bits
|
This value controls how much the sub-vectors are compressed. The more bits
|
||||||
the more accurate the index but the slower search. Only 4 and 8 are supported.
|
the more accurate the index but the slower search. Only 4 and 8 are supported.
|
||||||
|
|
||||||
max_iterations, default 50
|
max_iterations: int, default 50
|
||||||
|
|
||||||
Max iterations to train kmeans.
|
Max iterations to train kmeans.
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ class HnswPq:
|
|||||||
those cases it is unlikely that setting this larger will lead to the index
|
those cases it is unlikely that setting this larger will lead to the index
|
||||||
converging anyways.
|
converging anyways.
|
||||||
|
|
||||||
sample_rate, default 256
|
sample_rate: int, default 256
|
||||||
|
|
||||||
The rate used to calculate the number of training vectors for kmeans.
|
The rate used to calculate the number of training vectors for kmeans.
|
||||||
|
|
||||||
@@ -279,14 +279,14 @@ class HnswPq:
|
|||||||
Increasing this value might improve the quality of the index but in
|
Increasing this value might improve the quality of the index but in
|
||||||
most cases the default should be sufficient.
|
most cases the default should be sufficient.
|
||||||
|
|
||||||
m, default 20
|
m: int, default 20
|
||||||
|
|
||||||
The number of neighbors to select for each vector in the HNSW graph.
|
The number of neighbors to select for each vector in the HNSW graph.
|
||||||
|
|
||||||
This value controls the tradeoff between search speed and accuracy.
|
This value controls the tradeoff between search speed and accuracy.
|
||||||
The higher the value the more accurate the search but the slower it will be.
|
The higher the value the more accurate the search but the slower it will be.
|
||||||
|
|
||||||
ef_construction, default 300
|
ef_construction: int, default 300
|
||||||
|
|
||||||
The number of candidates to evaluate during the construction of the HNSW graph.
|
The number of candidates to evaluate during the construction of the HNSW graph.
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ class HnswPq:
|
|||||||
This value should be set to a value that is not less than `ef` in the
|
This value should be set to a value that is not less than `ef` in the
|
||||||
search phase.
|
search phase.
|
||||||
|
|
||||||
target_partition_size, default is 1,048,576
|
target_partition_size: int, default is 1,048,576
|
||||||
|
|
||||||
The target size of each partition.
|
The target size of each partition.
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ class HnswSq:
|
|||||||
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
|
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
|
||||||
l2 norm is 1), then dot distance is equivalent to the cosine distance.
|
l2 norm is 1), then dot distance is equivalent to the cosine distance.
|
||||||
|
|
||||||
num_partitions, default sqrt(num_rows)
|
num_partitions: int, default sqrt(num_rows)
|
||||||
|
|
||||||
The number of IVF partitions to create.
|
The number of IVF partitions to create.
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ class HnswSq:
|
|||||||
will require too much memory. Each partition becomes its own HNSW graph, so
|
will require too much memory. Each partition becomes its own HNSW graph, so
|
||||||
setting this value higher reduces the peak memory use of training.
|
setting this value higher reduces the peak memory use of training.
|
||||||
|
|
||||||
max_iterations, default 50
|
max_iterations: int, default 50
|
||||||
|
|
||||||
Max iterations to train kmeans.
|
Max iterations to train kmeans.
|
||||||
|
|
||||||
@@ -373,7 +373,7 @@ class HnswSq:
|
|||||||
In those cases it is unlikely that setting this larger will lead to
|
In those cases it is unlikely that setting this larger will lead to
|
||||||
the index converging anyways.
|
the index converging anyways.
|
||||||
|
|
||||||
sample_rate, default 256
|
sample_rate: int, default 256
|
||||||
|
|
||||||
The rate used to calculate the number of training vectors for kmeans.
|
The rate used to calculate the number of training vectors for kmeans.
|
||||||
|
|
||||||
@@ -389,14 +389,14 @@ class HnswSq:
|
|||||||
Increasing this value might improve the quality of the index but in
|
Increasing this value might improve the quality of the index but in
|
||||||
most cases the default should be sufficient.
|
most cases the default should be sufficient.
|
||||||
|
|
||||||
m, default 20
|
m: int, default 20
|
||||||
|
|
||||||
The number of neighbors to select for each vector in the HNSW graph.
|
The number of neighbors to select for each vector in the HNSW graph.
|
||||||
|
|
||||||
This value controls the tradeoff between search speed and accuracy.
|
This value controls the tradeoff between search speed and accuracy.
|
||||||
The higher the value the more accurate the search but the slower it will be.
|
The higher the value the more accurate the search but the slower it will be.
|
||||||
|
|
||||||
ef_construction, default 300
|
ef_construction: int, default 300
|
||||||
|
|
||||||
The number of candidates to evaluate during the construction of the HNSW graph.
|
The number of candidates to evaluate during the construction of the HNSW graph.
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ class HnswSq:
|
|||||||
This value should be set to a value that is not less than `ef` in the search
|
This value should be set to a value that is not less than `ef` in the search
|
||||||
phase.
|
phase.
|
||||||
|
|
||||||
target_partition_size, default is 1,048,576
|
target_partition_size: int, default is 1,048,576
|
||||||
|
|
||||||
The target size of each partition.
|
The target size of each partition.
|
||||||
|
|
||||||
@@ -460,7 +460,7 @@ class HnswFlat:
|
|||||||
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
|
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
|
||||||
l2 norm is 1), then dot distance is equivalent to the cosine distance.
|
l2 norm is 1), then dot distance is equivalent to the cosine distance.
|
||||||
|
|
||||||
num_partitions, default sqrt(num_rows)
|
num_partitions: int, default sqrt(num_rows)
|
||||||
|
|
||||||
The number of IVF partitions to create.
|
The number of IVF partitions to create.
|
||||||
|
|
||||||
@@ -470,18 +470,18 @@ class HnswFlat:
|
|||||||
graph, so setting this value higher reduces the peak memory use of
|
graph, so setting this value higher reduces the peak memory use of
|
||||||
training.
|
training.
|
||||||
|
|
||||||
max_iterations, default 50
|
max_iterations: int, default 50
|
||||||
|
|
||||||
Max iterations to train kmeans.
|
Max iterations to train kmeans.
|
||||||
|
|
||||||
When training an IVF index we use kmeans to calculate the partitions.
|
When training an IVF index we use kmeans to calculate the partitions.
|
||||||
This parameter controls how many iterations of kmeans to run.
|
This parameter controls how many iterations of kmeans to run.
|
||||||
|
|
||||||
sample_rate, default 256
|
sample_rate: int, default 256
|
||||||
|
|
||||||
The rate used to calculate the number of training vectors for kmeans.
|
The rate used to calculate the number of training vectors for kmeans.
|
||||||
|
|
||||||
m, default 20
|
m: int, default 20
|
||||||
|
|
||||||
The number of neighbors to select for each vector in the HNSW graph.
|
The number of neighbors to select for each vector in the HNSW graph.
|
||||||
|
|
||||||
@@ -489,7 +489,7 @@ class HnswFlat:
|
|||||||
The higher the value the more accurate the search but the slower it
|
The higher the value the more accurate the search but the slower it
|
||||||
will be.
|
will be.
|
||||||
|
|
||||||
ef_construction, default 300
|
ef_construction: int, default 300
|
||||||
|
|
||||||
The number of candidates to evaluate during the construction of the HNSW
|
The number of candidates to evaluate during the construction of the HNSW
|
||||||
graph.
|
graph.
|
||||||
@@ -501,7 +501,7 @@ class HnswFlat:
|
|||||||
than 500. This value should be set to a value that is not less than `ef`
|
than 500. This value should be set to a value that is not less than `ef`
|
||||||
in the search phase.
|
in the search phase.
|
||||||
|
|
||||||
target_partition_size, default is 1,048,576
|
target_partition_size: int, default is 1,048,576
|
||||||
|
|
||||||
The target size of each partition.
|
The target size of each partition.
|
||||||
"""
|
"""
|
||||||
@@ -605,7 +605,7 @@ class IvfFlat:
|
|||||||
|
|
||||||
The default value is 256.
|
The default value is 256.
|
||||||
|
|
||||||
target_partition_size, default is 8192
|
target_partition_size: int, default is 8192
|
||||||
|
|
||||||
The target size of each partition.
|
The target size of each partition.
|
||||||
|
|
||||||
@@ -769,7 +769,7 @@ class IvfPq:
|
|||||||
|
|
||||||
The default value is 256.
|
The default value is 256.
|
||||||
|
|
||||||
target_partition_size, default is 8192
|
target_partition_size: int, default is 8192
|
||||||
|
|
||||||
The target size of each partition.
|
The target size of each partition.
|
||||||
|
|
||||||
@@ -830,7 +830,7 @@ class IvfRq:
|
|||||||
sample_rate: int, default 256
|
sample_rate: int, default 256
|
||||||
Controls the number of training vectors: sample_rate * num_partitions.
|
Controls the number of training vectors: sample_rate * num_partitions.
|
||||||
|
|
||||||
target_partition_size, default is 8192
|
target_partition_size: int, default is 8192
|
||||||
Target size of each partition.
|
Target size of each partition.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -845,6 +845,9 @@ class IvfRq:
|
|||||||
accelerator: Optional[str] = None
|
accelerator: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
# The API reference renders this module with a single mkdocstrings directive,
|
||||||
|
# which only picks up names listed here. New public names must be added to this
|
||||||
|
# list, or they will silently go undocumented.
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"BTree",
|
"BTree",
|
||||||
"IvfPq",
|
"IvfPq",
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
"""Handles to operations a server may run asynchronously."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
from datetime import timedelta
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from lancedb.background_loop import LOOP
|
||||||
|
|
||||||
|
from . import _lancedb
|
||||||
|
|
||||||
|
|
||||||
|
class AsyncJob:
|
||||||
|
"""A handle to an operation that may still be running.
|
||||||
|
|
||||||
|
The operation may already be complete when the handle is created.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, inner: Optional["_lancedb.Job"]):
|
||||||
|
self._inner = inner
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self) -> Optional[str]:
|
||||||
|
"""Identifies the operation on the server that is running it.
|
||||||
|
|
||||||
|
Returned for correlating with server logs or the jobs API. Operations
|
||||||
|
that run in this process have no server id and return `None`. The value
|
||||||
|
is opaque: parsing it or storing it to resume the job later is not
|
||||||
|
supported.
|
||||||
|
"""
|
||||||
|
return self._inner.id if self._inner is not None else None
|
||||||
|
|
||||||
|
async def status(self) -> str:
|
||||||
|
"""The operation's current lifecycle state: "running", "finished",
|
||||||
|
"failed", or "cancelled".
|
||||||
|
|
||||||
|
A point snapshot; unlike `wait` it does not block or raise on a
|
||||||
|
terminal failure state. States a newer server reports that this
|
||||||
|
client version does not know pass through as-is.
|
||||||
|
"""
|
||||||
|
if self._inner is None:
|
||||||
|
return "finished"
|
||||||
|
return await self._inner.status()
|
||||||
|
|
||||||
|
async def wait(self, timeout: Optional[timedelta] = None):
|
||||||
|
"""Wait until the operation reaches a terminal state.
|
||||||
|
|
||||||
|
Raises `JobFailedError` if the operation failed, `JobCancelledError`
|
||||||
|
if it was cancelled, and `TimeoutError` if `timeout` elapses first.
|
||||||
|
"""
|
||||||
|
if self._inner is None:
|
||||||
|
return
|
||||||
|
if timeout is None:
|
||||||
|
await self._inner.wait()
|
||||||
|
else:
|
||||||
|
await asyncio.wait_for(self._inner.wait(), timeout.total_seconds())
|
||||||
|
|
||||||
|
async def cancel(self):
|
||||||
|
"""Request cancellation. Cancelling a finished operation is a no-op."""
|
||||||
|
if self._inner is None:
|
||||||
|
return
|
||||||
|
await self._inner.cancel()
|
||||||
|
|
||||||
|
|
||||||
|
class Job:
|
||||||
|
"""Synchronous counterpart of `AsyncJob`."""
|
||||||
|
|
||||||
|
def __init__(self, inner: Optional[AsyncJob]):
|
||||||
|
self._inner = inner
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self) -> Optional[str]:
|
||||||
|
"""Identifies the operation on the server that is running it.
|
||||||
|
|
||||||
|
See :attr:`AsyncJob.id`.
|
||||||
|
"""
|
||||||
|
return self._inner.id if self._inner is not None else None
|
||||||
|
|
||||||
|
def status(self) -> str:
|
||||||
|
"""The operation's current lifecycle state: "running", "finished",
|
||||||
|
"failed", or "cancelled".
|
||||||
|
|
||||||
|
See :meth:`AsyncJob.status`.
|
||||||
|
"""
|
||||||
|
if self._inner is None:
|
||||||
|
return "finished"
|
||||||
|
return LOOP.run(self._inner.status())
|
||||||
|
|
||||||
|
def wait(self, timeout: Optional[timedelta] = None):
|
||||||
|
"""Block until the operation reaches a terminal state.
|
||||||
|
|
||||||
|
Raises `JobFailedError` if the operation failed, `JobCancelledError`
|
||||||
|
if it was cancelled, and `TimeoutError` if `timeout` elapses first.
|
||||||
|
"""
|
||||||
|
if self._inner is None:
|
||||||
|
return
|
||||||
|
LOOP.run(self._inner.wait(timeout))
|
||||||
|
|
||||||
|
def cancel(self):
|
||||||
|
"""Request cancellation. Cancelling a finished operation is a no-op."""
|
||||||
|
if self._inner is None:
|
||||||
|
return
|
||||||
|
LOOP.run(self._inner.cancel())
|
||||||
@@ -92,8 +92,10 @@ class LanceMergeInsertBuilder(object):
|
|||||||
self._when_not_matched_by_source_delete = True
|
self._when_not_matched_by_source_delete = True
|
||||||
if isinstance(condition, Expr):
|
if isinstance(condition, Expr):
|
||||||
self._when_not_matched_by_source_condition_expr = condition._inner
|
self._when_not_matched_by_source_condition_expr = condition._inner
|
||||||
elif condition is not None:
|
self._when_not_matched_by_source_condition = None
|
||||||
|
else:
|
||||||
self._when_not_matched_by_source_condition = condition
|
self._when_not_matched_by_source_condition = condition
|
||||||
|
self._when_not_matched_by_source_condition_expr = None
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def use_index(self, use_index: bool) -> LanceMergeInsertBuilder:
|
def use_index(self, use_index: bool) -> LanceMergeInsertBuilder:
|
||||||
|
|||||||
@@ -38,7 +38,11 @@ from lance_namespace_urllib3_client.models.query_table_request_vector import (
|
|||||||
QueryTableRequestVector,
|
QueryTableRequestVector,
|
||||||
)
|
)
|
||||||
from lance_namespace_urllib3_client.models.string_fts_query import StringFtsQuery
|
from lance_namespace_urllib3_client.models.string_fts_query import StringFtsQuery
|
||||||
from lance_namespace.errors import NamespaceNotEmptyError, TableNotFoundError
|
from lance_namespace.errors import (
|
||||||
|
NamespaceNotEmptyError,
|
||||||
|
NamespaceNotFoundError,
|
||||||
|
TableNotFoundError,
|
||||||
|
)
|
||||||
from lancedb._lancedb import (
|
from lancedb._lancedb import (
|
||||||
connect_namespace as _connect_namespace,
|
connect_namespace as _connect_namespace,
|
||||||
connect_namespace_client as _connect_namespace_client,
|
connect_namespace_client as _connect_namespace_client,
|
||||||
@@ -53,6 +57,8 @@ from lance_namespace import (
|
|||||||
DropNamespaceResponse,
|
DropNamespaceResponse,
|
||||||
ListNamespacesResponse,
|
ListNamespacesResponse,
|
||||||
ListTablesResponse,
|
ListTablesResponse,
|
||||||
|
NamespaceExistsRequest,
|
||||||
|
TableExistsRequest,
|
||||||
)
|
)
|
||||||
from lancedb.table import AsyncTable, LanceTable, Table
|
from lancedb.table import AsyncTable, LanceTable, Table
|
||||||
from lancedb.util import validate_table_name
|
from lancedb.util import validate_table_name
|
||||||
@@ -780,6 +786,51 @@ class LanceNamespaceDBConnection(DBConnection):
|
|||||||
"""
|
"""
|
||||||
return LOOP.run(self._inner.describe_namespace(namespace_path))
|
return LOOP.run(self._inner.describe_namespace(namespace_path))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def namespace_exists(self, namespace_id: List[str]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if a namespace exists.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
namespace_id : List[str]
|
||||||
|
The namespace identifier to check.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
True if the namespace exists, False otherwise.
|
||||||
|
"""
|
||||||
|
request = NamespaceExistsRequest(id=namespace_id)
|
||||||
|
try:
|
||||||
|
self._namespace_client.namespace_exists(request)
|
||||||
|
return True
|
||||||
|
except NamespaceNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@override
|
||||||
|
def table_exists(self, table_id: List[str]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if a table exists.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
table_id : List[str]
|
||||||
|
The table identifier to check (full path including namespace
|
||||||
|
segments and table name).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
True if the table exists, False otherwise.
|
||||||
|
"""
|
||||||
|
request = TableExistsRequest(id=table_id)
|
||||||
|
try:
|
||||||
|
self._namespace_client.table_exists(request)
|
||||||
|
return True
|
||||||
|
except TableNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def list_tables(
|
def list_tables(
|
||||||
self,
|
self,
|
||||||
@@ -1233,6 +1284,49 @@ class AsyncLanceNamespaceDBConnection:
|
|||||||
"""
|
"""
|
||||||
return await self._inner.describe_namespace(namespace_path)
|
return await self._inner.describe_namespace(namespace_path)
|
||||||
|
|
||||||
|
async def namespace_exists(self, namespace_id: List[str]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if a namespace exists.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
namespace_id : List[str]
|
||||||
|
The namespace identifier to check.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
True if the namespace exists, False otherwise.
|
||||||
|
"""
|
||||||
|
request = NamespaceExistsRequest(id=namespace_id)
|
||||||
|
try:
|
||||||
|
self._namespace_client.namespace_exists(request)
|
||||||
|
return True
|
||||||
|
except NamespaceNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
async def table_exists(self, table_id: List[str]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if a table exists.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
table_id : List[str]
|
||||||
|
The table identifier to check (full path including namespace
|
||||||
|
segments and table name).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
True if the table exists, False otherwise.
|
||||||
|
"""
|
||||||
|
request = TableExistsRequest(id=table_id)
|
||||||
|
try:
|
||||||
|
self._namespace_client.table_exists(request)
|
||||||
|
return True
|
||||||
|
except TableNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
async def list_tables(
|
async def list_tables(
|
||||||
self,
|
self,
|
||||||
namespace_path: Optional[List[str]] = None,
|
namespace_path: Optional[List[str]] = None,
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ class PermutationBuilder:
|
|||||||
|
|
||||||
async def do_execute():
|
async def do_execute():
|
||||||
inner_tbl = await self._async.execute()
|
inner_tbl = await self._async.execute()
|
||||||
return LanceTable.from_inner(inner_tbl)
|
return await LanceTable.from_inner(inner_tbl)
|
||||||
|
|
||||||
return LOOP.run(do_execute())
|
return LOOP.run(do_execute())
|
||||||
|
|
||||||
@@ -438,7 +438,8 @@ class Permutation:
|
|||||||
_reader: Optional[PermutationReader] = None,
|
_reader: Optional[PermutationReader] = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Internal constructor. Use [from_tables](#from_tables) instead.
|
Internal constructor. Use
|
||||||
|
[from_tables][lancedb.permutation.Permutation.from_tables] instead.
|
||||||
"""
|
"""
|
||||||
assert base_table is not None, "base_table is required"
|
assert base_table is not None, "base_table is required"
|
||||||
assert selection is not None, "selection is required"
|
assert selection is not None, "selection is required"
|
||||||
@@ -985,8 +986,9 @@ class Permutation:
|
|||||||
types. Conversion of strings, lists, and structs will require creating python
|
types. Conversion of strings, lists, and structs will require creating python
|
||||||
objects and this is not zero-copy.
|
objects and this is not zero-copy.
|
||||||
|
|
||||||
For custom formatting, use [with_transform](#with_transform) which overrides
|
For custom formatting, use
|
||||||
this method.
|
[with_transform][lancedb.permutation.Permutation.with_transform] which
|
||||||
|
overrides this method.
|
||||||
"""
|
"""
|
||||||
assert format is not None, "format is required"
|
assert format is not None, "format is required"
|
||||||
if format == "python":
|
if format == "python":
|
||||||
@@ -1061,7 +1063,8 @@ class Permutation:
|
|||||||
Note: this method returns a new permutation and does not modify `self`
|
Note: this method returns a new permutation and does not modify `self`
|
||||||
It is provided for compatibility with the huggingface Dataset API.
|
It is provided for compatibility with the huggingface Dataset API.
|
||||||
|
|
||||||
Use [with_skip](#with_skip) instead to avoid confusion.
|
Use [with_skip][lancedb.permutation.Permutation.with_skip] instead to
|
||||||
|
avoid confusion.
|
||||||
"""
|
"""
|
||||||
return self.with_skip(skip)
|
return self.with_skip(skip)
|
||||||
|
|
||||||
@@ -1084,7 +1087,8 @@ class Permutation:
|
|||||||
Note: this method returns a new permutation and does not modify `self`
|
Note: this method returns a new permutation and does not modify `self`
|
||||||
It is provided for compatibility with the huggingface Dataset API.
|
It is provided for compatibility with the huggingface Dataset API.
|
||||||
|
|
||||||
Use [with_take](#with_take) instead to avoid confusion.
|
Use [with_take][lancedb.permutation.Permutation.with_take] instead to
|
||||||
|
avoid confusion.
|
||||||
"""
|
"""
|
||||||
return self.with_take(limit)
|
return self.with_take(limit)
|
||||||
|
|
||||||
@@ -1107,7 +1111,8 @@ class Permutation:
|
|||||||
Note: this method returns a new permutation and does not modify `self`
|
Note: this method returns a new permutation and does not modify `self`
|
||||||
It is provided for compatibility with the huggingface Dataset API.
|
It is provided for compatibility with the huggingface Dataset API.
|
||||||
|
|
||||||
Use [with_repeat](#with_repeat) instead to avoid confusion.
|
Use [with_repeat][lancedb.permutation.Permutation.with_repeat] instead
|
||||||
|
to avoid confusion.
|
||||||
"""
|
"""
|
||||||
return self.with_repeat(times)
|
return self.with_repeat(times)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -153,6 +153,16 @@ def Vector(
|
|||||||
return FixedSizeList
|
return FixedSizeList
|
||||||
|
|
||||||
|
|
||||||
|
def _raise_bare_vector_error(*_args):
|
||||||
|
raise TypeError("Vector must be parameterized with a dimension, e.g. Vector(128).")
|
||||||
|
|
||||||
|
|
||||||
|
# Pydantic v1 and v2 otherwise treat the bare Vector factory as a field validator
|
||||||
|
# and inspect its signature, which produces misleading errors about internal types.
|
||||||
|
setattr(Vector, "__get_validators__", _raise_bare_vector_error)
|
||||||
|
setattr(Vector, "__get_pydantic_core_schema__", _raise_bare_vector_error)
|
||||||
|
|
||||||
|
|
||||||
def MultiVector(
|
def MultiVector(
|
||||||
dim: int, value_type: pa.DataType = pa.float32(), nullable: bool = True
|
dim: int, value_type: pa.DataType = pa.float32(), nullable: bool = True
|
||||||
) -> Type:
|
) -> Type:
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ from ._blob import (
|
|||||||
finalize_blob_query_table,
|
finalize_blob_query_table,
|
||||||
replace_v2_blob_columns_with_bytes,
|
replace_v2_blob_columns_with_bytes,
|
||||||
replace_v2_blob_columns_with_bytes_sync,
|
replace_v2_blob_columns_with_bytes_sync,
|
||||||
supports_blob_auto_row_id,
|
|
||||||
validate_blob_mode,
|
validate_blob_mode,
|
||||||
)
|
)
|
||||||
from .types import BlobMode, QueryProjection
|
from .types import BlobMode, QueryProjection
|
||||||
@@ -651,7 +650,8 @@ class Query(pydantic.BaseModel):
|
|||||||
distance_type : Optional[str]
|
distance_type : Optional[str]
|
||||||
the distance type to use for vector search
|
the distance type to use for vector search
|
||||||
|
|
||||||
This can be l2 (default), cosine and dot. See [metric definitions][search] for
|
This can be l2 (default), cosine and dot. See
|
||||||
|
[metric definitions](https://lancedb.com/docs/search/vector-search/) for
|
||||||
more details.
|
more details.
|
||||||
|
|
||||||
If this is not a vector search this will be None.
|
If this is not a vector search this will be None.
|
||||||
@@ -664,8 +664,9 @@ class Query(pydantic.BaseModel):
|
|||||||
|
|
||||||
- A higher number makes search more accurate but also slower.
|
- A higher number makes search more accurate but also slower.
|
||||||
|
|
||||||
- See discussion in [Querying an ANN Index][querying-an-ann-index] for
|
- See discussion in
|
||||||
tuning advice.
|
[Querying an ANN Index](https://lancedb.com/docs/indexing/)
|
||||||
|
for tuning advice.
|
||||||
|
|
||||||
Will be None if this is not a vector search.
|
Will be None if this is not a vector search.
|
||||||
refine_factor : Optional[int]
|
refine_factor : Optional[int]
|
||||||
@@ -673,8 +674,9 @@ class Query(pydantic.BaseModel):
|
|||||||
|
|
||||||
- A higher number makes search more accurate but also slower.
|
- A higher number makes search more accurate but also slower.
|
||||||
|
|
||||||
- See discussion in [Querying an ANN Index][querying-an-ann-index] for
|
- See discussion in
|
||||||
tuning advice.
|
[Querying an ANN Index](https://lancedb.com/docs/indexing/)
|
||||||
|
for tuning advice.
|
||||||
|
|
||||||
Will be None if this is not a vector search.
|
Will be None if this is not a vector search.
|
||||||
lower_bound : Optional[float]
|
lower_bound : Optional[float]
|
||||||
@@ -1277,10 +1279,7 @@ class LanceQueryBuilder(ABC):
|
|||||||
return self._with_row_id is True
|
return self._with_row_id is True
|
||||||
|
|
||||||
def _blob_auto_row_id_enabled(self) -> bool:
|
def _blob_auto_row_id_enabled(self) -> bool:
|
||||||
if not supports_blob_auto_row_id(self._table):
|
|
||||||
return False
|
|
||||||
return blob_auto_row_id_for_scan(
|
return blob_auto_row_id_for_scan(
|
||||||
self._table,
|
|
||||||
self._table.schema,
|
self._table.schema,
|
||||||
self._columns,
|
self._columns,
|
||||||
with_row_id=self._with_row_id,
|
with_row_id=self._with_row_id,
|
||||||
@@ -1651,8 +1650,8 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
|
|||||||
Higher values will yield better recall (more likely to find vectors if
|
Higher values will yield better recall (more likely to find vectors if
|
||||||
they exist) at the expense of latency.
|
they exist) at the expense of latency.
|
||||||
|
|
||||||
See discussion in [Querying an ANN Index][querying-an-ann-index] for
|
See discussion in [Querying an ANN Index](https://lancedb.com/docs/indexing/)
|
||||||
tuning advice.
|
for tuning advice.
|
||||||
|
|
||||||
This method sets both the minimum and maximum number of probes to the same
|
This method sets both the minimum and maximum number of probes to the same
|
||||||
value. See `minimum_nprobes` and `maximum_nprobes` for more fine-grained
|
value. See `minimum_nprobes` and `maximum_nprobes` for more fine-grained
|
||||||
@@ -1752,8 +1751,8 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
|
|||||||
As an example, a refine factor of 2 will sample 2x as many vectors as
|
As an example, a refine factor of 2 will sample 2x as many vectors as
|
||||||
requested, re-ranks them, and returns the top half most relevant results.
|
requested, re-ranks them, and returns the top half most relevant results.
|
||||||
|
|
||||||
See discussion in [Querying an ANN Index][querying-an-ann-index] for
|
See discussion in [Querying an ANN Index](https://lancedb.com/docs/indexing/)
|
||||||
tuning advice.
|
for tuning advice.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@@ -2698,7 +2697,7 @@ class LanceHybridQueryBuilder(LanceQueryBuilder):
|
|||||||
self._fts_query.phrase_query(True)
|
self._fts_query.phrase_query(True)
|
||||||
if self._distance_type:
|
if self._distance_type:
|
||||||
self._vector_query.metric(self._distance_type)
|
self._vector_query.metric(self._distance_type)
|
||||||
if self._minimum_nprobes:
|
if self._minimum_nprobes is not None:
|
||||||
self._vector_query.minimum_nprobes(self._minimum_nprobes)
|
self._vector_query.minimum_nprobes(self._minimum_nprobes)
|
||||||
if self._maximum_nprobes is not None:
|
if self._maximum_nprobes is not None:
|
||||||
self._vector_query.maximum_nprobes(self._maximum_nprobes)
|
self._vector_query.maximum_nprobes(self._maximum_nprobes)
|
||||||
@@ -2771,7 +2770,7 @@ class AsyncQueryBase(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def _maybe_add_blob_row_id(self) -> None:
|
async def _maybe_add_blob_row_id(self) -> None:
|
||||||
if self._table is None or not supports_blob_auto_row_id(self._table):
|
if self._table is None:
|
||||||
self._blob_auto_row_id = False
|
self._blob_auto_row_id = False
|
||||||
self._blob_paths = ()
|
self._blob_paths = ()
|
||||||
return
|
return
|
||||||
@@ -2779,7 +2778,6 @@ class AsyncQueryBase(object):
|
|||||||
req = self._inner.to_query_request()
|
req = self._inner.to_query_request()
|
||||||
schema = await self._table.schema()
|
schema = await self._table.schema()
|
||||||
self._blob_auto_row_id = blob_auto_row_id_for_scan(
|
self._blob_auto_row_id = blob_auto_row_id_for_scan(
|
||||||
self._table,
|
|
||||||
schema,
|
schema,
|
||||||
req.select,
|
req.select,
|
||||||
with_row_id=self._with_row_id,
|
with_row_id=self._with_row_id,
|
||||||
@@ -3031,7 +3029,6 @@ class AsyncQueryBase(object):
|
|||||||
|
|
||||||
schema = await self._table.schema()
|
schema = await self._table.schema()
|
||||||
blob_auto_row_id = blob_auto_row_id_for_scan(
|
blob_auto_row_id = blob_auto_row_id_for_scan(
|
||||||
self._table,
|
|
||||||
schema,
|
schema,
|
||||||
query.columns,
|
query.columns,
|
||||||
with_row_id=self._with_row_id,
|
with_row_id=self._with_row_id,
|
||||||
@@ -3379,8 +3376,9 @@ class AsyncQuery(AsyncStandardQuery):
|
|||||||
are various ANN search parameters that will let you fine tune your recall
|
are various ANN search parameters that will let you fine tune your recall
|
||||||
accuracy vs search latency.
|
accuracy vs search latency.
|
||||||
|
|
||||||
Vector searches always have a [limit][]. If `limit` has not been called then
|
Vector searches always have a
|
||||||
a default `limit` of 10 will be used.
|
[limit][lancedb.query.AsyncVectorQuery.limit]. If `limit` has not been
|
||||||
|
called then a default `limit` of 10 will be used.
|
||||||
|
|
||||||
Typically, a single vector is passed in as the query. However, you can also
|
Typically, a single vector is passed in as the query. However, you can also
|
||||||
pass in multiple vectors. When multiple vectors are passed in, if the vector
|
pass in multiple vectors. When multiple vectors are passed in, if the vector
|
||||||
@@ -3511,8 +3509,9 @@ class AsyncFTSQuery(AsyncStandardQuery):
|
|||||||
are various ANN search parameters that will let you fine tune your recall
|
are various ANN search parameters that will let you fine tune your recall
|
||||||
accuracy vs search latency.
|
accuracy vs search latency.
|
||||||
|
|
||||||
Hybrid searches always have a [limit][]. If `limit` has not been called then
|
Hybrid searches always have a
|
||||||
a default `limit` of 10 will be used.
|
[limit][lancedb.query.AsyncHybridQuery.limit]. If `limit` has not been
|
||||||
|
called then a default `limit` of 10 will be used.
|
||||||
|
|
||||||
Typically, a single vector is passed in as the query. However, you can also
|
Typically, a single vector is passed in as the query. However, you can also
|
||||||
pass in multiple vectors. This can be useful if you want to find the nearest
|
pass in multiple vectors. This can be useful if you want to find the nearest
|
||||||
@@ -3875,10 +3874,9 @@ class AsyncHybridQuery(AsyncStandardQuery, AsyncVectorQueryBase):
|
|||||||
req = fts_query._inner.to_query_request()
|
req = fts_query._inner.to_query_request()
|
||||||
blob_auto_row_id = False
|
blob_auto_row_id = False
|
||||||
blob_paths: tuple[str, ...] = ()
|
blob_paths: tuple[str, ...] = ()
|
||||||
if self._table is not None and supports_blob_auto_row_id(self._table):
|
if self._table is not None:
|
||||||
schema = await self._table.schema()
|
schema = await self._table.schema()
|
||||||
blob_auto_row_id = blob_auto_row_id_for_scan(
|
blob_auto_row_id = blob_auto_row_id_for_scan(
|
||||||
self._table,
|
|
||||||
schema,
|
schema,
|
||||||
req.select,
|
req.select,
|
||||||
with_row_id=self._with_row_id,
|
with_row_id=self._with_row_id,
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ from lancedb import __version__
|
|||||||
from .header import HeaderProvider
|
from .header import HeaderProvider
|
||||||
from .oauth import OAuthConfig, OAuthFlowType
|
from .oauth import OAuthConfig, OAuthFlowType
|
||||||
|
|
||||||
|
# The API reference renders this module with a single mkdocstrings directive,
|
||||||
|
# which only picks up names listed here. New public names must be added to this
|
||||||
|
# list, or they will silently go undocumented.
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"TimeoutConfig",
|
"TimeoutConfig",
|
||||||
"RetryConfig",
|
"RetryConfig",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Dict, Iterable, List, Optional, Union
|
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
@@ -23,6 +23,10 @@ import pyarrow as pa
|
|||||||
|
|
||||||
from ..common import DATA
|
from ..common import DATA
|
||||||
from ..db import DBConnection, LOOP
|
from ..db import DBConnection, LOOP
|
||||||
|
from ..job import Job
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .._lancedb import JobDescription, JobInfo
|
||||||
from ..embeddings import EmbeddingFunctionConfig
|
from ..embeddings import EmbeddingFunctionConfig
|
||||||
from lance_namespace import (
|
from lance_namespace import (
|
||||||
LanceNamespace,
|
LanceNamespace,
|
||||||
@@ -415,6 +419,11 @@ class RemoteDBConnection(DBConnection):
|
|||||||
|
|
||||||
if namespace_path is None:
|
if namespace_path is None:
|
||||||
namespace_path = []
|
namespace_path = []
|
||||||
|
if storage_options is not None:
|
||||||
|
logging.info(
|
||||||
|
"storage_options is ignored in LanceDb Cloud"
|
||||||
|
" (storage is managed; set storage_options on connect() instead)"
|
||||||
|
)
|
||||||
if index_cache_size is not None:
|
if index_cache_size is not None:
|
||||||
logging.info(
|
logging.info(
|
||||||
"index_cache_size is ignored in LanceDb Cloud"
|
"index_cache_size is ignored in LanceDb Cloud"
|
||||||
@@ -684,6 +693,47 @@ class RemoteDBConnection(DBConnection):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@override
|
||||||
|
def job(self, job_id: str) -> Job:
|
||||||
|
"""A [Job][lancedb.job.Job] handle for a server-side job by id.
|
||||||
|
|
||||||
|
The handle is constructed without a server round trip; an unknown id
|
||||||
|
surfaces when the handle is used. Dropping the handle has no effect
|
||||||
|
on the job itself.
|
||||||
|
"""
|
||||||
|
return Job(self._conn.job(job_id))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def list_jobs(self) -> List["JobInfo"]:
|
||||||
|
"""List server-side jobs across the database's tables."""
|
||||||
|
return LOOP.run(self._conn.list_jobs())
|
||||||
|
|
||||||
|
@override
|
||||||
|
def get_job(self, job_id: str) -> Optional["JobDescription"]:
|
||||||
|
"""Describe a single server-side job by id.
|
||||||
|
|
||||||
|
Returns None when the server has no such job.
|
||||||
|
"""
|
||||||
|
return LOOP.run(self._conn.get_job(job_id))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def cancel_job(self, job_id: str) -> bool:
|
||||||
|
"""Request cancellation of a server-side job by id.
|
||||||
|
|
||||||
|
Returns True if the server accepted the cancellation, False if no
|
||||||
|
such job exists. Cancelling an already-terminal job is a no-op
|
||||||
|
success.
|
||||||
|
"""
|
||||||
|
return LOOP.run(self._conn.cancel_job(job_id))
|
||||||
|
|
||||||
|
@override
|
||||||
|
def job_history(self, job_id: Optional[str] = None) -> List[pa.RecordBatch]:
|
||||||
|
"""The lifecycle event history of a server-side job, as Arrow batches.
|
||||||
|
|
||||||
|
Lists history across all jobs when `job_id` is None.
|
||||||
|
"""
|
||||||
|
return LOOP.run(self._conn.job_history(job_id))
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def namespace_client(self) -> LanceNamespace:
|
def namespace_client(self) -> LanceNamespace:
|
||||||
"""Get the equivalent namespace client for this connection.
|
"""Get the equivalent namespace client for this connection.
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ class RetryError(LanceDBClientError):
|
|||||||
"""An error that occurs when the client has exceeded the maximum number of retries.
|
"""An error that occurs when the client has exceeded the maximum number of retries.
|
||||||
|
|
||||||
The retry strategy can be adjusted by setting the
|
The retry strategy can be adjusted by setting the
|
||||||
[retry_config](lancedb.remote.ClientConfig.retry_config) in the client
|
[retry_config][lancedb.remote.ClientConfig.retry_config] in the client
|
||||||
configuration. This is passed in the `client_config` argument of
|
configuration. This is passed in the `client_config` argument of
|
||||||
[connect](lancedb.connect) and [connect_async](lancedb.connect_async).
|
[connect][lancedb.connect] and [connect_async][lancedb.connect_async].
|
||||||
|
|
||||||
The __cause__ attribute of this exception will be the last exception that
|
The __cause__ attribute of this exception will be the last exception that
|
||||||
caused the retry to fail. It will be an
|
caused the retry to fail. It will be an
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from typing import (
|
|||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from lancedb import __version__
|
from lancedb import __version__
|
||||||
|
from lancedb._blob import BlobFile
|
||||||
|
|
||||||
from lancedb._lancedb import (
|
from lancedb._lancedb import (
|
||||||
AddColumnsResult,
|
AddColumnsResult,
|
||||||
@@ -47,6 +48,7 @@ from lancedb.index import (
|
|||||||
IvfSq,
|
IvfSq,
|
||||||
LabelList,
|
LabelList,
|
||||||
)
|
)
|
||||||
|
from lancedb.job import Job
|
||||||
from lancedb.remote.db import LOOP
|
from lancedb.remote.db import LOOP
|
||||||
from lancedb.table import IndexConfigType, KNOWN_METRICS
|
from lancedb.table import IndexConfigType, KNOWN_METRICS
|
||||||
import pyarrow as pa
|
import pyarrow as pa
|
||||||
@@ -540,6 +542,34 @@ class RemoteTable(Table):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_index_async(
|
||||||
|
self,
|
||||||
|
column: str,
|
||||||
|
*,
|
||||||
|
config: IndexConfigType,
|
||||||
|
replace: Optional[bool] = None,
|
||||||
|
wait_timeout: Optional[timedelta] = None,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
train: bool = True,
|
||||||
|
) -> Job:
|
||||||
|
"""Create an index, returning a handle to the indexing job.
|
||||||
|
|
||||||
|
The job may already be complete when returned; callers must not assume
|
||||||
|
the index exists until :meth:`Job.wait` returns.
|
||||||
|
"""
|
||||||
|
return Job(
|
||||||
|
LOOP.run(
|
||||||
|
self._table.create_index_async(
|
||||||
|
column,
|
||||||
|
replace=replace,
|
||||||
|
config=config,
|
||||||
|
wait_timeout=wait_timeout,
|
||||||
|
name=name,
|
||||||
|
train=train,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _is_legacy_create_index_call(
|
def _is_legacy_create_index_call(
|
||||||
self,
|
self,
|
||||||
first_arg: str,
|
first_arg: str,
|
||||||
@@ -580,8 +610,9 @@ class RemoteTable(Table):
|
|||||||
progress: Optional[Union[bool, Callable, Any]] = None,
|
progress: Optional[Union[bool, Callable, Any]] = None,
|
||||||
write_parallelism: Optional[int] = None,
|
write_parallelism: Optional[int] = None,
|
||||||
) -> AddResult:
|
) -> AddResult:
|
||||||
"""Add more data to the [Table](Table). It has the same API signature as
|
"""Add more data to the [Table][lancedb.table.Table].
|
||||||
the OSS version.
|
|
||||||
|
It has the same API signature as the OSS version.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@@ -641,7 +672,8 @@ class RemoteTable(Table):
|
|||||||
fast_search: bool = False,
|
fast_search: bool = False,
|
||||||
) -> LanceVectorQueryBuilder:
|
) -> LanceVectorQueryBuilder:
|
||||||
"""Create a search query to find the nearest neighbors
|
"""Create a search query to find the nearest neighbors
|
||||||
of the given query vector. We currently support [vector search][search]
|
of the given query vector. We currently support
|
||||||
|
[vector search](https://lancedb.com/docs/search/vector-search/)
|
||||||
|
|
||||||
All query options are defined in
|
All query options are defined in
|
||||||
[LanceVectorQueryBuilder][lancedb.query.LanceVectorQueryBuilder].
|
[LanceVectorQueryBuilder][lancedb.query.LanceVectorQueryBuilder].
|
||||||
@@ -1037,22 +1069,22 @@ class RemoteTable(Table):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def blob_columns(self) -> list[str]:
|
def blob_columns(self) -> list[str]:
|
||||||
raise NotImplementedError(
|
return LOOP.run(self._table.blob_columns())
|
||||||
"blob_columns() is not yet supported on the LanceDB Cloud"
|
|
||||||
)
|
|
||||||
|
|
||||||
def fetch_blobs(self, column: str, row_ids) -> pa.LargeBinaryArray:
|
def fetch_blobs(
|
||||||
raise NotImplementedError("fetch_blobs() is not supported on LanceDB Cloud")
|
self, column: str, row_ids: Union[list[int], pa.Table]
|
||||||
|
) -> pa.LargeBinaryArray:
|
||||||
|
return LOOP.run(self._table.fetch_blobs(column, row_ids))
|
||||||
|
|
||||||
def fetch_blob_ranges(self, column: str, requests) -> pa.LargeBinaryArray:
|
def fetch_blob_ranges(self, column: str, requests) -> pa.LargeBinaryArray:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"fetch_blob_ranges() is not supported on LanceDB Cloud"
|
"fetch_blob_ranges() is not supported on LanceDB Cloud"
|
||||||
)
|
)
|
||||||
|
|
||||||
def fetch_blob_files(self, column: str, row_ids):
|
def fetch_blob_files(
|
||||||
raise NotImplementedError(
|
self, column: str, row_ids: Union[list[int], pa.Table]
|
||||||
"fetch_blob_files() is not supported on LanceDB Cloud"
|
) -> "list[Optional[BlobFile]]":
|
||||||
)
|
return LOOP.run(self._table.fetch_blob_files(column, row_ids))
|
||||||
|
|
||||||
def head(self, n=5) -> pa.Table:
|
def head(self, n=5) -> pa.Table:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ from .answerdotai import AnswerdotaiRerankers
|
|||||||
from .voyageai import VoyageAIReranker
|
from .voyageai import VoyageAIReranker
|
||||||
from .watsonx import WatsonxReranker
|
from .watsonx import WatsonxReranker
|
||||||
|
|
||||||
|
# The API reference renders this module with a single mkdocstrings directive,
|
||||||
|
# which only picks up names listed here. New public names must be added to this
|
||||||
|
# list, or they will silently go undocumented.
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Reranker",
|
"Reranker",
|
||||||
"CrossEncoderReranker",
|
"CrossEncoderReranker",
|
||||||
|
|||||||
+147
-35
@@ -40,6 +40,7 @@ from ._blob import (
|
|||||||
from .types import BlobMode
|
from .types import BlobMode
|
||||||
from lancedb.arrow import peek_reader
|
from lancedb.arrow import peek_reader
|
||||||
from lancedb.background_loop import LOOP, embedding_executor
|
from lancedb.background_loop import LOOP, embedding_executor
|
||||||
|
from lancedb.job import AsyncJob, Job
|
||||||
from .dependencies import (
|
from .dependencies import (
|
||||||
_check_for_hugging_face,
|
_check_for_hugging_face,
|
||||||
_check_for_lance,
|
_check_for_lance,
|
||||||
@@ -107,6 +108,11 @@ def _should_push_down_query_table(
|
|||||||
return namespace_client is not None and "QueryTable" in pushdown_operations
|
return namespace_client is not None and "QueryTable" in pushdown_operations
|
||||||
|
|
||||||
|
|
||||||
|
def _polars_predicate_pushdown_barrier(frame: Any) -> Any:
|
||||||
|
"""Return a Polars frame unchanged while blocking predicate pushdown."""
|
||||||
|
return frame
|
||||||
|
|
||||||
|
|
||||||
_MODEL_BACKED_TOKENIZER_PREFIXES = ("jieba", "lindera")
|
_MODEL_BACKED_TOKENIZER_PREFIXES = ("jieba", "lindera")
|
||||||
_MODEL_BACKED_TOKENIZER_ERRORS = (
|
_MODEL_BACKED_TOKENIZER_ERRORS = (
|
||||||
"unknown base tokenizer",
|
"unknown base tokenizer",
|
||||||
@@ -863,12 +869,18 @@ class Table(ABC):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def to_polars(self, **kwargs) -> "pl.DataFrame":
|
def to_polars(self, **kwargs) -> "pl.LazyFrame":
|
||||||
"""Return the table as a polars.DataFrame.
|
"""Return the table as a Polars LazyFrame.
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
The Polars streaming engine is not supported because it does not currently
|
||||||
|
implement Python PyArrow dataset scans. Use the default engine when collecting
|
||||||
|
this LazyFrame.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
polars.DataFrame
|
polars.LazyFrame
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@@ -977,6 +989,24 @@ class Table(ABC):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def create_index_async(
|
||||||
|
self,
|
||||||
|
column: str,
|
||||||
|
*,
|
||||||
|
config: IndexConfigType,
|
||||||
|
replace: Optional[bool] = None,
|
||||||
|
wait_timeout: Optional[timedelta] = None,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
train: bool = True,
|
||||||
|
) -> Job:
|
||||||
|
"""Create an index, returning a handle to the indexing job.
|
||||||
|
|
||||||
|
Takes the same arguments as :meth:`create_index`. The job may already
|
||||||
|
be complete when returned; callers must not assume the index exists
|
||||||
|
until :meth:`Job.wait` returns.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def drop_index(self, name: str) -> None:
|
def drop_index(self, name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Drop an index from the table.
|
Drop an index from the table.
|
||||||
@@ -1211,7 +1241,7 @@ class Table(ABC):
|
|||||||
progress: Optional[Union[bool, Callable, Any]] = None,
|
progress: Optional[Union[bool, Callable, Any]] = None,
|
||||||
write_parallelism: Optional[int] = None,
|
write_parallelism: Optional[int] = None,
|
||||||
) -> AddResult:
|
) -> AddResult:
|
||||||
"""Add more data to the [Table](Table).
|
"""Add more data to the [Table][lancedb.table.Table].
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@@ -1343,8 +1373,8 @@ class Table(ABC):
|
|||||||
fts_columns: Optional[Union[str, List[str]]] = None,
|
fts_columns: Optional[Union[str, List[str]]] = None,
|
||||||
) -> LanceQueryBuilder:
|
) -> LanceQueryBuilder:
|
||||||
"""Create a search query to find the nearest neighbors
|
"""Create a search query to find the nearest neighbors
|
||||||
of the given query vector. We currently support [vector search][search]
|
of the given query vector. We currently support [vector search](https://lancedb.com/docs/search/vector-search/)
|
||||||
and [full-text search][experimental-full-text-search].
|
and [full-text search](https://lancedb.com/docs/search/full-text-search/).
|
||||||
|
|
||||||
All query options are defined in
|
All query options are defined in
|
||||||
[LanceQueryBuilder][lancedb.query.LanceQueryBuilder].
|
[LanceQueryBuilder][lancedb.query.LanceQueryBuilder].
|
||||||
@@ -1574,8 +1604,10 @@ class Table(ABC):
|
|||||||
"""Open lazy, seekable :class:`~lancedb._blob.BlobFile` handles.
|
"""Open lazy, seekable :class:`~lancedb._blob.BlobFile` handles.
|
||||||
|
|
||||||
Prefer this over :meth:`fetch_blobs` for large payloads. ``row_ids`` is
|
Prefer this over :meth:`fetch_blobs` for large payloads. ``row_ids`` is
|
||||||
a ``list[int]`` or query ``pyarrow.Table`` with ``_rowid`` (or stashed
|
a ``list[int]`` or a query ``pyarrow.Table`` carrying row identity via
|
||||||
row-id metadata). Null rows are ``None``. Local tables only.
|
``_rowid`` or a ``_lance_row_id`` field on the blob descriptor. Null
|
||||||
|
rows are ``None``. Remote tables require LanceDB Cloud server 0.5.0 or
|
||||||
|
newer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -1778,7 +1810,7 @@ class Table(ABC):
|
|||||||
for faster reads.
|
for faster reads.
|
||||||
|
|
||||||
Arguments are passed onto Lance's
|
Arguments are passed onto Lance's
|
||||||
[compact_files][lance.dataset.DatasetOptimizer.compact_files].
|
`lance.dataset.DatasetOptimizer.compact_files`.
|
||||||
For most cases, the default should be fine.
|
For most cases, the default should be fine.
|
||||||
|
|
||||||
See Also
|
See Also
|
||||||
@@ -1832,6 +1864,8 @@ class Table(ABC):
|
|||||||
retrain: bool, default False
|
retrain: bool, default False
|
||||||
This parameter is no longer used and is deprecated.
|
This parameter is no longer used and is deprecated.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
The frequency an application should call optimize is based on the frequency of
|
The frequency an application should call optimize is based on the frequency of
|
||||||
data modifications. If data is frequently added, deleted, or updated then
|
data modifications. If data is frequently added, deleted, or updated then
|
||||||
optimize should be run frequently. A good rule of thumb is to run optimize if
|
optimize should be run frequently. A good rule of thumb is to run optimize if
|
||||||
@@ -1986,15 +2020,14 @@ class Table(ABC):
|
|||||||
change permanent you can use the `[Self::restore]` method.
|
change permanent you can use the `[Self::restore]` method.
|
||||||
|
|
||||||
Any operation that modifies the table will fail while the table is in a checked
|
Any operation that modifies the table will fail while the table is in a checked
|
||||||
out state.
|
out state. To return the table to a normal state use
|
||||||
|
`[Self::checkout_latest]`.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
version: int | str,
|
version: int | str,
|
||||||
The version to check out. A version number (`int`) or a tag
|
The version to check out. A version number (`int`) or a tag
|
||||||
(`str`) can be provided.
|
(`str`) can be provided.
|
||||||
|
|
||||||
To return the table to a normal state use `[Self::checkout_latest]`
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -2160,11 +2193,15 @@ class LanceTable(Table):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_inner(cls, tbl: LanceDBTable):
|
async def from_inner(cls, tbl: LanceDBTable):
|
||||||
from .db import LanceDBConnection
|
from .db import AsyncConnection, LanceDBConnection
|
||||||
|
|
||||||
async_tbl = AsyncTable(tbl)
|
async_tbl = AsyncTable(tbl)
|
||||||
conn = LanceDBConnection.from_inner(tbl.database())
|
inner_conn = tbl.database()
|
||||||
|
read_consistency_interval = await AsyncConnection(
|
||||||
|
inner_conn
|
||||||
|
).get_read_consistency_interval()
|
||||||
|
conn = LanceDBConnection.from_inner(inner_conn, read_consistency_interval)
|
||||||
return cls(
|
return cls(
|
||||||
conn,
|
conn,
|
||||||
async_tbl.name,
|
async_tbl.name,
|
||||||
@@ -2468,13 +2505,7 @@ class LanceTable(Table):
|
|||||||
return LOOP.run(self._table.count_rows(filter))
|
return LOOP.run(self._table.count_rows(filter))
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
val = f"{self.__class__.__name__}(name={self.name!r}"
|
return f"{self.__class__.__name__}(name={self.name!r}, _conn={self._conn!r})"
|
||||||
if self._conn.read_consistency_interval is not None:
|
|
||||||
val += ", read_consistency_interval={!r}".format(
|
|
||||||
self._conn.read_consistency_interval
|
|
||||||
)
|
|
||||||
val += f", _conn={self._conn!r})"
|
|
||||||
return val
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
@@ -2549,6 +2580,9 @@ class LanceTable(Table):
|
|||||||
2. Currently we've disabled push-down of the filters from polars
|
2. Currently we've disabled push-down of the filters from polars
|
||||||
because polars pushdown into pyarrow uses pyarrow compute
|
because polars pushdown into pyarrow uses pyarrow compute
|
||||||
expressions rather than SQl strings (which LanceDB supports)
|
expressions rather than SQl strings (which LanceDB supports)
|
||||||
|
3. The Polars streaming engine is not supported because it does not
|
||||||
|
currently implement Python PyArrow dataset scans. Use the default
|
||||||
|
engine when collecting this LazyFrame.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@@ -2557,8 +2591,12 @@ class LanceTable(Table):
|
|||||||
from lancedb.integrations.pyarrow import PyarrowDatasetAdapter
|
from lancedb.integrations.pyarrow import PyarrowDatasetAdapter
|
||||||
|
|
||||||
dataset = PyarrowDatasetAdapter(self)
|
dataset = PyarrowDatasetAdapter(self)
|
||||||
return pl.scan_pyarrow_dataset(
|
# Polars 1.32's non-PyArrow callback path passes batch_size twice. Keep
|
||||||
dataset, allow_pyarrow_filter=False, batch_size=batch_size
|
# the compatible PyArrow path, but block predicates because this adapter
|
||||||
|
# cannot translate PyArrow expressions into LanceDB filters.
|
||||||
|
return pl.scan_pyarrow_dataset(dataset, batch_size=batch_size).map_batches(
|
||||||
|
_polars_predicate_pushdown_barrier,
|
||||||
|
predicate_pushdown=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# New unified API overload
|
# New unified API overload
|
||||||
@@ -2783,6 +2821,34 @@ class LanceTable(Table):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_index_async(
|
||||||
|
self,
|
||||||
|
column: str,
|
||||||
|
*,
|
||||||
|
config: IndexConfigType,
|
||||||
|
replace: Optional[bool] = None,
|
||||||
|
wait_timeout: Optional[timedelta] = None,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
train: bool = True,
|
||||||
|
) -> Job:
|
||||||
|
"""Create an index, returning a handle to the indexing job.
|
||||||
|
|
||||||
|
The job may already be complete when returned; callers must not assume
|
||||||
|
the index exists until :meth:`Job.wait` returns.
|
||||||
|
"""
|
||||||
|
return Job(
|
||||||
|
LOOP.run(
|
||||||
|
self._table.create_index_async(
|
||||||
|
column,
|
||||||
|
replace=replace,
|
||||||
|
config=config,
|
||||||
|
wait_timeout=wait_timeout,
|
||||||
|
name=name,
|
||||||
|
train=train,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _is_legacy_create_index_call(
|
def _is_legacy_create_index_call(
|
||||||
self,
|
self,
|
||||||
first_arg: str,
|
first_arg: str,
|
||||||
@@ -3387,8 +3453,8 @@ class LanceTable(Table):
|
|||||||
fts_columns: Optional[Union[str, List[str]]] = None,
|
fts_columns: Optional[Union[str, List[str]]] = None,
|
||||||
) -> LanceQueryBuilder:
|
) -> LanceQueryBuilder:
|
||||||
"""Create a search query to find the nearest neighbors
|
"""Create a search query to find the nearest neighbors
|
||||||
of the given query vector. We currently support [vector search][search]
|
of the given query vector. We currently support [vector search](https://lancedb.com/docs/search/vector-search/)
|
||||||
and [full-text search][search].
|
and [full-text search](https://lancedb.com/docs/search/full-text-search/).
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
@@ -3418,8 +3484,9 @@ class LanceTable(Table):
|
|||||||
- *default None*.
|
- *default None*.
|
||||||
Acceptable types are: list, np.ndarray, PIL.Image.Image
|
Acceptable types are: list, np.ndarray, PIL.Image.Image
|
||||||
|
|
||||||
- If None then the select/[where][sql]/limit clauses are applied
|
- If None then the
|
||||||
to filter the table
|
select/[where][lancedb.query.LanceQueryBuilder.where]/limit clauses
|
||||||
|
are applied to filter the table
|
||||||
vector_column_name: str, optional
|
vector_column_name: str, optional
|
||||||
The name of the vector column to search.
|
The name of the vector column to search.
|
||||||
|
|
||||||
@@ -3813,6 +3880,8 @@ class LanceTable(Table):
|
|||||||
retrain: bool, default False
|
retrain: bool, default False
|
||||||
This parameter is no longer used and is deprecated.
|
This parameter is no longer used and is deprecated.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
The frequency an application should call optimize is based on the frequency of
|
The frequency an application should call optimize is based on the frequency of
|
||||||
data modifications. If data is frequently added, deleted, or updated then
|
data modifications. If data is frequently added, deleted, or updated then
|
||||||
optimize should be run frequently. A good rule of thumb is to run optimize if
|
optimize should be run frequently. A good rule of thumb is to run optimize if
|
||||||
@@ -4691,7 +4760,7 @@ class AsyncTable:
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
**kwargs
|
**kwargs
|
||||||
Forwarded to [`lance.dataset`][lance.dataset].
|
Forwarded to `lance.dataset`.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@@ -4867,6 +4936,46 @@ class AsyncTable:
|
|||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
async def create_index_async(
|
||||||
|
self,
|
||||||
|
column: str,
|
||||||
|
*,
|
||||||
|
replace: Optional[bool] = None,
|
||||||
|
config: Optional[
|
||||||
|
Union[
|
||||||
|
IvfFlat,
|
||||||
|
IvfPq,
|
||||||
|
IvfRq,
|
||||||
|
HnswPq,
|
||||||
|
HnswSq,
|
||||||
|
HnswFlat,
|
||||||
|
BTree,
|
||||||
|
Bitmap,
|
||||||
|
LabelList,
|
||||||
|
Fm,
|
||||||
|
FTS,
|
||||||
|
]
|
||||||
|
] = None,
|
||||||
|
wait_timeout: Optional[timedelta] = None,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
train: bool = True,
|
||||||
|
) -> AsyncJob:
|
||||||
|
"""Create an index, returning a handle to the indexing job.
|
||||||
|
|
||||||
|
Takes the same arguments as :meth:`create_index`. The job may already
|
||||||
|
be complete when returned; callers must not assume the index exists
|
||||||
|
until :meth:`AsyncJob.wait` resolves.
|
||||||
|
"""
|
||||||
|
job = await self._inner.create_index_async(
|
||||||
|
column,
|
||||||
|
index=config,
|
||||||
|
replace=replace,
|
||||||
|
wait_timeout=wait_timeout,
|
||||||
|
name=name,
|
||||||
|
train=train,
|
||||||
|
)
|
||||||
|
return AsyncJob(job)
|
||||||
|
|
||||||
async def drop_index(self, name: str) -> None:
|
async def drop_index(self, name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Drop an index from the table.
|
Drop an index from the table.
|
||||||
@@ -5010,7 +5119,7 @@ class AsyncTable:
|
|||||||
progress: Optional[Union[bool, Callable, Any]] = None,
|
progress: Optional[Union[bool, Callable, Any]] = None,
|
||||||
write_parallelism: Optional[int] = None,
|
write_parallelism: Optional[int] = None,
|
||||||
) -> AddResult:
|
) -> AddResult:
|
||||||
"""Add more data to the [Table](Table).
|
"""Add more data to the [AsyncTable][lancedb.table.AsyncTable].
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@@ -5212,8 +5321,8 @@ class AsyncTable:
|
|||||||
fts_columns: Optional[Union[str, List[str]]] = None,
|
fts_columns: Optional[Union[str, List[str]]] = None,
|
||||||
) -> Union[AsyncHybridQuery, AsyncFTSQuery, AsyncVectorQuery]:
|
) -> Union[AsyncHybridQuery, AsyncFTSQuery, AsyncVectorQuery]:
|
||||||
"""Create a search query to find the nearest neighbors
|
"""Create a search query to find the nearest neighbors
|
||||||
of the given query vector. We currently support [vector search][search]
|
of the given query vector. We currently support [vector search](https://lancedb.com/docs/search/vector-search/)
|
||||||
and [full-text search][experimental-full-text-search].
|
and [full-text search](https://lancedb.com/docs/search/full-text-search/).
|
||||||
|
|
||||||
All query options are defined in [AsyncQuery][lancedb.query.AsyncQuery].
|
All query options are defined in [AsyncQuery][lancedb.query.AsyncQuery].
|
||||||
|
|
||||||
@@ -5774,15 +5883,14 @@ class AsyncTable:
|
|||||||
change permanent you can use the `[Self::restore]` method.
|
change permanent you can use the `[Self::restore]` method.
|
||||||
|
|
||||||
Any operation that modifies the table will fail while the table is in a checked
|
Any operation that modifies the table will fail while the table is in a checked
|
||||||
out state.
|
out state. To return the table to a normal state use
|
||||||
|
`[Self::checkout_latest]`.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
version: int | str,
|
version: int | str,
|
||||||
The version to check out. A version number (`int`) or a tag
|
The version to check out. A version number (`int`) or a tag
|
||||||
(`str`) can be provided.
|
(`str`) can be provided.
|
||||||
|
|
||||||
To return the table to a normal state use `[Self::checkout_latest]`
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
await self._inner.checkout(version)
|
await self._inner.checkout(version)
|
||||||
@@ -5966,6 +6074,8 @@ class AsyncTable:
|
|||||||
retrain: bool, default False
|
retrain: bool, default False
|
||||||
This parameter is no longer used and is deprecated.
|
This parameter is no longer used and is deprecated.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
The frequency an application should call optimize is based on the frequency of
|
The frequency an application should call optimize is based on the frequency of
|
||||||
data modifications. If data is frequently added, deleted, or updated then
|
data modifications. If data is frequently added, deleted, or updated then
|
||||||
optimize should be run frequently. A good rule of thumb is to run optimize if
|
optimize should be run frequently. A good rule of thumb is to run optimize if
|
||||||
@@ -6346,6 +6456,8 @@ class Branches:
|
|||||||
dry_run: bool, default False
|
dry_run: bool, default False
|
||||||
When True, only preview. When False, attempt the merge.
|
When True, only preview. When False, attempt the merge.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
A rejected merge returns ``status="rejected"`` instead of raising.
|
A rejected merge returns ``status="rejected"`` instead of raising.
|
||||||
"""
|
"""
|
||||||
return LOOP.run(self._table.branches.merge(from_branch, dry_run))
|
return LOOP.run(self._table.branches.merge(from_branch, dry_run))
|
||||||
|
|||||||
@@ -395,6 +395,11 @@ def _(value: dict):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@value_to_sql.register(pa.Scalar)
|
||||||
|
def _(value: pa.Scalar):
|
||||||
|
return value_to_sql(value.as_py())
|
||||||
|
|
||||||
|
|
||||||
@value_to_sql.register(np.ndarray)
|
@value_to_sql.register(np.ndarray)
|
||||||
def _(value: np.ndarray):
|
def _(value: np.ndarray):
|
||||||
return value_to_sql(value.tolist())
|
return value_to_sql(value.tolist())
|
||||||
|
|||||||
@@ -91,19 +91,13 @@ def test_quickstart(tmp_path):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
# --8<-- [end:alter_columns_vector]
|
# --8<-- [end:alter_columns_vector]
|
||||||
# Change it back since we can get a panic with fp16
|
|
||||||
tbl.alter_columns(
|
|
||||||
{
|
|
||||||
"path": "vector",
|
|
||||||
"data_type": pa.list_(pa.float32(), list_size=2),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
# --8<-- [start:drop_columns]
|
# --8<-- [start:drop_columns]
|
||||||
tbl.drop_columns(["dbl_price"])
|
tbl.drop_columns(["dbl_price"])
|
||||||
# --8<-- [end:drop_columns]
|
# --8<-- [end:drop_columns]
|
||||||
# --8<-- [start:create_index]
|
# --8<-- [start:create_index]
|
||||||
tbl.create_index(num_sub_vectors=1)
|
tbl.create_index(num_sub_vectors=1)
|
||||||
# --8<-- [end:create_index]
|
# --8<-- [end:create_index]
|
||||||
|
tbl.search([100, 100]).limit(2).to_pandas()
|
||||||
# --8<-- [start:delete_rows]
|
# --8<-- [start:delete_rows]
|
||||||
tbl.delete('item = "fizz"')
|
tbl.delete('item = "fizz"')
|
||||||
# --8<-- [end:delete_rows]
|
# --8<-- [end:delete_rows]
|
||||||
@@ -185,13 +179,6 @@ async def test_quickstart_async(tmp_path):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
# --8<-- [end:alter_columns_async_vector]
|
# --8<-- [end:alter_columns_async_vector]
|
||||||
# Change it back since we can get a panic with fp16
|
|
||||||
await tbl.alter_columns(
|
|
||||||
{
|
|
||||||
"path": "vector",
|
|
||||||
"data_type": pa.list_(pa.float32(), list_size=2),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
# --8<-- [start:drop_columns_async]
|
# --8<-- [start:drop_columns_async]
|
||||||
await tbl.drop_columns(["dbl_price"])
|
await tbl.drop_columns(["dbl_price"])
|
||||||
# --8<-- [end:drop_columns_async]
|
# --8<-- [end:drop_columns_async]
|
||||||
@@ -200,6 +187,7 @@ async def test_quickstart_async(tmp_path):
|
|||||||
# --8<-- [start:create_index_async]
|
# --8<-- [start:create_index_async]
|
||||||
await tbl.create_index("vector")
|
await tbl.create_index("vector")
|
||||||
# --8<-- [end:create_index_async]
|
# --8<-- [end:create_index_async]
|
||||||
|
await tbl.vector_search([100, 100]).limit(2).to_pandas()
|
||||||
# --8<-- [start:delete_rows_async]
|
# --8<-- [start:delete_rows_async]
|
||||||
await tbl.delete('item = "fizz"')
|
await tbl.delete('item = "fizz"')
|
||||||
# --8<-- [end:delete_rows_async]
|
# --8<-- [end:delete_rows_async]
|
||||||
|
|||||||
@@ -226,13 +226,13 @@ def test_fetch_blob_ranges_validates_requests():
|
|||||||
table = _blob_table("range_validation", [{"id": 1, "image": b"abc"}])
|
table = _blob_table("range_validation", [{"id": 1, "image": b"abc"}])
|
||||||
row_id = _row_ids_by_id(table)[1]
|
row_id = _row_ids_by_id(table)[1]
|
||||||
|
|
||||||
with pytest.raises(RuntimeError, match="exceeds blob size"):
|
with pytest.raises(ValueError, match="exceeds blob size"):
|
||||||
table.fetch_blob_ranges("image", [(row_id, 2, 2)])
|
table.fetch_blob_ranges("image", [(row_id, 2, 2)])
|
||||||
|
|
||||||
with pytest.raises(RuntimeError, match="offset \\+ length overflowed"):
|
with pytest.raises(ValueError, match="offset \\+ length overflowed"):
|
||||||
table.fetch_blob_ranges("image", [(row_id, 2**64 - 1, 1)])
|
table.fetch_blob_ranges("image", [(row_id, 2**64 - 1, 1)])
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="row ids"):
|
with pytest.raises(ValueError, match="row IDs"):
|
||||||
table.fetch_blob_ranges("image", [(2**64 - 1, 0, 1)])
|
table.fetch_blob_ranges("image", [(2**64 - 1, 0, 1)])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
|
||||||
|
import inspect
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from importlib import resources
|
||||||
import os
|
import os
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
@@ -17,6 +19,10 @@ from lance_namespace.errors import NamespaceNotEmptyError, TableNotFoundError
|
|||||||
from lancedb.pydantic import LanceModel, Vector
|
from lancedb.pydantic import LanceModel, Vector
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_includes_pep_561_marker():
|
||||||
|
assert resources.files(lancedb).joinpath("py.typed").is_file()
|
||||||
|
|
||||||
|
|
||||||
def test_basic(tmp_path):
|
def test_basic(tmp_path):
|
||||||
db = lancedb.connect(tmp_path)
|
db = lancedb.connect(tmp_path)
|
||||||
|
|
||||||
@@ -62,6 +68,44 @@ def test_basic(tmp_path):
|
|||||||
assert db.open_table("test").name == db["test"].name
|
assert db.open_table("test").name == db["test"].name
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_debugger_inspection_does_not_use_background_loop(tmp_path, monkeypatch):
|
||||||
|
from lancedb.background_loop import LOOP
|
||||||
|
|
||||||
|
db = lancedb.connect(tmp_path)
|
||||||
|
table = db.create_table("test", data=[{"id": 1}])
|
||||||
|
|
||||||
|
def fail_run(*args, **kwargs):
|
||||||
|
raise AssertionError("debugger inspection should not use the background loop")
|
||||||
|
|
||||||
|
monkeypatch.setattr(LOOP, "run", fail_run)
|
||||||
|
|
||||||
|
# Debuggers enumerate and evaluate every exposed attribute when expanding a
|
||||||
|
# variable. This must remain safe while their breakpoint suspends LOOP's thread.
|
||||||
|
members = dict(inspect.getmembers(db))
|
||||||
|
|
||||||
|
assert members["uri"] == str(tmp_path)
|
||||||
|
assert members["read_consistency_interval"] is None
|
||||||
|
assert repr(db) == f"LanceDBConnection(uri={str(tmp_path)!r})"
|
||||||
|
assert repr(table) == f"LanceTable(name='test', _conn={db!r})"
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_consistency_interval_does_not_use_background_loop(tmp_path, monkeypatch):
|
||||||
|
from lancedb.background_loop import LOOP
|
||||||
|
from lancedb.db import LanceDBConnection
|
||||||
|
|
||||||
|
consistency_interval = timedelta(seconds=5)
|
||||||
|
db = lancedb.connect(tmp_path, read_consistency_interval=consistency_interval)
|
||||||
|
db_from_inner = LanceDBConnection.from_inner(db._inner, consistency_interval)
|
||||||
|
|
||||||
|
def fail_run(*args, **kwargs):
|
||||||
|
raise AssertionError("properties should not use the Python background loop")
|
||||||
|
|
||||||
|
monkeypatch.setattr(LOOP, "run", fail_run)
|
||||||
|
|
||||||
|
assert db.read_consistency_interval == consistency_interval
|
||||||
|
assert db_from_inner.read_consistency_interval == consistency_interval
|
||||||
|
|
||||||
|
|
||||||
def test_ingest_pd(tmp_path):
|
def test_ingest_pd(tmp_path):
|
||||||
db = lancedb.connect(tmp_path)
|
db = lancedb.connect(tmp_path)
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,23 @@ def test_embedding_function(tmp_path):
|
|||||||
assert np.allclose(actual, expected)
|
assert np.allclose(actual, expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_instructor_ndims_uses_instruction():
|
||||||
|
instructor = get_registry().get("instructor").create()
|
||||||
|
model = MagicMock()
|
||||||
|
model.encode.return_value = np.zeros((1, 384))
|
||||||
|
|
||||||
|
with patch.object(type(instructor), "get_model", return_value=model):
|
||||||
|
assert instructor.ndims() == 384
|
||||||
|
|
||||||
|
model.encode.assert_called_once_with(
|
||||||
|
[[instructor.source_instruction, "foo"]],
|
||||||
|
batch_size=instructor.batch_size,
|
||||||
|
show_progress_bar=instructor.show_progress_bar,
|
||||||
|
normalize_embeddings=instructor.normalize_embeddings,
|
||||||
|
device=instructor.device,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_embedding_function_variables():
|
def test_embedding_function_variables():
|
||||||
@register("variable-testing")
|
@register("variable-testing")
|
||||||
class VariableTestingFunction(TextEmbeddingFunction):
|
class VariableTestingFunction(TextEmbeddingFunction):
|
||||||
@@ -115,34 +132,16 @@ def test_embedding_function_variables():
|
|||||||
assert func.safe_model_dump()["secret_key"] == "$var:secret"
|
assert func.safe_model_dump()["secret_key"] == "$var:secret"
|
||||||
|
|
||||||
|
|
||||||
def test_parse_functions_with_variables():
|
def test_openai_variables_survive_metadata_round_trip():
|
||||||
@register("variable-parsing-test")
|
|
||||||
class VariableParsingFunction(TextEmbeddingFunction):
|
|
||||||
api_key: str
|
|
||||||
base_url: Optional[str] = None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def sensitive_keys():
|
|
||||||
return ["api_key"]
|
|
||||||
|
|
||||||
def ndims(self):
|
|
||||||
return 10
|
|
||||||
|
|
||||||
def generate_embeddings(self, texts):
|
|
||||||
# Mock implementation that just returns random embeddings
|
|
||||||
# In real usage, this would use the api_key to call an API
|
|
||||||
return [np.random.rand(self.ndims()).tolist() for _ in texts]
|
|
||||||
|
|
||||||
registry = EmbeddingFunctionRegistry.get_instance()
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
|
||||||
registry.set_var("test_api_key", "sk-test-key-12345")
|
registry.set_var("test_api_key", "sk-test-key-12345")
|
||||||
registry.set_var("test_base_url", "https://api.example.com")
|
|
||||||
|
|
||||||
conf = EmbeddingFunctionConfig(
|
conf = EmbeddingFunctionConfig(
|
||||||
source_column="text",
|
source_column="text",
|
||||||
vector_column="vector",
|
vector_column="vector",
|
||||||
function=registry.get("variable-parsing-test").create(
|
function=registry.get("openai").create(
|
||||||
api_key="$var:test_api_key", base_url="$var:test_base_url"
|
api_key="$var:test_api_key", base_url="https://api.example.com"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -150,7 +149,10 @@ def test_parse_functions_with_variables():
|
|||||||
|
|
||||||
# Create a mock arrow table with the metadata
|
# Create a mock arrow table with the metadata
|
||||||
schema = pa.schema(
|
schema = pa.schema(
|
||||||
[pa.field("text", pa.string()), pa.field("vector", pa.list_(pa.float32(), 10))]
|
[
|
||||||
|
pa.field("text", pa.string()),
|
||||||
|
pa.field("vector", pa.list_(pa.float32(), 1536)),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
table = pa.table({"text": [], "vector": []}, schema=schema)
|
table = pa.table({"text": [], "vector": []}, schema=schema)
|
||||||
table = table.replace_schema_metadata(metadata)
|
table = table.replace_schema_metadata(metadata)
|
||||||
@@ -164,13 +166,15 @@ def test_parse_functions_with_variables():
|
|||||||
|
|
||||||
assert parsed_func.api_key == "sk-test-key-12345"
|
assert parsed_func.api_key == "sk-test-key-12345"
|
||||||
assert parsed_func.base_url == "https://api.example.com"
|
assert parsed_func.base_url == "https://api.example.com"
|
||||||
|
|
||||||
embeddings = parsed_func.generate_embeddings(["test text"])
|
|
||||||
assert len(embeddings) == 1
|
|
||||||
assert len(embeddings[0]) == 10
|
|
||||||
|
|
||||||
assert parsed_func.safe_model_dump()["api_key"] == "$var:test_api_key"
|
assert parsed_func.safe_model_dump()["api_key"] == "$var:test_api_key"
|
||||||
|
|
||||||
|
with patch("lancedb.embeddings.openai.attempt_import_or_raise") as import_openai:
|
||||||
|
parsed_func._openai_client
|
||||||
|
|
||||||
|
import_openai.return_value.OpenAI.assert_called_once_with(
|
||||||
|
api_key="sk-test-key-12345", base_url="https://api.example.com"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_embedding_with_bad_results(tmp_path):
|
def test_embedding_with_bad_results(tmp_path):
|
||||||
@register("null-embedding")
|
@register("null-embedding")
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import pyarrow.compute as pc
|
|||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
from lancedb.index import FTS
|
from lancedb.index import BTree, FTS, IvfPq
|
||||||
from lancedb.table import AsyncTable, Table
|
from lancedb.table import AsyncTable, Table
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +99,86 @@ async def test_async_hybrid_query_filters(table: AsyncTable):
|
|||||||
assert result["text"].to_pylist() == ["cat", "b"]
|
assert result["text"].to_pylist() == ["cat", "b"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_hybrid_query_with_stale_fixed_size_binary_prefilter(
|
||||||
|
tmpdir_factory,
|
||||||
|
):
|
||||||
|
tmp_path = str(tmpdir_factory.mktemp("stale_scalar_prefilter"))
|
||||||
|
db = await lancedb.connect_async(tmp_path)
|
||||||
|
|
||||||
|
def fixed_size_binary(value: int) -> bytes:
|
||||||
|
return value.to_bytes(16, byteorder="big")
|
||||||
|
|
||||||
|
num_rows = 1000
|
||||||
|
data = pa.table(
|
||||||
|
{
|
||||||
|
"space_id": pa.array(
|
||||||
|
[fixed_size_binary(i) for i in range(num_rows)],
|
||||||
|
type=pa.binary(16),
|
||||||
|
),
|
||||||
|
"text": ["book"] * num_rows,
|
||||||
|
"vector": pa.array(
|
||||||
|
[[float(i), float(i)] for i in range(num_rows)],
|
||||||
|
type=pa.list_(pa.float32(), 2),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
table = await db.create_table("test", data)
|
||||||
|
await table.create_index(
|
||||||
|
"vector", config=IvfPq(num_partitions=4, num_sub_vectors=2)
|
||||||
|
)
|
||||||
|
await table.create_index("space_id", config=BTree())
|
||||||
|
await table.create_index("text", config=FTS(with_position=False))
|
||||||
|
|
||||||
|
# Advance the search indices without advancing the scalar index. This is the
|
||||||
|
# state that previously let hybrid search use an incomplete scalar prefilter.
|
||||||
|
await table.add(data)
|
||||||
|
lance_dataset = await table.to_lance()
|
||||||
|
lance_dataset.optimize.optimize_indices(index_names=["vector_idx", "text_idx"])
|
||||||
|
await table.checkout_latest()
|
||||||
|
|
||||||
|
scalar_stats = await table.index_stats("space_id_idx")
|
||||||
|
assert scalar_stats is not None
|
||||||
|
assert scalar_stats.num_indexed_rows == num_rows
|
||||||
|
assert scalar_stats.num_unindexed_rows == num_rows
|
||||||
|
|
||||||
|
for index_name in ["vector_idx", "text_idx"]:
|
||||||
|
search_stats = await table.index_stats(index_name)
|
||||||
|
assert search_stats is not None
|
||||||
|
assert search_stats.num_indexed_rows == num_rows * 2
|
||||||
|
assert search_stats.num_unindexed_rows == 0
|
||||||
|
|
||||||
|
matching_ids = [5, 10, 15, 20, 25, 30]
|
||||||
|
literals = [
|
||||||
|
f"arrow_cast(0x{fixed_size_binary(i).hex()}, 'FixedSizeBinary(16)')"
|
||||||
|
for i in matching_ids
|
||||||
|
]
|
||||||
|
predicate = f"space_id IN ({', '.join(literals)})"
|
||||||
|
expected_ids = sorted(fixed_size_binary(i) for i in matching_ids for _ in range(2))
|
||||||
|
|
||||||
|
vector_query = (
|
||||||
|
table.query().where(predicate).nearest_to([5.0, 5.0]).limit(num_rows * 2)
|
||||||
|
)
|
||||||
|
vector_results = await vector_query.to_arrow()
|
||||||
|
assert sorted(vector_results["space_id"].to_pylist()) == expected_ids
|
||||||
|
|
||||||
|
fts_query = (
|
||||||
|
table.query().where(predicate).nearest_to_text("book").limit(num_rows * 2)
|
||||||
|
)
|
||||||
|
fts_results = await fts_query.to_arrow()
|
||||||
|
assert sorted(fts_results["space_id"].to_pylist()) == expected_ids
|
||||||
|
|
||||||
|
hybrid_results = await (
|
||||||
|
table.query()
|
||||||
|
.where(predicate)
|
||||||
|
.nearest_to([5.0, 5.0])
|
||||||
|
.nearest_to_text("book")
|
||||||
|
.limit(num_rows * 2)
|
||||||
|
.to_arrow()
|
||||||
|
)
|
||||||
|
assert sorted(hybrid_results["space_id"].to_pylist()) == expected_ids
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_hybrid_query_default_limit(table: AsyncTable):
|
async def test_async_hybrid_query_default_limit(table: AsyncTable):
|
||||||
# add 10 new rows
|
# add 10 new rows
|
||||||
@@ -123,6 +203,19 @@ async def test_async_hybrid_query_default_limit(table: AsyncTable):
|
|||||||
assert texts.count("a") == 1
|
assert texts.count("a") == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_hybrid_query_minimum_nprobes_zero_raises(sync_table: Table):
|
||||||
|
# minimum_nprobes(0) must raise the same validation error a plain vector
|
||||||
|
# query raises, not silently no-op because 0 is falsy.
|
||||||
|
with pytest.raises(ValueError, match="minimum_nprobes must be greater than 0"):
|
||||||
|
(
|
||||||
|
sync_table.search(query_type="hybrid")
|
||||||
|
.vector([0.0, 0.4])
|
||||||
|
.text("dog")
|
||||||
|
.minimum_nprobes(0)
|
||||||
|
.to_arrow()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_hybrid_query_distance_range(sync_table: Table):
|
def test_hybrid_query_distance_range(sync_table: Table):
|
||||||
reranker = RRFReranker(return_score="all")
|
reranker = RRFReranker(return_score="all")
|
||||||
result = (
|
result = (
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import lancedb._lancedb as _lancedb
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(sys.platform != "linux", reason="ldd is Linux-specific")
|
||||||
|
def test_native_extension_does_not_link_openssl():
|
||||||
|
"""OpenSSL-linked wheels abort when imported on RHEL hosts in FIPS mode."""
|
||||||
|
ldd = shutil.which("ldd")
|
||||||
|
if ldd is None:
|
||||||
|
pytest.skip("ldd is not installed")
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
[ldd, _lancedb.__file__],
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
openssl_libraries = re.findall(
|
||||||
|
r"^\s*(lib(?:crypto|ssl)\S*)\s+=>", result.stdout, flags=re.MULTILINE
|
||||||
|
)
|
||||||
|
|
||||||
|
assert not openssl_libraries, (
|
||||||
|
"the LanceDB native extension must use rustls instead of linking OpenSSL: "
|
||||||
|
f"{openssl_libraries}"
|
||||||
|
)
|
||||||
@@ -84,6 +84,15 @@ async def binary_table(db_async):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_create_index_async_returns_done_job(some_table: AsyncTable):
|
||||||
|
job = await some_table.create_index_async("id", config=BTree())
|
||||||
|
assert job.id is None
|
||||||
|
await job.wait()
|
||||||
|
assert len(await some_table.list_indices()) == 1
|
||||||
|
await job.cancel()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_create_scalar_index(some_table: AsyncTable):
|
async def test_create_scalar_index(some_table: AsyncTable):
|
||||||
# Can create
|
# Can create
|
||||||
@@ -363,6 +372,31 @@ async def test_create_vector_index(some_table: AsyncTable):
|
|||||||
assert stats.num_indices == 1
|
assert stats.num_indices == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_create_ivf_index_reports_unsplittable_partitions(db_async):
|
||||||
|
dim = 8
|
||||||
|
num_partitions = 300 # More than 256 selects hierarchical k-means.
|
||||||
|
base_vectors = [[float(row == column) for column in range(dim)] for row in range(5)]
|
||||||
|
vectors = pa.array(base_vectors * 200, pa.list_(pa.float32(), dim))
|
||||||
|
table = await db_async.create_table(
|
||||||
|
"unsplittable_partitions",
|
||||||
|
pa.table({"vector": vectors}),
|
||||||
|
)
|
||||||
|
|
||||||
|
error_pattern = (
|
||||||
|
rf"Cannot create {num_partitions} IVF partitions: k-means could only form"
|
||||||
|
)
|
||||||
|
with pytest.raises(RuntimeError, match=error_pattern):
|
||||||
|
await table.create_index(
|
||||||
|
"vector",
|
||||||
|
config=IvfFlat(
|
||||||
|
distance_type="dot",
|
||||||
|
num_partitions=num_partitions,
|
||||||
|
max_iterations=10,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_create_4bit_ivfpq_index(some_table: AsyncTable):
|
async def test_create_4bit_ivfpq_index(some_table: AsyncTable):
|
||||||
# Can create
|
# Can create
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ Tests verify:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -239,7 +240,7 @@ def create_tracking_namespace(
|
|||||||
|
|
||||||
dir_props = {f"storage.{k}": v for k, v in storage_options_with_refresh.items()}
|
dir_props = {f"storage.{k}": v for k, v in storage_options_with_refresh.items()}
|
||||||
|
|
||||||
if bucket_name.startswith("/") or bucket_name.startswith("file://"):
|
if os.path.isabs(bucket_name) or bucket_name.startswith("file://"):
|
||||||
dir_props["root"] = f"{bucket_name}/namespace_root"
|
dir_props["root"] = f"{bucket_name}/namespace_root"
|
||||||
else:
|
else:
|
||||||
dir_props["root"] = f"s3://{bucket_name}/namespace_root"
|
dir_props["root"] = f"s3://{bucket_name}/namespace_root"
|
||||||
@@ -767,3 +768,70 @@ def test_namespace_with_schema_only(s3_bucket: str, use_custom: bool):
|
|||||||
|
|
||||||
# Verify data was added
|
# Verify data was added
|
||||||
assert table.count_rows() == 2
|
assert table.count_rows() == 2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("use_custom", [False, True], ids=["DirectoryNS", "CustomNS"])
|
||||||
|
def test_namespace_exists(use_custom: bool):
|
||||||
|
"""
|
||||||
|
Test namespace_exists returns True for existing and False for non-existent.
|
||||||
|
"""
|
||||||
|
temp_dir = tempfile.mkdtemp()
|
||||||
|
try:
|
||||||
|
ns_client, _ = create_tracking_namespace(
|
||||||
|
bucket_name=temp_dir,
|
||||||
|
storage_options={},
|
||||||
|
credential_expires_in_seconds=3600,
|
||||||
|
use_custom=use_custom,
|
||||||
|
)
|
||||||
|
db = LanceNamespaceDBConnection(ns_client)
|
||||||
|
|
||||||
|
namespace_name = f"test_ns_{uuid.uuid4().hex[:8]}"
|
||||||
|
db.create_namespace([namespace_name])
|
||||||
|
|
||||||
|
# Existing namespace should return True
|
||||||
|
assert db.namespace_exists(namespace_id=[namespace_name]) is True
|
||||||
|
|
||||||
|
# Non-existent namespace should return False
|
||||||
|
assert db.namespace_exists(namespace_id=["nonexistent_ns"]) is False
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("use_custom", [False, True], ids=["DirectoryNS", "CustomNS"])
|
||||||
|
def test_table_exists(use_custom: bool):
|
||||||
|
"""
|
||||||
|
Test table_exists returns True for existing table and False for non-existent.
|
||||||
|
"""
|
||||||
|
temp_dir = tempfile.mkdtemp()
|
||||||
|
try:
|
||||||
|
ns_client, _ = create_tracking_namespace(
|
||||||
|
bucket_name=temp_dir,
|
||||||
|
storage_options={},
|
||||||
|
credential_expires_in_seconds=3600,
|
||||||
|
use_custom=use_custom,
|
||||||
|
)
|
||||||
|
db = LanceNamespaceDBConnection(ns_client)
|
||||||
|
|
||||||
|
namespace_name = f"test_ns_{uuid.uuid4().hex[:8]}"
|
||||||
|
db.create_namespace([namespace_name])
|
||||||
|
|
||||||
|
table_name = f"test_table_{uuid.uuid4().hex}"
|
||||||
|
namespace_path = [namespace_name]
|
||||||
|
schema = pa.schema(
|
||||||
|
[
|
||||||
|
pa.field("id", pa.int64()),
|
||||||
|
pa.field("vector", pa.list_(pa.float32(), 2)),
|
||||||
|
pa.field("text", pa.string()),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
db.create_table(table_name, schema=schema, namespace_path=namespace_path)
|
||||||
|
|
||||||
|
# Existing table should return True
|
||||||
|
table_id = namespace_path + [table_name]
|
||||||
|
assert db.table_exists(table_id=table_id) is True
|
||||||
|
|
||||||
|
# Non-existent table should return False
|
||||||
|
assert db.table_exists(table_id=namespace_path + ["nonexistent_table"]) is False
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def test_pyo3_abi_matches_minimum_supported_python():
|
||||||
|
project_dir = Path(__file__).parents[2]
|
||||||
|
pyproject = (project_dir / "pyproject.toml").read_text()
|
||||||
|
cargo_manifest = (project_dir / "Cargo.toml").read_text()
|
||||||
|
|
||||||
|
minimum_python = re.search(
|
||||||
|
r'^requires-python\s*=\s*">=(\d+)\.(\d+)"$', pyproject, re.MULTILINE
|
||||||
|
)
|
||||||
|
assert minimum_python is not None
|
||||||
|
|
||||||
|
major, minor = minimum_python.groups()
|
||||||
|
expected_abi = f"abi3-py{major}{minor}"
|
||||||
|
configured_abis = re.findall(r'"(abi3-py\d+)"', cargo_manifest)
|
||||||
|
|
||||||
|
assert configured_abis == [expected_abi, expected_abi], (
|
||||||
|
"the pyo3 runtime and build ABI features must both match requires-python"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(sys.platform != "win32", reason="Windows wheel regression test")
|
||||||
|
def test_windows_wheel_tag_and_native_import():
|
||||||
|
project_dir = Path(__file__).parents[2]
|
||||||
|
wheels = list((project_dir.parent / "target" / "wheels").glob("lancedb-*.whl"))
|
||||||
|
if not wheels:
|
||||||
|
pytest.skip("no wheel artifact is available in this development environment")
|
||||||
|
|
||||||
|
assert len(wheels) == 1
|
||||||
|
assert wheels[0].name.endswith("-cp310-abi3-win_amd64.whl")
|
||||||
|
|
||||||
|
native_module = importlib.import_module("lancedb._lancedb")
|
||||||
|
assert Path(native_module.__file__).suffix == ".pyd"
|
||||||
@@ -6,6 +6,7 @@ import math
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from lancedb import DBConnection, Table, connect
|
from lancedb import DBConnection, Table, connect
|
||||||
|
from lancedb.background_loop import LOOP
|
||||||
from lancedb.permutation import Permutation, Permutations, permutation_builder
|
from lancedb.permutation import Permutation, Permutations, permutation_builder
|
||||||
|
|
||||||
|
|
||||||
@@ -31,6 +32,25 @@ def test_split_random_ratios(mem_db):
|
|||||||
assert 65 <= split_1_count <= 75 # ~70% ± tolerance
|
assert 65 <= split_1_count <= 75 # ~70% ± tolerance
|
||||||
|
|
||||||
|
|
||||||
|
def test_execute_does_not_reenter_background_loop(tmp_path, monkeypatch):
|
||||||
|
import threading
|
||||||
|
|
||||||
|
db = connect(tmp_path)
|
||||||
|
tbl = db.create_table("test_table", pa.table({"x": range(10)}))
|
||||||
|
original_run = LOOP.run
|
||||||
|
|
||||||
|
def fail_on_reentry(future):
|
||||||
|
assert threading.current_thread() is not LOOP.thread
|
||||||
|
return original_run(future)
|
||||||
|
|
||||||
|
monkeypatch.setattr(LOOP, "run", fail_on_reentry)
|
||||||
|
|
||||||
|
permutation_tbl = permutation_builder(tbl).execute()
|
||||||
|
|
||||||
|
assert permutation_tbl.count_rows() == 10
|
||||||
|
assert permutation_tbl._conn.read_consistency_interval is None
|
||||||
|
|
||||||
|
|
||||||
def test_split_random_counts(mem_db):
|
def test_split_random_counts(mem_db):
|
||||||
"""Test random splitting with absolute counts."""
|
"""Test random splitting with absolute counts."""
|
||||||
tbl = mem_db.create_table(
|
tbl = mem_db.create_table(
|
||||||
|
|||||||
@@ -415,6 +415,17 @@ def test_nullable_vector():
|
|||||||
assert schema == pa.schema([pa.field("vec", pa.list_(pa.float32(), 16), True)])
|
assert schema == pa.schema([pa.field("vec", pa.list_(pa.float32(), 16), True)])
|
||||||
|
|
||||||
|
|
||||||
|
def test_bare_vector_raises_clear_error():
|
||||||
|
namespace = {
|
||||||
|
"__name__": "test_model_without_pyarrow",
|
||||||
|
"LanceModel": LanceModel,
|
||||||
|
"Vector": Vector,
|
||||||
|
}
|
||||||
|
|
||||||
|
with pytest.raises(TypeError, match=r"Vector must be parameterized.*Vector\(128\)"):
|
||||||
|
exec("class TestModel(LanceModel):\n vector: Vector", namespace)
|
||||||
|
|
||||||
|
|
||||||
def test_fixed_size_list_field():
|
def test_fixed_size_list_field():
|
||||||
class TestModel(pydantic.BaseModel):
|
class TestModel(pydantic.BaseModel):
|
||||||
vec: Vector(16)
|
vec: Vector(16)
|
||||||
|
|||||||
@@ -570,6 +570,15 @@ def test_query_builder(table):
|
|||||||
assert all(np.array(rs[0]["vector"]) == [1, 2])
|
assert all(np.array(rs[0]["vector"]) == [1, 2])
|
||||||
|
|
||||||
|
|
||||||
|
def test_query_multiple_vectors(table):
|
||||||
|
results = table.search([np.array([1, 2]), np.array([4, 5])]).limit(1).to_list()
|
||||||
|
|
||||||
|
assert len(results) == 2
|
||||||
|
results_by_query = {result["query_index"]: result for result in results}
|
||||||
|
assert results_by_query[0]["id"] == 1
|
||||||
|
assert results_by_query[1]["id"] == 2
|
||||||
|
|
||||||
|
|
||||||
def test_with_row_id(table: lancedb.table.Table):
|
def test_with_row_id(table: lancedb.table.Table):
|
||||||
rs = table.search().with_row_id(True).to_arrow()
|
rs = table.search().with_row_id(True).to_arrow()
|
||||||
assert "_rowid" in rs.column_names
|
assert "_rowid" in rs.column_names
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ def make_mock_http_handler(handler):
|
|||||||
return MockLanceDBHandler
|
return MockLanceDBHandler
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("db_name", ["a" * 64, "invalid..database"])
|
||||||
|
def test_connect_rejects_invalid_cloud_dns_hostname(db_name):
|
||||||
|
with pytest.raises(ValueError, match="DNS labels must contain 1 to 63 bytes"):
|
||||||
|
lancedb.connect(f"db://{db_name}", api_key="fake")
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def mock_lancedb_connection(handler):
|
def mock_lancedb_connection(handler):
|
||||||
with http.server.HTTPServer(
|
with http.server.HTTPServer(
|
||||||
@@ -812,6 +818,121 @@ def test_table_create_indices():
|
|||||||
table.drop_index("custom_fts_idx")
|
table.drop_index("custom_fts_idx")
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_create_index_async_returns_job():
|
||||||
|
from lancedb.index import BTree
|
||||||
|
|
||||||
|
describe_calls = []
|
||||||
|
|
||||||
|
def handler(request):
|
||||||
|
content_len = int(request.headers.get("Content-Length", 0))
|
||||||
|
body = request.rfile.read(content_len) if content_len > 0 else b""
|
||||||
|
if request.path == "/v1/table/test/create_index/":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(b'{"job_id": "job-1"}')
|
||||||
|
elif request.path == "/v1/jobs/describe":
|
||||||
|
assert json.loads(body)["job_id"] == "job-1"
|
||||||
|
describe_calls.append(1)
|
||||||
|
state = "IN_PROGRESS" if len(describe_calls) == 1 else "DONE"
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(
|
||||||
|
json.dumps(dict(job_id="job-1", job_state=state)).encode()
|
||||||
|
)
|
||||||
|
elif request.path == "/v1/jobs/cancel":
|
||||||
|
assert json.loads(body)["job_id"] == "job-1"
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(b"{}")
|
||||||
|
elif request.path == "/v1/table/test/create/?mode=create":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(b"{}")
|
||||||
|
elif request.path == "/v1/table/test/describe/":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(
|
||||||
|
json.dumps(
|
||||||
|
dict(
|
||||||
|
version=1,
|
||||||
|
schema=dict(
|
||||||
|
fields=[
|
||||||
|
dict(name="id", type={"type": "int64"}, nullable=False),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
).encode()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
|
||||||
|
with mock_lancedb_connection(handler) as db:
|
||||||
|
table = db.create_table("test", [{"id": 1}])
|
||||||
|
job = table.create_index_async("id", config=BTree())
|
||||||
|
assert job.id == "job-1"
|
||||||
|
job.wait(timeout=timedelta(seconds=30))
|
||||||
|
assert len(describe_calls) == 2
|
||||||
|
job.cancel()
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_job_wait_raises_on_failure():
|
||||||
|
from lancedb.exceptions import JobFailedError
|
||||||
|
from lancedb.index import BTree
|
||||||
|
|
||||||
|
def handler(request):
|
||||||
|
content_len = int(request.headers.get("Content-Length", 0))
|
||||||
|
body = request.rfile.read(content_len) if content_len > 0 else b""
|
||||||
|
if request.path == "/v1/table/test/create_index/":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(b'{"job_id": "job-2"}')
|
||||||
|
elif request.path == "/v1/jobs/describe":
|
||||||
|
assert json.loads(body)["job_id"] == "job-2"
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(
|
||||||
|
json.dumps(dict(job_id="job-2", job_state="FAILED")).encode()
|
||||||
|
)
|
||||||
|
elif request.path == "/v1/table/test/create/?mode=create":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(b"{}")
|
||||||
|
elif request.path == "/v1/table/test/describe/":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(
|
||||||
|
json.dumps(
|
||||||
|
dict(
|
||||||
|
version=1,
|
||||||
|
schema=dict(
|
||||||
|
fields=[
|
||||||
|
dict(name="id", type={"type": "int64"}, nullable=False),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
).encode()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
|
||||||
|
with mock_lancedb_connection(handler) as db:
|
||||||
|
table = db.create_table("test", [{"id": 1}])
|
||||||
|
job = table.create_index_async("id", config=BTree())
|
||||||
|
with pytest.raises(JobFailedError, match="job-2"):
|
||||||
|
job.wait()
|
||||||
|
|
||||||
|
|
||||||
def test_remote_create_index_new_api():
|
def test_remote_create_index_new_api():
|
||||||
received_requests = []
|
received_requests = []
|
||||||
|
|
||||||
@@ -1020,7 +1141,7 @@ def query_test_table(query_handler, *, server_version=Version("0.1.0")):
|
|||||||
request.send_header("Content-Type", "application/json")
|
request.send_header("Content-Type", "application/json")
|
||||||
request.send_header("phalanx-version", str(server_version))
|
request.send_header("phalanx-version", str(server_version))
|
||||||
request.end_headers()
|
request.end_headers()
|
||||||
request.wfile.write(b"{}")
|
request.wfile.write(b'{"version": 1, "schema": {"fields": []}}')
|
||||||
elif request.path == "/v1/table/test/query/":
|
elif request.path == "/v1/table/test/query/":
|
||||||
content_len = int(request.headers.get("Content-Length"))
|
content_len = int(request.headers.get("Content-Length"))
|
||||||
body = request.rfile.read(content_len)
|
body = request.rfile.read(content_len)
|
||||||
@@ -1858,3 +1979,330 @@ def test_inherited_remote_table_reopens_after_fork():
|
|||||||
finally:
|
finally:
|
||||||
server.shutdown()
|
server.shutdown()
|
||||||
server_thread.join()
|
server_thread.join()
|
||||||
|
|
||||||
|
|
||||||
|
BLOB_DESCRIBE_RESPONSE = {
|
||||||
|
"table": "test",
|
||||||
|
"version": 1,
|
||||||
|
"schema": {
|
||||||
|
"fields": [
|
||||||
|
{"name": "id", "type": {"type": "int64"}, "nullable": False},
|
||||||
|
{
|
||||||
|
"name": "image",
|
||||||
|
"type": {
|
||||||
|
"type": "struct",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"type": {"type": "large_binary"},
|
||||||
|
"nullable": True,
|
||||||
|
},
|
||||||
|
{"name": "uri", "type": {"type": "string"}, "nullable": True},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"nullable": True,
|
||||||
|
"metadata": {
|
||||||
|
"ARROW:extension:name": "lance.blob.v2",
|
||||||
|
"ARROW:extension:metadata": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def blob_query_response_table():
|
||||||
|
image_field = pa.field(
|
||||||
|
"image",
|
||||||
|
pa.struct(
|
||||||
|
[
|
||||||
|
pa.field("kind", pa.uint8(), nullable=False),
|
||||||
|
pa.field("position", pa.uint64(), nullable=False),
|
||||||
|
pa.field("size", pa.uint64(), nullable=False),
|
||||||
|
pa.field("blob_id", pa.uint32(), nullable=False),
|
||||||
|
pa.field("blob_uri", pa.string(), nullable=False),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
metadata={"lance-encoding:blob": "true"},
|
||||||
|
)
|
||||||
|
images = pa.StructArray.from_arrays(
|
||||||
|
[
|
||||||
|
pa.array([1, 0, 0], type=pa.uint8()),
|
||||||
|
pa.array([0, 0, 0], type=pa.uint64()),
|
||||||
|
pa.array([5, 0, 5], type=pa.uint64()),
|
||||||
|
pa.array([1, 0, 2], type=pa.uint32()),
|
||||||
|
pa.array(["", "", ""], type=pa.string()),
|
||||||
|
],
|
||||||
|
fields=image_field.type,
|
||||||
|
mask=pa.array([False, True, False]),
|
||||||
|
)
|
||||||
|
return pa.Table.from_arrays(
|
||||||
|
[
|
||||||
|
pa.array([1, 2, 3], type=pa.int64()),
|
||||||
|
images,
|
||||||
|
pa.array([10, 20, 30], type=pa.uint64()),
|
||||||
|
],
|
||||||
|
schema=pa.schema(
|
||||||
|
[
|
||||||
|
pa.field("id", pa.int64(), nullable=False),
|
||||||
|
image_field,
|
||||||
|
pa.field("_rowid", pa.uint64()),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def blob_remote_table(*, server_version=Version("0.5.0")):
|
||||||
|
def handler(request):
|
||||||
|
if request.path == "/v1/table/test/describe/":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.send_header("phalanx-version", str(server_version))
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(json.dumps(BLOB_DESCRIBE_RESPONSE).encode())
|
||||||
|
elif request.path.startswith("/v1/table/test/blob/image/"):
|
||||||
|
path = request.path.partition("?")[0]
|
||||||
|
row_id = int(path.split("/")[-2])
|
||||||
|
payload = {10: b"alpha", 20: None, 30: b"gamma"}[row_id]
|
||||||
|
if payload is None:
|
||||||
|
request.send_response(204)
|
||||||
|
request.end_headers()
|
||||||
|
return
|
||||||
|
byte_range = request.headers["Range"].removeprefix("bytes=")
|
||||||
|
start_text, end_text = byte_range.split("-", maxsplit=1)
|
||||||
|
start = int(start_text)
|
||||||
|
end = int(end_text) if end_text else len(payload) - 1
|
||||||
|
chunk = payload[start : end + 1]
|
||||||
|
request.send_response(206)
|
||||||
|
request.send_header("Content-Range", f"bytes {start}-{end}/{len(payload)}")
|
||||||
|
request.send_header("Content-Length", str(len(chunk)))
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(chunk)
|
||||||
|
elif request.path == "/v1/table/test/query/":
|
||||||
|
content_len = int(request.headers.get("Content-Length", 0))
|
||||||
|
body = json.loads(request.rfile.read(content_len))
|
||||||
|
assert body["columns"] == ["id", "image"]
|
||||||
|
assert body["with_row_id"] is True
|
||||||
|
response_table = blob_query_response_table()
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/vnd.apache.arrow.file")
|
||||||
|
request.end_headers()
|
||||||
|
with pa.ipc.new_file(request.wfile, response_table.schema) as writer:
|
||||||
|
writer.write_table(response_table)
|
||||||
|
elif request.path == "/v1/table/test/fetch_blobs/":
|
||||||
|
content_len = int(request.headers.get("Content-Length", 0))
|
||||||
|
body = json.loads(request.rfile.read(content_len))
|
||||||
|
assert body["column"] == "image"
|
||||||
|
assert body["row_ids"] == [10, 20, 30]
|
||||||
|
response_table = pa.table(
|
||||||
|
{"image": pa.array([b"alpha", None, b"gamma"], type=pa.large_binary())}
|
||||||
|
)
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/vnd.apache.arrow.stream")
|
||||||
|
request.end_headers()
|
||||||
|
with pa.ipc.new_stream(request.wfile, response_table.schema) as writer:
|
||||||
|
writer.write_table(response_table)
|
||||||
|
else:
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
|
||||||
|
with mock_lancedb_connection(handler) as db:
|
||||||
|
yield db.open_table("test")
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_blob_columns_and_fetch():
|
||||||
|
with blob_remote_table() as table:
|
||||||
|
assert table.blob_columns() == ["image"]
|
||||||
|
blobs = table.fetch_blobs("image", [10, 20, 30])
|
||||||
|
assert blobs.to_pylist() == [b"alpha", None, b"gamma"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_blob_files_are_lazy_seekable_handles():
|
||||||
|
with blob_remote_table() as table:
|
||||||
|
files = table.fetch_blob_files("image", [10, 20, 30])
|
||||||
|
|
||||||
|
assert len(files) == 3
|
||||||
|
alpha, null_row, gamma = files
|
||||||
|
assert null_row is None
|
||||||
|
assert alpha is not None
|
||||||
|
assert gamma is not None
|
||||||
|
assert alpha.size() == 5
|
||||||
|
assert alpha.read_range(1, 3) == b"lph"
|
||||||
|
gamma.seek(2)
|
||||||
|
assert gamma.read() == b"mma"
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_blob_fetch_accepts_query_table():
|
||||||
|
hits = pa.table({"_rowid": pa.array([10, 20, 30], type=pa.uint64())})
|
||||||
|
|
||||||
|
with blob_remote_table() as table:
|
||||||
|
blobs = table.fetch_blobs("image", hits)
|
||||||
|
|
||||||
|
assert blobs.to_pylist() == [b"alpha", None, b"gamma"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_blob_query_stashes_row_ids_for_fetch():
|
||||||
|
with blob_remote_table() as table:
|
||||||
|
hits = table.search().select(["id", "image"]).limit(3).to_arrow()
|
||||||
|
assert "_rowid" not in hits.column_names
|
||||||
|
assert "_lance_row_id" in hits.schema.field("image").type.names
|
||||||
|
blobs = table.fetch_blobs("image", hits)
|
||||||
|
|
||||||
|
assert blobs.to_pylist() == [b"alpha", None, b"gamma"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_blob_query_survives_a_server_that_ignores_the_row_id_request():
|
||||||
|
def handler(request):
|
||||||
|
if request.path == "/v1/table/test/describe/":
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.send_header("phalanx-version", "0.5.0")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(json.dumps(BLOB_DESCRIBE_RESPONSE).encode())
|
||||||
|
elif request.path == "/v1/table/test/query/":
|
||||||
|
content_len = int(request.headers.get("Content-Length", 0))
|
||||||
|
assert json.loads(request.rfile.read(content_len))["with_row_id"] is True
|
||||||
|
response_table = blob_query_response_table().drop_columns(["_rowid"])
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/vnd.apache.arrow.file")
|
||||||
|
request.end_headers()
|
||||||
|
with pa.ipc.new_file(request.wfile, response_table.schema) as writer:
|
||||||
|
writer.write_table(response_table)
|
||||||
|
else:
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
|
||||||
|
with mock_lancedb_connection(handler) as db:
|
||||||
|
table = db.open_table("test")
|
||||||
|
hits = table.search().select(["id", "image"]).limit(3).to_arrow()
|
||||||
|
|
||||||
|
assert hits.column_names == ["id", "image"]
|
||||||
|
assert "_lance_row_id" not in hits.schema.field("image").type.names
|
||||||
|
with pytest.raises(ValueError, match="pass a list of row ids"):
|
||||||
|
table.fetch_blobs("image", hits)
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_blob_byte_apis_not_supported_on_old_server():
|
||||||
|
with blob_remote_table(server_version=Version("0.1.0")) as table:
|
||||||
|
assert table.blob_columns() == ["image"]
|
||||||
|
with pytest.raises(NotImplementedError, match="not supported"):
|
||||||
|
table.fetch_blobs("image", [1])
|
||||||
|
with pytest.raises(NotImplementedError, match="not supported"):
|
||||||
|
table.fetch_blob_files("image", [1])
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_connection_jobs_surface():
|
||||||
|
from lancedb.exceptions import JobFailedError
|
||||||
|
|
||||||
|
schema = pa.schema([("state", pa.string())])
|
||||||
|
batch = pa.record_batch([pa.array(["created", "done"])], schema=schema)
|
||||||
|
sink = pa.BufferOutputStream()
|
||||||
|
with pa.ipc.new_stream(sink, schema) as writer:
|
||||||
|
writer.write_batch(batch)
|
||||||
|
events_body = sink.getvalue().to_pybytes()
|
||||||
|
|
||||||
|
def handler(request):
|
||||||
|
content_len = int(request.headers.get("Content-Length", 0))
|
||||||
|
body = request.rfile.read(content_len) if content_len > 0 else b""
|
||||||
|
payload = json.loads(body) if body else {}
|
||||||
|
if request.path == "/v1/jobs/list":
|
||||||
|
if payload.get("page_token") is None:
|
||||||
|
rsp = dict(
|
||||||
|
jobs=[
|
||||||
|
dict(
|
||||||
|
job_id="job-1",
|
||||||
|
table="t1",
|
||||||
|
job_type="create_index",
|
||||||
|
state="in_progress",
|
||||||
|
created_at_millis=1000,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
page_token="next",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assert payload["page_token"] == "next"
|
||||||
|
rsp = dict(
|
||||||
|
jobs=[
|
||||||
|
dict(
|
||||||
|
job_id="job-2",
|
||||||
|
table="t2",
|
||||||
|
job_type="create_index",
|
||||||
|
state="succeeded",
|
||||||
|
created_at_millis=2000,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(json.dumps(rsp).encode())
|
||||||
|
elif request.path == "/v1/jobs/describe":
|
||||||
|
if payload["job_id"] != "job-1":
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
return
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(
|
||||||
|
json.dumps(
|
||||||
|
dict(
|
||||||
|
job_id="job-1",
|
||||||
|
job_type="create_index",
|
||||||
|
job_state="FAILED",
|
||||||
|
creation_ms=1000,
|
||||||
|
spec=dict(column="vec"),
|
||||||
|
failure=dict(
|
||||||
|
phase="execute", message="worker died", retryable=True
|
||||||
|
),
|
||||||
|
)
|
||||||
|
).encode()
|
||||||
|
)
|
||||||
|
elif request.path == "/v1/jobs/cancel":
|
||||||
|
if payload["job_id"] != "job-1":
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
return
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/json")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(b'{"job_id": "job-1"}')
|
||||||
|
elif request.path == "/v1/jobs/query_events":
|
||||||
|
assert payload["job_id"] == "job-1"
|
||||||
|
request.send_response(200)
|
||||||
|
request.send_header("Content-Type", "application/vnd.apache.arrow.stream")
|
||||||
|
request.end_headers()
|
||||||
|
request.wfile.write(events_body)
|
||||||
|
else:
|
||||||
|
request.send_response(404)
|
||||||
|
request.end_headers()
|
||||||
|
|
||||||
|
with mock_lancedb_connection(handler) as db:
|
||||||
|
jobs = db.list_jobs()
|
||||||
|
assert [job.job_id for job in jobs] == ["job-1", "job-2"]
|
||||||
|
assert jobs[0].state == "running"
|
||||||
|
assert jobs[0].table == "t1"
|
||||||
|
assert jobs[1].state == "finished"
|
||||||
|
|
||||||
|
description = db.get_job("job-1")
|
||||||
|
assert description.job_type == "create_index"
|
||||||
|
assert description.state == "failed"
|
||||||
|
assert json.loads(description.spec_json) == {"column": "vec"}
|
||||||
|
assert description.failure.message == "worker died"
|
||||||
|
assert description.failure.retryable is True
|
||||||
|
assert db.get_job("missing") is None
|
||||||
|
|
||||||
|
assert db.cancel_job("job-1") is True
|
||||||
|
assert db.cancel_job("missing") is False
|
||||||
|
|
||||||
|
batches = db.job_history("job-1")
|
||||||
|
assert len(batches) == 1
|
||||||
|
assert batches[0].num_rows == 2
|
||||||
|
assert batches[0].column("state").to_pylist() == ["created", "done"]
|
||||||
|
|
||||||
|
job = db.job("job-1")
|
||||||
|
assert job.id == "job-1"
|
||||||
|
assert job.status() == "failed"
|
||||||
|
with pytest.raises(JobFailedError, match="worker died"):
|
||||||
|
job.wait(timeout=timedelta(seconds=5))
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
|
||||||
|
import ctypes
|
||||||
|
import gc
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import warnings
|
import warnings
|
||||||
|
import weakref
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import List
|
from typing import List
|
||||||
@@ -98,6 +102,30 @@ def test_basic(mem_db: DBConnection):
|
|||||||
assert table.to_arrow() == expected_data
|
assert table.to_arrow() == expected_data
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_preserves_nulls_from_sliced_arrow_table(mem_db: DBConnection):
|
||||||
|
data = pa.table(
|
||||||
|
{
|
||||||
|
"id": [0, 1, 2, 3, 4],
|
||||||
|
"score_cn": [None, 22, None, 5, 8],
|
||||||
|
"score_mt": [None, 42, None, 5, 8],
|
||||||
|
"vector": [
|
||||||
|
[20, 19, -1, -1],
|
||||||
|
[41, 38, 22, 42],
|
||||||
|
[10, 10, -1, -1],
|
||||||
|
[5, 5, 5, 5],
|
||||||
|
[8, 8, 8, 8],
|
||||||
|
],
|
||||||
|
}
|
||||||
|
).slice(1)
|
||||||
|
|
||||||
|
table = mem_db.create_table("sliced_nullable", data=data)
|
||||||
|
result = table.search([41, 38, 22, 42]).limit(1).to_arrow()
|
||||||
|
|
||||||
|
assert result["id"].to_pylist() == [1]
|
||||||
|
assert result["score_cn"].to_pylist() == [22]
|
||||||
|
assert result["score_mt"].to_pylist() == [42]
|
||||||
|
|
||||||
|
|
||||||
def test_table_to_pandas_default_matches_arrow(tmp_db: DBConnection):
|
def test_table_to_pandas_default_matches_arrow(tmp_db: DBConnection):
|
||||||
pd = pytest.importorskip("pandas")
|
pd = pytest.importorskip("pandas")
|
||||||
data = pa.table({"id": [1, 2], "text": ["one", "two"]})
|
data = pa.table({"id": [1, 2], "text": ["one", "two"]})
|
||||||
@@ -434,6 +462,38 @@ def test_add(mem_db: DBConnection):
|
|||||||
_add(table, schema)
|
_add(table, schema)
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_releases_arrow_buffers_without_gc(mem_db: DBConnection):
|
||||||
|
"""Regression test for https://github.com/lancedb/lancedb/issues/2512."""
|
||||||
|
schema = pa.schema([pa.field("x", pa.int64())])
|
||||||
|
table = mem_db.create_table("test_add_releases_arrow_buffers", schema=schema)
|
||||||
|
|
||||||
|
class BufferOwner:
|
||||||
|
def __init__(self, size: int):
|
||||||
|
self.memory = ctypes.create_string_buffer(size)
|
||||||
|
|
||||||
|
owner_refs = []
|
||||||
|
gc_was_enabled = gc.isenabled()
|
||||||
|
gc.disable()
|
||||||
|
try:
|
||||||
|
for _ in range(3):
|
||||||
|
size = 8 * 1024
|
||||||
|
owner = BufferOwner(size)
|
||||||
|
arrow_buffer = pa.foreign_buffer(
|
||||||
|
ctypes.addressof(owner.memory), size, owner
|
||||||
|
)
|
||||||
|
array = pa.Array.from_buffers(pa.int64(), 1024, [None, arrow_buffer])
|
||||||
|
batch = pa.RecordBatch.from_arrays([array], schema=schema)
|
||||||
|
owner_refs.append(weakref.ref(owner))
|
||||||
|
|
||||||
|
table.add(batch)
|
||||||
|
del batch, array, arrow_buffer, owner
|
||||||
|
|
||||||
|
assert all(owner_ref() is None for owner_ref in owner_refs)
|
||||||
|
finally:
|
||||||
|
if gc_was_enabled:
|
||||||
|
gc.enable()
|
||||||
|
|
||||||
|
|
||||||
def test_add_write_parallelism(mem_db: DBConnection):
|
def test_add_write_parallelism(mem_db: DBConnection):
|
||||||
schema = pa.schema([pa.field("id", pa.int64())])
|
schema = pa.schema([pa.field("id", pa.int64())])
|
||||||
table = mem_db.create_table("test", schema=schema)
|
table = mem_db.create_table("test", schema=schema)
|
||||||
@@ -869,6 +929,7 @@ def test_polars(mem_db: DBConnection):
|
|||||||
|
|
||||||
# enter table to polars dataframe
|
# enter table to polars dataframe
|
||||||
result = table.to_polars()
|
result = table.to_polars()
|
||||||
|
assert isinstance(result, pl.LazyFrame)
|
||||||
assert np.allclose(result.collect()["vector"].to_list(), data["vector"])
|
assert np.allclose(result.collect()["vector"].to_list(), data["vector"])
|
||||||
|
|
||||||
# make sure filtering isn't broken
|
# make sure filtering isn't broken
|
||||||
@@ -1402,6 +1463,15 @@ async def test_async_open_table_with_branch_version(tmp_path):
|
|||||||
assert await pinned.count_rows() == 4 # writable again
|
assert await pinned.count_rows() == 4 # writable again
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_index_async_returns_done_job(mem_db: DBConnection):
|
||||||
|
table = mem_db.create_table("job_test", [{"id": i} for i in range(10)])
|
||||||
|
job = table.create_index_async("id", config=BTree())
|
||||||
|
assert job.id is None
|
||||||
|
job.wait()
|
||||||
|
assert len(table.list_indices()) == 1
|
||||||
|
job.cancel()
|
||||||
|
|
||||||
|
|
||||||
@patch("lancedb.table.AsyncTable.create_index")
|
@patch("lancedb.table.AsyncTable.create_index")
|
||||||
def test_create_index_method(mock_create_index, mem_db: DBConnection):
|
def test_create_index_method(mock_create_index, mem_db: DBConnection):
|
||||||
table = mem_db.create_table(
|
table = mem_db.create_table(
|
||||||
@@ -1776,6 +1846,27 @@ def test_add_with_empty_fixed_size_list_drops_bad_rows(mem_db: DBConnection):
|
|||||||
assert np.allclose(data["embedding"].to_pylist()[0], np.array([0.1] * 16))
|
assert np.allclose(data["embedding"].to_pylist()[0], np.array([0.1] * 16))
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_nullable_fixed_size_list_with_none(mem_db: DBConnection):
|
||||||
|
"""Regression test for issue #2340."""
|
||||||
|
table = mem_db.create_table(
|
||||||
|
"test_nullable_fixed_size_list",
|
||||||
|
schema=pa.schema(
|
||||||
|
[
|
||||||
|
pa.field("id", pa.string()),
|
||||||
|
pa.field("feature", pa.list_(pa.float32(), 256)),
|
||||||
|
pa.field("tags", pa.list_(pa.string())),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
table.add([{"id": "1", "feature": None, "tags": ["tag1", "tag2"]}])
|
||||||
|
|
||||||
|
result = table.to_arrow()
|
||||||
|
assert result.to_pylist() == [
|
||||||
|
{"id": "1", "feature": None, "tags": ["tag1", "tag2"]}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_add_nullable_struct_with_none(mem_db: DBConnection):
|
def test_add_nullable_struct_with_none(mem_db: DBConnection):
|
||||||
"""Regression test for issue #2654: a nullable struct column whose
|
"""Regression test for issue #2654: a nullable struct column whose
|
||||||
first batch contains only None values must not crash in
|
first batch contains only None values must not crash in
|
||||||
@@ -1815,6 +1906,33 @@ def test_add_nullable_struct_with_none(mem_db: DBConnection):
|
|||||||
assert result.column("data").to_pylist() == [{"x": 1.0}, None]
|
assert result.column("data").to_pylist() == [{"x": 1.0}, None]
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_mostly_null_list_v2_2_page_boundary(tmp_path):
|
||||||
|
# Regression test for #3194. This row/value count crosses a v2.2 structural
|
||||||
|
# encoding page boundary where Lance 3.0.0 sliced repetition/definition
|
||||||
|
# levels by row offset and decoded child arrays at different lengths.
|
||||||
|
num_rows = 64_885
|
||||||
|
num_values = 217
|
||||||
|
list_type = pa.list_(pa.float32())
|
||||||
|
source = pa.table(
|
||||||
|
{
|
||||||
|
"id": np.arange(num_rows, dtype=np.int64),
|
||||||
|
"coords": pa.array(
|
||||||
|
[[1.0, 2.0, 3.0, 4.0]] * num_values + [None] * (num_rows - num_values),
|
||||||
|
type=list_type,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
db = lancedb.connect(
|
||||||
|
tmp_path,
|
||||||
|
storage_options={"new_table_data_storage_version": "2.2"},
|
||||||
|
)
|
||||||
|
table = db.create_table("test_sparse_nullable_list", data=source)
|
||||||
|
|
||||||
|
result = table.search().select(["id", "coords"]).limit(num_rows).to_arrow()
|
||||||
|
|
||||||
|
assert result.equals(source)
|
||||||
|
|
||||||
|
|
||||||
def test_add_with_integer_embeddings_preserves_casting(mem_db: DBConnection):
|
def test_add_with_integer_embeddings_preserves_casting(mem_db: DBConnection):
|
||||||
class Schema(LanceModel):
|
class Schema(LanceModel):
|
||||||
text: str
|
text: str
|
||||||
@@ -2100,6 +2218,45 @@ def test_merge(tmp_db: DBConnection, tmp_path):
|
|||||||
table.merge(other_dataset, left_on="id")
|
table.merge(other_dataset, left_on="id")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("storage_version", ["legacy", "stable"])
|
||||||
|
def test_search_after_merge(tmp_path, storage_version):
|
||||||
|
pytest.importorskip("lance")
|
||||||
|
pd = pytest.importorskip("pandas")
|
||||||
|
|
||||||
|
db = lancedb.connect(
|
||||||
|
tmp_path,
|
||||||
|
storage_options={"new_table_data_storage_version": storage_version},
|
||||||
|
)
|
||||||
|
rng = np.random.default_rng(42)
|
||||||
|
row_count = 512
|
||||||
|
vectors = rng.standard_normal((row_count, 8)).astype(np.float32)
|
||||||
|
table = db.create_table(
|
||||||
|
"search_after_merge",
|
||||||
|
data=pd.DataFrame(
|
||||||
|
{
|
||||||
|
"id": [str(i) for i in range(row_count)],
|
||||||
|
"vector": list(vectors),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
table.create_index("vector", config=IvfPq(num_partitions=1, num_sub_vectors=2))
|
||||||
|
|
||||||
|
links = pd.DataFrame(
|
||||||
|
{
|
||||||
|
"id": [str(i) for i in range(row_count // 2)],
|
||||||
|
"link": [f"https://example.com/{i}" for i in range(row_count // 2)],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
table.merge(links, left_on="id")
|
||||||
|
|
||||||
|
query = table.search(vectors[-1]).refine_factor(50).limit(10)
|
||||||
|
assert "ANN" in query.explain_plan(verbose=True)
|
||||||
|
|
||||||
|
result = query.to_arrow()
|
||||||
|
links_by_id = dict(zip(result["id"].to_pylist(), result["link"].to_pylist()))
|
||||||
|
assert links_by_id[str(row_count - 1)] is None
|
||||||
|
|
||||||
|
|
||||||
def test_delete(mem_db: DBConnection):
|
def test_delete(mem_db: DBConnection):
|
||||||
table = mem_db.create_table(
|
table = mem_db.create_table(
|
||||||
"my_table",
|
"my_table",
|
||||||
@@ -2115,6 +2272,27 @@ def test_delete(mem_db: DBConnection):
|
|||||||
assert table.to_arrow()["id"].to_pylist() == [1]
|
assert table.to_arrow()["id"].to_pylist() == [1]
|
||||||
|
|
||||||
|
|
||||||
|
def test_concurrent_deletes_are_thread_safe(mem_db: DBConnection):
|
||||||
|
num_workers = 8
|
||||||
|
table = mem_db.create_table(
|
||||||
|
"my_table", data=[{"id": row_id} for row_id in range(num_workers)]
|
||||||
|
)
|
||||||
|
barrier = threading.Barrier(num_workers)
|
||||||
|
|
||||||
|
def delete(row_id: int):
|
||||||
|
barrier.wait()
|
||||||
|
return table.delete(f"id = {row_id}")
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=num_workers) as pool:
|
||||||
|
results = list(pool.map(delete, range(num_workers)))
|
||||||
|
|
||||||
|
assert all(result.num_deleted_rows == 1 for result in results)
|
||||||
|
assert sorted(result.version for result in results) == list(
|
||||||
|
range(2, num_workers + 2)
|
||||||
|
)
|
||||||
|
assert table.count_rows() == 0
|
||||||
|
|
||||||
|
|
||||||
def test_delete_expr(mem_db: DBConnection):
|
def test_delete_expr(mem_db: DBConnection):
|
||||||
table = mem_db.create_table(
|
table = mem_db.create_table(
|
||||||
"my_table",
|
"my_table",
|
||||||
@@ -2165,6 +2343,20 @@ def test_update(mem_db: DBConnection):
|
|||||||
assert np.allclose(v, np.array([[1.2, 1.9], [1.1, 1.1]]))
|
assert np.allclose(v, np.array([[1.2, 1.9], [1.1, 1.1]]))
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_with_arrow_scalar(mem_db: DBConnection):
|
||||||
|
schema = pa.schema({"id": pa.int64(), "vector": pa.list_(pa.float32(), 4)})
|
||||||
|
table = mem_db.create_table("my_table", schema=schema)
|
||||||
|
table.add([{"id": 1, "vector": [1.0, 2.0, 3.0, 4.0]}])
|
||||||
|
|
||||||
|
value = table.search().select(["vector"]).limit(1).to_arrow()["vector"][0]
|
||||||
|
assert isinstance(value, pa.FixedSizeListScalar)
|
||||||
|
|
||||||
|
result = table.update(where="id == 1", values={"vector": value})
|
||||||
|
|
||||||
|
assert result.rows_updated == 1
|
||||||
|
assert table.to_arrow()["vector"].to_pylist() == [[1.0, 2.0, 3.0, 4.0]]
|
||||||
|
|
||||||
|
|
||||||
def test_update_types(mem_db: DBConnection):
|
def test_update_types(mem_db: DBConnection):
|
||||||
table = mem_db.create_table(
|
table = mem_db.create_table(
|
||||||
"my_table",
|
"my_table",
|
||||||
@@ -2332,6 +2524,55 @@ def test_merge_insert(mem_db: DBConnection):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_merge_insert_nullable_pandas_into_pydantic_schema(mem_db: DBConnection):
|
||||||
|
# Regression test for https://github.com/lancedb/lancedb/issues/2366
|
||||||
|
pd = pytest.importorskip("pandas")
|
||||||
|
|
||||||
|
class Document(LanceModel):
|
||||||
|
id: int
|
||||||
|
title: str
|
||||||
|
content: str
|
||||||
|
|
||||||
|
table = mem_db.create_table("documents", schema=Document)
|
||||||
|
table.add(
|
||||||
|
pd.DataFrame(
|
||||||
|
{
|
||||||
|
"title": ["Old title", "Unchanged"],
|
||||||
|
"id": [2, 3],
|
||||||
|
"content": ["Old content", "Keep this"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Pandas produces nullable Arrow fields, in an order that differs from the
|
||||||
|
# non-nullable Pydantic schema. This is valid as long as the data has no nulls.
|
||||||
|
new_data = pd.DataFrame(
|
||||||
|
{
|
||||||
|
"title": ["Inserted", "Updated"],
|
||||||
|
"id": [1, 2],
|
||||||
|
"content": ["New row", "New content"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
result = (
|
||||||
|
table.merge_insert("id")
|
||||||
|
.when_matched_update_all()
|
||||||
|
.when_not_matched_insert_all()
|
||||||
|
.execute(new_data)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result.num_inserted_rows == 1
|
||||||
|
assert result.num_updated_rows == 1
|
||||||
|
expected = pa.Table.from_pylist(
|
||||||
|
[
|
||||||
|
{"id": 1, "title": "Inserted", "content": "New row"},
|
||||||
|
{"id": 2, "title": "Updated", "content": "New content"},
|
||||||
|
{"id": 3, "title": "Unchanged", "content": "Keep this"},
|
||||||
|
],
|
||||||
|
schema=Document.to_arrow_schema(),
|
||||||
|
)
|
||||||
|
assert table.to_arrow().sort_by("id") == expected
|
||||||
|
|
||||||
|
|
||||||
def test_merge_insert_by_source_delete_expr(mem_db: DBConnection):
|
def test_merge_insert_by_source_delete_expr(mem_db: DBConnection):
|
||||||
table = mem_db.create_table(
|
table = mem_db.create_table(
|
||||||
"my_table",
|
"my_table",
|
||||||
@@ -2355,6 +2596,29 @@ def test_merge_insert_by_source_delete_expr(mem_db: DBConnection):
|
|||||||
assert table.to_arrow().sort_by("a") == expected
|
assert table.to_arrow().sort_by("a") == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_merge_insert_by_source_delete_reconfigure(mem_db: DBConnection):
|
||||||
|
# Calling when_not_matched_by_source_delete() again with no condition must
|
||||||
|
# widen the delete to unconditional, not keep the earlier condition around.
|
||||||
|
table = mem_db.create_table(
|
||||||
|
"my_table",
|
||||||
|
data=pa.table({"a": [1, 2, 3], "b": ["a", "b", "c"]}),
|
||||||
|
)
|
||||||
|
new_data = pa.table({"a": [2, 4], "b": ["x", "z"]})
|
||||||
|
|
||||||
|
merge_insert_res = (
|
||||||
|
table.merge_insert("a")
|
||||||
|
.when_matched_update_all()
|
||||||
|
.when_not_matched_insert_all()
|
||||||
|
.when_not_matched_by_source_delete("a > 2")
|
||||||
|
.when_not_matched_by_source_delete()
|
||||||
|
.execute(new_data)
|
||||||
|
)
|
||||||
|
assert merge_insert_res.num_deleted_rows == 2
|
||||||
|
|
||||||
|
expected = pa.table({"a": [2, 4], "b": ["x", "z"]})
|
||||||
|
assert table.to_arrow().sort_by("a") == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_merge_insert_by_source_delete_expr_async(
|
async def test_merge_insert_by_source_delete_expr_async(
|
||||||
mem_db_async: AsyncConnection,
|
mem_db_async: AsyncConnection,
|
||||||
@@ -2409,6 +2673,36 @@ def test_merge_insert_subschema(mem_db: DBConnection, data_format):
|
|||||||
assert table.to_arrow().sort_by("id") == expected
|
assert table.to_arrow().sort_by("id") == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_repeated_partial_merge_insert_with_scalar_index(mem_db: DBConnection):
|
||||||
|
def make_batch(start: int) -> pa.Table:
|
||||||
|
return pa.table(
|
||||||
|
{
|
||||||
|
"id": [f"id-{i:04}" for i in range(start, start + 100)],
|
||||||
|
"category": ["A"] * 100,
|
||||||
|
"value_a": [float(i) for i in range(start, start + 100)],
|
||||||
|
"value_b": [float(i) / 10 for i in range(100)],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
table = mem_db.create_table("my_table", data=make_batch(0))
|
||||||
|
table.add(make_batch(100))
|
||||||
|
table.add(make_batch(200))
|
||||||
|
table.create_index("id", config=BTree())
|
||||||
|
|
||||||
|
ids = [f"id-{i:04}" for i in range(100, 200)]
|
||||||
|
for value in (999.0, 888.0):
|
||||||
|
result = (
|
||||||
|
table.merge_insert("id")
|
||||||
|
.when_matched_update_all()
|
||||||
|
.execute(pa.table({"id": ids, "value_a": [value] * 100}))
|
||||||
|
)
|
||||||
|
assert result.num_updated_rows == 100
|
||||||
|
|
||||||
|
actual = table.to_arrow().sort_by("id")
|
||||||
|
assert actual.num_rows == 300
|
||||||
|
assert actual["value_a"].to_pylist()[100:200] == [888.0] * 100
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_merge_insert_async(mem_db_async: AsyncConnection):
|
async def test_merge_insert_async(mem_db_async: AsyncConnection):
|
||||||
data = pa.table({"a": [1, 2, 3], "b": ["a", "b", "c"]})
|
data = pa.table({"a": [1, 2, 3], "b": ["a", "b", "c"]})
|
||||||
@@ -2505,25 +2799,66 @@ def test_create_with_embedding_function(mem_db: DBConnection):
|
|||||||
assert actual == expected
|
assert actual == expected
|
||||||
|
|
||||||
|
|
||||||
def test_create_f16_table(mem_db: DBConnection):
|
def test_create_f16_table_from_arrow_data(mem_db: DBConnection):
|
||||||
|
dimension = 32
|
||||||
|
num_rows = 512
|
||||||
|
values = pa.array(
|
||||||
|
np.random.default_rng(42)
|
||||||
|
.standard_normal(num_rows * dimension)
|
||||||
|
.astype(np.float16)
|
||||||
|
)
|
||||||
|
df = pa.table(
|
||||||
|
{
|
||||||
|
"text": [f"s-{i}" for i in range(num_rows)],
|
||||||
|
"vector": pa.FixedSizeListArray.from_arrays(values, dimension),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
table = mem_db.create_table("f16_tbl", data=df)
|
||||||
|
assert table.schema.field("vector").type == pa.list_(pa.float16(), dimension)
|
||||||
|
table.create_index(num_partitions=2, num_sub_vectors=2)
|
||||||
|
|
||||||
|
query = df["vector"][2].as_py()
|
||||||
|
expected = table.search(query).limit(2).to_arrow()
|
||||||
|
|
||||||
|
assert "s-2" in expected["text"].to_pylist()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("accelerator", [None, "cuda"])
|
||||||
|
def test_create_f16_table(tmp_path, accelerator):
|
||||||
|
if accelerator == "cuda":
|
||||||
|
torch = pytest.importorskip("torch")
|
||||||
|
if not torch.cuda.is_available():
|
||||||
|
pytest.skip("CUDA not available")
|
||||||
|
|
||||||
class MyTable(LanceModel):
|
class MyTable(LanceModel):
|
||||||
text: str
|
text: str
|
||||||
vector: Vector(32, value_type=pa.float16())
|
vector: Vector(32, value_type=pa.float16())
|
||||||
|
|
||||||
|
rng = np.random.default_rng(42)
|
||||||
|
vectors = rng.standard_normal((512, 32)).astype(np.float16)
|
||||||
df = pa.table(
|
df = pa.table(
|
||||||
{
|
{
|
||||||
"text": [f"s-{i}" for i in range(512)],
|
"text": [f"s-{i}" for i in range(512)],
|
||||||
"vector": [np.random.randn(32).astype(np.float16) for _ in range(512)],
|
"vector": list(vectors),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
table = mem_db.create_table(
|
db = lancedb.connect(tmp_path)
|
||||||
|
table = db.create_table(
|
||||||
"f16_tbl",
|
"f16_tbl",
|
||||||
schema=MyTable,
|
schema=MyTable,
|
||||||
)
|
)
|
||||||
table.add(df)
|
table.add(df)
|
||||||
table.create_index(num_partitions=2, num_sub_vectors=2)
|
table.create_index(
|
||||||
|
"vector",
|
||||||
|
config=IvfPq(
|
||||||
|
num_partitions=2,
|
||||||
|
num_sub_vectors=2,
|
||||||
|
accelerator=accelerator,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
query = df["vector"][2].as_py()
|
# Match the issue's float64 query against an explicitly typed float16 column.
|
||||||
|
query = vectors[2].astype(np.float64)
|
||||||
expected = table.search(query).limit(2).to_arrow()
|
expected = table.search(query).limit(2).to_arrow()
|
||||||
|
|
||||||
assert "s-2" in expected["text"].to_pylist()
|
assert "s-2" in expected["text"].to_pylist()
|
||||||
@@ -3087,9 +3422,6 @@ def test_consistency(tmp_path, consistency_interval):
|
|||||||
|
|
||||||
db2 = lancedb.connect(tmp_path, read_consistency_interval=consistency_interval)
|
db2 = lancedb.connect(tmp_path, read_consistency_interval=consistency_interval)
|
||||||
table2 = db2.open_table("my_table")
|
table2 = db2.open_table("my_table")
|
||||||
if consistency_interval is not None:
|
|
||||||
assert "read_consistency_interval=datetime.timedelta(" in repr(db2)
|
|
||||||
assert "read_consistency_interval=datetime.timedelta(" in repr(table2)
|
|
||||||
assert table2.version == table.version
|
assert table2.version == table.version
|
||||||
|
|
||||||
table.add([{"id": 1}])
|
table.add([{"id": 1}])
|
||||||
@@ -3438,8 +3770,8 @@ def test_create_table_empty_list_no_schema_error(mem_db: DBConnection):
|
|||||||
mem_db.create_table("test_empty_no_schema", data=[])
|
mem_db.create_table("test_empty_no_schema", data=[])
|
||||||
|
|
||||||
|
|
||||||
def test_add_table_with_empty_embeddings(tmp_path):
|
def test_create_table_without_data_with_vector_schema(tmp_path):
|
||||||
"""Test exact scenario from issue #1968
|
"""Test exact scenario from issue #1968.
|
||||||
|
|
||||||
Regression test for issue #1968:
|
Regression test for issue #1968:
|
||||||
https://github.com/lancedb/lancedb/issues/1968
|
https://github.com/lancedb/lancedb/issues/1968
|
||||||
@@ -3451,6 +3783,9 @@ def test_add_table_with_empty_embeddings(tmp_path):
|
|||||||
embedding: Vector(16)
|
embedding: Vector(16)
|
||||||
|
|
||||||
table = db.create_table("test", schema=MySchema)
|
table = db.create_table("test", schema=MySchema)
|
||||||
|
assert table.count_rows() == 0
|
||||||
|
assert table.schema == MySchema.to_arrow_schema()
|
||||||
|
|
||||||
table.add(
|
table.add(
|
||||||
[{"text": "bar", "embedding": [0.1] * 16}],
|
[{"text": "bar", "embedding": [0.1] * 16}],
|
||||||
on_bad_vectors="drop",
|
on_bad_vectors="drop",
|
||||||
|
|||||||
@@ -75,6 +75,22 @@ class TestVoyageAIModelRegistration:
|
|||||||
with pytest.raises(ValueError, match="not supported"):
|
with pytest.raises(ValueError, match="not supported"):
|
||||||
func.ndims()
|
func.ndims()
|
||||||
|
|
||||||
|
def test_voyage3_source_embeddings_use_text_api(self, mock_voyageai_client):
|
||||||
|
"""Regression test for text table data being sent to the multimodal API."""
|
||||||
|
mock_voyageai_client.tokenize.return_value = [["hello", "world"]]
|
||||||
|
mock_voyageai_client.embed.return_value.embeddings = [[0.1] * 1024]
|
||||||
|
|
||||||
|
registry = get_registry()
|
||||||
|
func = registry.get("voyageai").create(name="voyage-3")
|
||||||
|
|
||||||
|
embeddings = func.compute_source_embeddings("hello world")
|
||||||
|
|
||||||
|
assert embeddings == [[0.1] * 1024]
|
||||||
|
mock_voyageai_client.embed.assert_called_once_with(
|
||||||
|
texts=["hello world"], model="voyage-3", input_type="document"
|
||||||
|
)
|
||||||
|
mock_voyageai_client.multimodal_embed.assert_not_called()
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"model_name",
|
"model_name",
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
from typing import assert_type
|
||||||
|
|
||||||
|
import lancedb
|
||||||
|
from lancedb import AsyncConnection, DBConnection
|
||||||
|
|
||||||
|
|
||||||
|
def check_connect_type() -> None:
|
||||||
|
assert_type(lancedb.connect("memory://"), DBConnection)
|
||||||
|
|
||||||
|
|
||||||
|
async def check_connect_async_type() -> None:
|
||||||
|
assert_type(await lancedb.connect_async("memory://"), AsyncConnection)
|
||||||
@@ -13,7 +13,11 @@ use crate::{
|
|||||||
runtime::future_into_py,
|
runtime::future_into_py,
|
||||||
table::Table,
|
table::Table,
|
||||||
};
|
};
|
||||||
use arrow::{datatypes::Schema, ffi_stream::ArrowArrayStreamReader, pyarrow::FromPyArrow};
|
use arrow::{
|
||||||
|
datatypes::Schema,
|
||||||
|
ffi_stream::ArrowArrayStreamReader,
|
||||||
|
pyarrow::{FromPyArrow, ToPyArrow},
|
||||||
|
};
|
||||||
use lancedb::{
|
use lancedb::{
|
||||||
connection::Connection as LanceConnection,
|
connection::Connection as LanceConnection,
|
||||||
connection::NamespaceClientPushdownOperation,
|
connection::NamespaceClientPushdownOperation,
|
||||||
@@ -24,7 +28,7 @@ use pyo3::{
|
|||||||
Bound, FromPyObject, Py, PyAny, PyRef, PyResult, Python,
|
Bound, FromPyObject, Py, PyAny, PyRef, PyResult, Python,
|
||||||
exceptions::{PyRuntimeError, PyValueError},
|
exceptions::{PyRuntimeError, PyValueError},
|
||||||
pyclass, pyfunction, pymethods,
|
pyclass, pyfunction, pymethods,
|
||||||
types::{PyDict, PyDictMethods},
|
types::{PyDict, PyDictMethods, PyList, PyListMethods},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
@@ -536,6 +540,55 @@ impl Connection {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn job(&self, job_id: String) -> PyResult<crate::job::Job> {
|
||||||
|
let inner = self.get_inner()?.clone();
|
||||||
|
Ok(crate::job::Job::new(inner.job(job_id).infer_error()?))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_jobs(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.get_inner()?.clone();
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
let jobs = inner.list_jobs().await.infer_error()?;
|
||||||
|
Ok(jobs
|
||||||
|
.into_iter()
|
||||||
|
.map(crate::job::JobInfo::from)
|
||||||
|
.collect::<Vec<_>>())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_job(self_: PyRef<'_, Self>, job_id: String) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.get_inner()?.clone();
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
let description = inner.get_job(&job_id).await.infer_error()?;
|
||||||
|
Ok(description.map(crate::job::JobDescription::from))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cancel_job(self_: PyRef<'_, Self>, job_id: String) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.get_inner()?.clone();
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
inner.cancel_job(&job_id).await.infer_error()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pyo3(signature = (job_id=None))]
|
||||||
|
pub fn job_history(
|
||||||
|
self_: PyRef<'_, Self>,
|
||||||
|
job_id: Option<String>,
|
||||||
|
) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.get_inner()?.clone();
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
let batches = inner.job_history(job_id.as_deref()).await.infer_error()?;
|
||||||
|
Python::attach(|py| {
|
||||||
|
let list = PyList::empty(py);
|
||||||
|
for batch in batches {
|
||||||
|
list.append(batch.to_pyarrow(py)?)?;
|
||||||
|
}
|
||||||
|
Ok(list.unbind())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
|
|||||||
@@ -102,6 +102,18 @@ impl<T> PythonErrorExt<T> for std::result::Result<T, LanceError> {
|
|||||||
err.setattr(intern!(py, "__cause__"), cause_err)?;
|
err.setattr(intern!(py, "__cause__"), cause_err)?;
|
||||||
Err(PyErr::from_value(err))
|
Err(PyErr::from_value(err))
|
||||||
}),
|
}),
|
||||||
|
LanceError::JobFailed { .. } => Python::attach(|py| {
|
||||||
|
let cls = py
|
||||||
|
.import(intern!(py, "lancedb.exceptions"))?
|
||||||
|
.getattr(intern!(py, "JobFailedError"))?;
|
||||||
|
Err(PyErr::from_value(cls.call1((err.to_string(),))?))
|
||||||
|
}),
|
||||||
|
LanceError::JobCancelled { .. } => Python::attach(|py| {
|
||||||
|
let cls = py
|
||||||
|
.import(intern!(py, "lancedb.exceptions"))?
|
||||||
|
.getattr(intern!(py, "JobCancelledError"))?;
|
||||||
|
Err(PyErr::from_value(cls.call1((err.to_string(),))?))
|
||||||
|
}),
|
||||||
_ => self.runtime_error(),
|
_ => self.runtime_error(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::runtime::future_into_py;
|
||||||
|
use pyo3::{Bound, PyAny, PyRef, PyResult, pyclass, pymethods};
|
||||||
|
|
||||||
|
use crate::error::PythonErrorExt;
|
||||||
|
|
||||||
|
#[pyclass]
|
||||||
|
pub struct Job {
|
||||||
|
inner: Arc<lancedb::Job>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Job {
|
||||||
|
pub(crate) fn new(inner: lancedb::Job) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: Arc::new(inner),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
impl Job {
|
||||||
|
#[getter]
|
||||||
|
pub fn id(&self) -> Option<String> {
|
||||||
|
self.inner.id().map(str::to_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn status(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.inner.clone();
|
||||||
|
future_into_py(
|
||||||
|
self_.py(),
|
||||||
|
async move { inner.status().await.infer_error() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn wait(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.inner.clone();
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
inner.wait().await.infer_error()?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cancel(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
let inner = self_.inner.clone();
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
inner.cancel().await.infer_error()?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row from `Connection.list_jobs`: one server-side job.
|
||||||
|
#[pyclass(get_all, skip_from_py_object)]
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct JobInfo {
|
||||||
|
job_id: String,
|
||||||
|
table: String,
|
||||||
|
job_type: String,
|
||||||
|
state: String,
|
||||||
|
created_at_millis: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
impl JobInfo {
|
||||||
|
fn __repr__(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"JobInfo(job_id={:?}, table={:?}, job_type={:?}, state={:?}, created_at_millis={})",
|
||||||
|
self.job_id, self.table, self.job_type, self.state, self.created_at_millis
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<lancedb::database::JobInfo> for JobInfo {
|
||||||
|
fn from(info: lancedb::database::JobInfo) -> Self {
|
||||||
|
Self {
|
||||||
|
job_id: info.job_id,
|
||||||
|
table: info.table,
|
||||||
|
job_type: info.job_type,
|
||||||
|
state: info.state,
|
||||||
|
created_at_millis: info.created_at_millis,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The server's account of why a job failed.
|
||||||
|
#[pyclass(get_all, skip_from_py_object)]
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct JobFailureInfo {
|
||||||
|
phase: Option<String>,
|
||||||
|
message: Option<String>,
|
||||||
|
retryable: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
impl JobFailureInfo {
|
||||||
|
fn __repr__(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"JobFailureInfo(phase={:?}, message={:?}, retryable={:?})",
|
||||||
|
self.phase, self.message, self.retryable
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A described job from `Connection.get_job`.
|
||||||
|
#[pyclass(get_all, skip_from_py_object)]
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct JobDescription {
|
||||||
|
job_id: String,
|
||||||
|
job_type: String,
|
||||||
|
state: String,
|
||||||
|
creation_ms: i64,
|
||||||
|
spec_json: Option<String>,
|
||||||
|
failure: Option<JobFailureInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
impl JobDescription {
|
||||||
|
fn __repr__(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"JobDescription(job_id={:?}, job_type={:?}, state={:?}, creation_ms={})",
|
||||||
|
self.job_id, self.job_type, self.state, self.creation_ms
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<lancedb::database::JobDescription> for JobDescription {
|
||||||
|
fn from(description: lancedb::database::JobDescription) -> Self {
|
||||||
|
Self {
|
||||||
|
job_id: description.job_id,
|
||||||
|
job_type: description.job_type,
|
||||||
|
state: description.state,
|
||||||
|
creation_ms: description.creation_ms,
|
||||||
|
spec_json: (!description.spec.is_null()).then(|| description.spec.to_string()),
|
||||||
|
failure: description.failure.map(|failure| JobFailureInfo {
|
||||||
|
phase: failure.phase,
|
||||||
|
message: failure.message,
|
||||||
|
retryable: failure.retryable,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ pub mod error;
|
|||||||
pub mod expr;
|
pub mod expr;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
pub mod index;
|
pub mod index;
|
||||||
|
pub mod job;
|
||||||
pub mod namespace;
|
pub mod namespace;
|
||||||
pub mod oauth;
|
pub mod oauth;
|
||||||
pub mod otel;
|
pub mod otel;
|
||||||
@@ -44,6 +45,10 @@ pub fn _lancedb(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|||||||
m.add_class::<Connection>()?;
|
m.add_class::<Connection>()?;
|
||||||
m.add_class::<Session>()?;
|
m.add_class::<Session>()?;
|
||||||
m.add_class::<Table>()?;
|
m.add_class::<Table>()?;
|
||||||
|
m.add_class::<crate::job::Job>()?;
|
||||||
|
m.add_class::<crate::job::JobInfo>()?;
|
||||||
|
m.add_class::<crate::job::JobDescription>()?;
|
||||||
|
m.add_class::<crate::job::JobFailureInfo>()?;
|
||||||
m.add_class::<PyBlobFile>()?;
|
m.add_class::<PyBlobFile>()?;
|
||||||
m.add_class::<IndexConfig>()?;
|
m.add_class::<IndexConfig>()?;
|
||||||
m.add_class::<Query>()?;
|
m.add_class::<Query>()?;
|
||||||
|
|||||||
+71
-13
@@ -426,9 +426,11 @@ pub struct PyBlobFile {
|
|||||||
impl PyBlobFile {
|
impl PyBlobFile {
|
||||||
fn read_bytes(self_: PyRef<'_, Self>) -> PyResult<Py<PyBytes>> {
|
fn read_bytes(self_: PyRef<'_, Self>) -> PyResult<Py<PyBytes>> {
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
let bytes = block_on(async move { inner.read().await })
|
let py = self_.py();
|
||||||
|
let bytes = py
|
||||||
|
.detach(move || block_on(async move { inner.read().await }))
|
||||||
.map_err(|e| PyRuntimeError::new_err(format!("blob read failed: {e}")))?;
|
.map_err(|e| PyRuntimeError::new_err(format!("blob read failed: {e}")))?;
|
||||||
Ok(PyBytes::new(self_.py(), bytes.as_ref()).unbind())
|
Ok(PyBytes::new(py, bytes.as_ref()).unbind())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
pub fn read(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
||||||
@@ -444,24 +446,32 @@ impl PyBlobFile {
|
|||||||
|
|
||||||
fn close(self_: PyRef<'_, Self>) -> PyResult<()> {
|
fn close(self_: PyRef<'_, Self>) -> PyResult<()> {
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
block_on(async move { inner.close().await })
|
self_
|
||||||
|
.py()
|
||||||
|
.detach(move || block_on(async move { inner.close().await }))
|
||||||
.map_err(|e| PyRuntimeError::new_err(format!("blob close failed: {e}")))
|
.map_err(|e| PyRuntimeError::new_err(format!("blob close failed: {e}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_closed(self_: PyRef<'_, Self>) -> bool {
|
fn is_closed(self_: PyRef<'_, Self>) -> bool {
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
block_on(async move { inner.is_closed().await })
|
self_
|
||||||
|
.py()
|
||||||
|
.detach(move || block_on(async move { inner.is_closed().await }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn seek(self_: PyRef<'_, Self>, position: u64) -> PyResult<()> {
|
fn seek(self_: PyRef<'_, Self>, position: u64) -> PyResult<()> {
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
block_on(async move { inner.seek(position).await })
|
self_
|
||||||
|
.py()
|
||||||
|
.detach(move || block_on(async move { inner.seek(position).await }))
|
||||||
.map_err(|e| PyRuntimeError::new_err(format!("blob seek failed: {e}")))
|
.map_err(|e| PyRuntimeError::new_err(format!("blob seek failed: {e}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tell(self_: PyRef<'_, Self>) -> PyResult<u64> {
|
fn tell(self_: PyRef<'_, Self>) -> PyResult<u64> {
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
block_on(async move { inner.tell().await })
|
self_
|
||||||
|
.py()
|
||||||
|
.detach(move || block_on(async move { inner.tell().await }))
|
||||||
.map_err(|e| PyRuntimeError::new_err(format!("blob tell failed: {e}")))
|
.map_err(|e| PyRuntimeError::new_err(format!("blob tell failed: {e}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,16 +485,20 @@ impl PyBlobFile {
|
|||||||
.checked_add(length as u64)
|
.checked_add(length as u64)
|
||||||
.ok_or_else(|| PyValueError::new_err("offset + length overflowed"))?;
|
.ok_or_else(|| PyValueError::new_err("offset + length overflowed"))?;
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
let bytes = block_on(async move { inner.read_range(offset..end).await })
|
let py = self_.py();
|
||||||
|
let bytes = py
|
||||||
|
.detach(move || block_on(async move { inner.read_range(offset..end).await }))
|
||||||
.map_err(|e| PyRuntimeError::new_err(format!("blob read_range failed: {e}")))?;
|
.map_err(|e| PyRuntimeError::new_err(format!("blob read_range failed: {e}")))?;
|
||||||
Ok(PyBytes::new(self_.py(), bytes.as_ref()).unbind())
|
Ok(PyBytes::new(py, bytes.as_ref()).unbind())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_up_to(self_: PyRef<'_, Self>, length: usize) -> PyResult<Py<PyBytes>> {
|
fn read_up_to(self_: PyRef<'_, Self>, length: usize) -> PyResult<Py<PyBytes>> {
|
||||||
let inner = self_.inner.clone();
|
let inner = self_.inner.clone();
|
||||||
let bytes = block_on(async move { inner.read_up_to(length).await })
|
let py = self_.py();
|
||||||
.map_err(|e| PyRuntimeError::new_err(format!("blob read failed: {e}")))?;
|
let bytes = py
|
||||||
Ok(PyBytes::new(self_.py(), bytes.as_ref()).unbind())
|
.detach(move || block_on(async move { inner.read_up_to(length).await }))
|
||||||
|
.map_err(|e| PyRuntimeError::new_err(format!("blob read_up_to failed: {e}")))?;
|
||||||
|
Ok(PyBytes::new(py, bytes.as_ref()).unbind())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,6 +745,9 @@ impl Table {
|
|||||||
|
|
||||||
#[allow(private_interfaces)]
|
#[allow(private_interfaces)]
|
||||||
pub fn delete(self_: PyRef<'_, Self>, condition: PredicateArg) -> PyResult<Bound<'_, PyAny>> {
|
pub fn delete(self_: PyRef<'_, Self>, condition: PredicateArg) -> PyResult<Bound<'_, PyAny>> {
|
||||||
|
// Do not hold the Python borrow across the await. The cloned Rust table
|
||||||
|
// handle is thread-safe and allows deletes on the same Python table to
|
||||||
|
// run concurrently without PyO3 reporting "Already borrowed".
|
||||||
let inner = self_.inner_ref()?.clone();
|
let inner = self_.inner_ref()?.clone();
|
||||||
future_into_py(self_.py(), async move {
|
future_into_py(self_.py(), async move {
|
||||||
let result = match &condition {
|
let result = match &condition {
|
||||||
@@ -805,6 +822,37 @@ impl Table {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyo3(signature = (column, index=None, replace=None, wait_timeout=None, *, name=None, train=None))]
|
||||||
|
pub fn create_index_async<'a>(
|
||||||
|
self_: PyRef<'a, Self>,
|
||||||
|
column: String,
|
||||||
|
index: Option<Bound<'_, PyAny>>,
|
||||||
|
replace: Option<bool>,
|
||||||
|
wait_timeout: Option<Bound<'_, PyAny>>,
|
||||||
|
name: Option<String>,
|
||||||
|
train: Option<bool>,
|
||||||
|
) -> PyResult<Bound<'a, PyAny>> {
|
||||||
|
let index = extract_index_params(&index)?;
|
||||||
|
let timeout = wait_timeout.map(|t| t.extract::<std::time::Duration>().unwrap());
|
||||||
|
let mut op = self_
|
||||||
|
.inner_ref()?
|
||||||
|
.create_index_with_timeout(&[column], index, timeout);
|
||||||
|
if let Some(replace) = replace {
|
||||||
|
op = op.replace(replace);
|
||||||
|
}
|
||||||
|
if let Some(name) = name {
|
||||||
|
op = op.name(name);
|
||||||
|
}
|
||||||
|
if let Some(train) = train {
|
||||||
|
op = op.train(train);
|
||||||
|
}
|
||||||
|
|
||||||
|
future_into_py(self_.py(), async move {
|
||||||
|
let job = op.execute_async().await.infer_error()?;
|
||||||
|
Ok(crate::job::Job::new(job))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn drop_index(self_: PyRef<'_, Self>, index_name: String) -> PyResult<Bound<'_, PyAny>> {
|
pub fn drop_index(self_: PyRef<'_, Self>, index_name: String) -> PyResult<Bound<'_, PyAny>> {
|
||||||
let inner = self_.inner_ref()?.clone();
|
let inner = self_.inner_ref()?.clone();
|
||||||
future_into_py(self_.py(), async move {
|
future_into_py(self_.py(), async move {
|
||||||
@@ -1330,7 +1378,12 @@ impl Table {
|
|||||||
|
|
||||||
let inner = self_.inner_ref()?.clone();
|
let inner = self_.inner_ref()?.clone();
|
||||||
future_into_py(self_.py(), async move {
|
future_into_py(self_.py(), async move {
|
||||||
let result = inner.add_columns(definitions, None).await.infer_error()?;
|
let result = inner
|
||||||
|
.add_columns()
|
||||||
|
.transform(definitions)
|
||||||
|
.execute()
|
||||||
|
.await
|
||||||
|
.infer_error()?;
|
||||||
Ok(AddColumnsResult::from(result))
|
Ok(AddColumnsResult::from(result))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1344,7 +1397,12 @@ impl Table {
|
|||||||
|
|
||||||
let inner = self_.inner_ref()?.clone();
|
let inner = self_.inner_ref()?.clone();
|
||||||
future_into_py(self_.py(), async move {
|
future_into_py(self_.py(), async move {
|
||||||
let result = inner.add_columns(transform, None).await.infer_error()?;
|
let result = inner
|
||||||
|
.add_columns()
|
||||||
|
.transform(transform)
|
||||||
|
.execute()
|
||||||
|
.await
|
||||||
|
.infer_error()?;
|
||||||
Ok(AddColumnsResult::from(result))
|
Ok(AddColumnsResult::from(result))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+1169
-1067
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.95.0"
|
channel = "1.97.0"
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ lance-namespace = { workspace = true }
|
|||||||
lance-namespace-impls = { workspace = true }
|
lance-namespace-impls = { workspace = true }
|
||||||
metrics = { workspace = true, optional = true }
|
metrics = { workspace = true, optional = true }
|
||||||
metrics-util = { workspace = true, optional = true }
|
metrics-util = { workspace = true, optional = true }
|
||||||
# Pin the transitive GooseFS SDK until the 0.1.6 compile break is fixed upstream.
|
# Pin the GooseFS SDK to the version required by Lance's OpenDAL dependency.
|
||||||
goosefs-sdk = { version = "=0.1.5", optional = true }
|
goosefs-sdk = { version = "=0.1.9", optional = true }
|
||||||
moka = { workspace = true }
|
moka = { workspace = true }
|
||||||
pin-project = { workspace = true }
|
pin-project = { workspace = true }
|
||||||
tokio = { version = "1.23", features = ["rt-multi-thread", "sync"] }
|
tokio = { version = "1.23", features = ["rt-multi-thread", "sync"] }
|
||||||
@@ -75,6 +75,8 @@ reqwest = { version = "0.12.0", default-features = false, features = [
|
|||||||
"http2",
|
"http2",
|
||||||
"json",
|
"json",
|
||||||
"macos-system-configuration",
|
"macos-system-configuration",
|
||||||
|
# Avoid linking OpenSSL into Python wheels, which breaks on FIPS hosts.
|
||||||
|
"rustls-tls-native-roots",
|
||||||
"stream",
|
"stream",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
http = { version = "1", optional = true } # Matching what is in reqwest
|
http = { version = "1", optional = true } # Matching what is in reqwest
|
||||||
|
|||||||
+199
-3
@@ -9,6 +9,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Blob tables require Lance file format >= 2.2 and stable row ids at create.
|
//! Blob tables require Lance file format >= 2.2 and stable row ids at create.
|
||||||
|
|
||||||
|
use std::ops::Range;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use arrow_array::LargeBinaryArray;
|
use arrow_array::LargeBinaryArray;
|
||||||
@@ -16,11 +17,203 @@ use arrow_array::builder::LargeBinaryBuilder;
|
|||||||
use arrow_schema::{DataType, Field, Schema};
|
use arrow_schema::{DataType, Field, Schema};
|
||||||
use lance::dataset::{BlobRangeRequest as LanceBlobRangeRequest, Dataset, WriteParams};
|
use lance::dataset::{BlobRangeRequest as LanceBlobRangeRequest, Dataset, WriteParams};
|
||||||
use lance_arrow::FieldExt;
|
use lance_arrow::FieldExt;
|
||||||
use lance_encoding::version::LanceFileVersion;
|
use lance_file::version::LanceFileVersion;
|
||||||
|
use lance_io::object_store::ObjectStore;
|
||||||
|
use object_store::path::Path;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
|
|
||||||
pub use lance::dataset::BlobFile;
|
/// Seekable handle for one blob value, backed by local storage or a remote
|
||||||
|
/// HTTP byte-range endpoint.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BlobFile {
|
||||||
|
inner: BlobFileInner,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum BlobFileInner {
|
||||||
|
Native(lance::dataset::BlobFile),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
Remote(Box<crate::remote::table::blobs::RemoteBlobFile>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<lance::dataset::BlobFile> for BlobFile {
|
||||||
|
fn from(value: lance::dataset::BlobFile) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: BlobFileInner::Native(value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
impl From<crate::remote::table::blobs::RemoteBlobFile> for BlobFile {
|
||||||
|
fn from(value: crate::remote::table::blobs::RemoteBlobFile) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: BlobFileInner::Remote(Box::new(value)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BlobFile {
|
||||||
|
/// Inline reader over a data-file slice.
|
||||||
|
pub fn new_inline(
|
||||||
|
object_store: Arc<ObjectStore>,
|
||||||
|
path: Path,
|
||||||
|
position: u64,
|
||||||
|
size: u64,
|
||||||
|
) -> Self {
|
||||||
|
lance::dataset::BlobFile::new_inline(object_store, path, position, size).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dedicated sidecar-file reader.
|
||||||
|
pub fn new_dedicated(object_store: Arc<ObjectStore>, path: Path, size: u64) -> Self {
|
||||||
|
lance::dataset::BlobFile::new_dedicated(object_store, path, size).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Packed reader for a slice in a shared sidecar.
|
||||||
|
pub fn new_packed(
|
||||||
|
object_store: Arc<ObjectStore>,
|
||||||
|
path: Path,
|
||||||
|
position: u64,
|
||||||
|
size: u64,
|
||||||
|
) -> Self {
|
||||||
|
lance::dataset::BlobFile::new_packed(object_store, path, position, size).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// External reader at a resolved object location.
|
||||||
|
pub fn new_external(
|
||||||
|
object_store: Arc<ObjectStore>,
|
||||||
|
path: Path,
|
||||||
|
uri: String,
|
||||||
|
position: u64,
|
||||||
|
size: u64,
|
||||||
|
) -> Self {
|
||||||
|
lance::dataset::BlobFile::new_external(object_store, path, uri, position, size).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Close the handle.
|
||||||
|
pub async fn close(&self) -> lance_core::Result<()> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.close().await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.close().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the handle is closed.
|
||||||
|
pub async fn is_closed(&self) -> bool {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.is_closed().await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.is_closed(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read a range without moving the cursor.
|
||||||
|
pub async fn read_range(&self, range: Range<u64>) -> lance_core::Result<bytes::Bytes> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.read_range(range).await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.read_range(range).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read ranges without moving the cursor.
|
||||||
|
pub async fn read_ranges(
|
||||||
|
&self,
|
||||||
|
ranges: &[Range<u64>],
|
||||||
|
) -> lance_core::Result<Vec<bytes::Bytes>> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.read_ranges(ranges).await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.read_ranges(ranges).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read from the cursor to the end.
|
||||||
|
pub async fn read(&self) -> lance_core::Result<bytes::Bytes> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.read().await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.read().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read up to `len` bytes and advance the cursor.
|
||||||
|
pub async fn read_up_to(&self, len: usize) -> lance_core::Result<bytes::Bytes> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.read_up_to(len).await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.read_up_to(len).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Move the cursor to `new_cursor`.
|
||||||
|
pub async fn seek(&self, new_cursor: u64) -> lance_core::Result<()> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.seek(new_cursor).await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.seek(new_cursor).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Current cursor position.
|
||||||
|
pub async fn tell(&self) -> lance_core::Result<u64> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.tell().await,
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.tell().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Blob length in bytes.
|
||||||
|
pub fn size(&self) -> u64 {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.size(),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(file) => file.size(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Physical byte offset in the data file. `None` on remote handles. The
|
||||||
|
/// Cloud byte-range route does not expose storage layout.
|
||||||
|
pub fn position(&self) -> Option<u64> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => Some(file.position()),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Path of the data file holding the blob. `None` on remote handles. The
|
||||||
|
/// Cloud byte-range route does not expose storage layout.
|
||||||
|
pub fn data_path(&self) -> Option<&Path> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => Some(file.data_path()),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Native storage layout. `None` on remote handles. The Cloud byte-range
|
||||||
|
/// route does not expose layout.
|
||||||
|
pub fn kind(&self) -> Option<lance_core::datatypes::BlobKind> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => Some(file.kind()),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// External URI for native handles. Remote handles do not expose storage URIs.
|
||||||
|
pub fn uri(&self) -> Option<&str> {
|
||||||
|
match &self.inner {
|
||||||
|
BlobFileInner::Native(file) => file.uri(),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
BlobFileInner::Remote(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// One row-specific blob range read request.
|
/// One row-specific blob range read request.
|
||||||
///
|
///
|
||||||
@@ -264,7 +457,10 @@ pub(crate) async fn take_blob_files_aligned(
|
|||||||
|
|
||||||
let handles = dataset.take_blobs(row_ids, column).await?;
|
let handles = dataset.take_blobs(row_ids, column).await?;
|
||||||
ensure_all_row_ids_resolved(column, row_ids.len(), handles.len())?;
|
ensure_all_row_ids_resolved(column, row_ids.len(), handles.len())?;
|
||||||
Ok(handles)
|
Ok(handles
|
||||||
|
.into_iter()
|
||||||
|
.map(|handle| handle.map(Into::into))
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ use crate::connection::create_table::CreateTableBuilder;
|
|||||||
use crate::data::scannable::Scannable;
|
use crate::data::scannable::Scannable;
|
||||||
use crate::database::listing::ListingDatabase;
|
use crate::database::listing::ListingDatabase;
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
CloneTableRequest, Database, DatabaseOptions, OpenTableRequest, ReadConsistency,
|
CloneTableRequest, Database, DatabaseOptions, JobDescription, JobInfo, OpenTableRequest,
|
||||||
TableNamesRequest,
|
ReadConsistency, TableNamesRequest,
|
||||||
};
|
};
|
||||||
use crate::embeddings::{EmbeddingRegistry, MemoryRegistry};
|
use crate::embeddings::{EmbeddingRegistry, MemoryRegistry};
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
@@ -34,7 +34,7 @@ use crate::remote::{
|
|||||||
db::{OPT_REMOTE_API_KEY, OPT_REMOTE_HOST_OVERRIDE, OPT_REMOTE_REGION},
|
db::{OPT_REMOTE_API_KEY, OPT_REMOTE_HOST_OVERRIDE, OPT_REMOTE_REGION},
|
||||||
};
|
};
|
||||||
use lance::io::ObjectStoreParams;
|
use lance::io::ObjectStoreParams;
|
||||||
pub use lance_encoding::version::LanceFileVersion;
|
pub use lance_file::version::LanceFileVersion;
|
||||||
#[cfg(feature = "remote")]
|
#[cfg(feature = "remote")]
|
||||||
use lance_io::object_store::StorageOptions;
|
use lance_io::object_store::StorageOptions;
|
||||||
use lance_io::object_store::{StorageOptionsAccessor, StorageOptionsProvider};
|
use lance_io::object_store::{StorageOptionsAccessor, StorageOptionsProvider};
|
||||||
@@ -456,6 +456,10 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
/// Created [`TableRef`], or [`Error::TableNotFound`] if the table does not exist.
|
/// Created [`TableRef`], or [`Error::TableNotFound`] if the table does not exist.
|
||||||
|
/// If the table's storage is present but holds no readable dataset (for example a
|
||||||
|
/// `<name>.lance` directory left behind by an interrupted drop and re-create, which
|
||||||
|
/// [`Self::table_names`] still lists) this returns [`Error::TableCorrupted`]
|
||||||
|
/// instead.
|
||||||
pub fn open_table(&self, name: impl Into<String>) -> OpenTableBuilder {
|
pub fn open_table(&self, name: impl Into<String>) -> OpenTableBuilder {
|
||||||
OpenTableBuilder::new(
|
OpenTableBuilder::new(
|
||||||
self.internal.clone(),
|
self.internal.clone(),
|
||||||
@@ -513,6 +517,39 @@ impl Connection {
|
|||||||
self.internal.read_consistency().await
|
self.internal.read_consistency().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [`crate::job::Job`] handle for a server-side job by id, suitable for
|
||||||
|
/// waiting on or cancelling the job.
|
||||||
|
///
|
||||||
|
/// The handle is constructed without a server round trip; an unknown id
|
||||||
|
/// surfaces when the handle is used. Only server-backed databases support
|
||||||
|
/// job handles by id.
|
||||||
|
pub fn job(&self, job_id: impl AsRef<str>) -> Result<crate::job::Job> {
|
||||||
|
self.internal.job(job_id.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List server-side jobs across the database's tables.
|
||||||
|
pub async fn list_jobs(&self) -> Result<Vec<JobInfo>> {
|
||||||
|
self.internal.list_jobs().await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Describe a single server-side job by id. `None` when the server has no
|
||||||
|
/// such job.
|
||||||
|
pub async fn get_job(&self, job_id: impl AsRef<str>) -> Result<Option<JobDescription>> {
|
||||||
|
self.internal.get_job(job_id.as_ref()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Request cancellation of a server-side job by id. Returns true if the
|
||||||
|
/// server accepted the cancellation, false if no such job exists.
|
||||||
|
pub async fn cancel_job(&self, job_id: impl AsRef<str>) -> Result<bool> {
|
||||||
|
self.internal.cancel_job(job_id.as_ref()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The lifecycle event history of a server-side job (all jobs when
|
||||||
|
/// `job_id` is `None`), as recorded Arrow batches.
|
||||||
|
pub async fn job_history(&self, job_id: Option<&str>) -> Result<Vec<RecordBatch>> {
|
||||||
|
self.internal.job_history(job_id).await
|
||||||
|
}
|
||||||
|
|
||||||
/// Drop a table in the database.
|
/// Drop a table in the database.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|||||||
@@ -202,6 +202,17 @@ mod tests {
|
|||||||
assert_eq!(table.count_rows(None).await.unwrap(), 0);
|
assert_eq!(table.count_rows(None).await.unwrap(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn create_table_in_named_memory_database() {
|
||||||
|
let db = connect("memory://foo").execute().await.unwrap();
|
||||||
|
let batch = record_batch!(("id", Int64, [1, 2, 3])).unwrap();
|
||||||
|
|
||||||
|
let table = db.create_table("my_table", batch).execute().await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(table.uri().await.unwrap(), "memory://foo/my_table.lance");
|
||||||
|
assert_eq!(table.count_rows(None).await.unwrap(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
async fn test_create_table_with_data<T>(data: T)
|
async fn test_create_table_with_data<T>(data: T)
|
||||||
where
|
where
|
||||||
T: Scannable + 'static,
|
T: Scannable + 'static,
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use arrow_array::RecordBatch;
|
||||||
|
|
||||||
use lance::dataset::ReadParams;
|
use lance::dataset::ReadParams;
|
||||||
use lance_namespace::LanceNamespace;
|
use lance_namespace::LanceNamespace;
|
||||||
use lance_namespace::models::{
|
use lance_namespace::models::{
|
||||||
@@ -200,6 +202,45 @@ pub enum ReadConsistency {
|
|||||||
Strong,
|
Strong,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A row from [`Database::list_jobs`]: one server-side job (index build,
|
||||||
|
/// compaction, column refresh, ...).
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct JobInfo {
|
||||||
|
/// The job id -- what [`Database::get_job`] and [`Database::cancel_job`]
|
||||||
|
/// accept.
|
||||||
|
pub job_id: String,
|
||||||
|
/// The table the job runs against, without URI or namespace.
|
||||||
|
pub table: String,
|
||||||
|
pub job_type: String,
|
||||||
|
/// Lifecycle state: "running", "finished", "failed", or "cancelled".
|
||||||
|
pub state: String,
|
||||||
|
/// When the job was created, in milliseconds since the epoch.
|
||||||
|
pub created_at_millis: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A described job from [`Database::get_job`]: lifecycle state plus the
|
||||||
|
/// job-type-specific specification.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct JobDescription {
|
||||||
|
pub job_id: String,
|
||||||
|
pub job_type: String,
|
||||||
|
/// Lifecycle state: "running", "finished", "failed", or "cancelled".
|
||||||
|
pub state: String,
|
||||||
|
/// When the job was created, in milliseconds since the epoch.
|
||||||
|
pub creation_ms: i64,
|
||||||
|
/// The job-type-specific specification. Null when the server omits it.
|
||||||
|
pub spec: serde_json::Value,
|
||||||
|
/// Why the job failed, when the job is failed and the server reports a
|
||||||
|
/// reason.
|
||||||
|
pub failure: Option<crate::error::JobFailure>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn job_op_not_supported<T>(what: &str) -> Result<T> {
|
||||||
|
Err(crate::error::Error::NotSupported {
|
||||||
|
message: format!("{} is not supported by this database", what),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// The `Database` trait defines the interface for database implementations.
|
/// The `Database` trait defines the interface for database implementations.
|
||||||
///
|
///
|
||||||
/// A database is responsible for managing tables and their metadata.
|
/// A database is responsible for managing tables and their metadata.
|
||||||
@@ -245,6 +286,31 @@ pub trait Database:
|
|||||||
///
|
///
|
||||||
/// See [`CloneTableRequest`] for detailed documentation and examples.
|
/// See [`CloneTableRequest`] for detailed documentation and examples.
|
||||||
async fn clone_table(&self, request: CloneTableRequest) -> Result<Arc<dyn BaseTable>>;
|
async fn clone_table(&self, request: CloneTableRequest) -> Result<Arc<dyn BaseTable>>;
|
||||||
|
/// A [`crate::job::Job`] handle for a server-side job by id, suitable for
|
||||||
|
/// waiting on or cancelling the job. The handle is constructed without a
|
||||||
|
/// server round trip; an unknown id surfaces when the handle is used.
|
||||||
|
fn job(&self, _job_id: &str) -> Result<crate::job::Job> {
|
||||||
|
job_op_not_supported("job")
|
||||||
|
}
|
||||||
|
/// List server-side jobs across the database's tables.
|
||||||
|
async fn list_jobs(&self) -> Result<Vec<JobInfo>> {
|
||||||
|
job_op_not_supported("list_jobs")
|
||||||
|
}
|
||||||
|
/// Describe a single job by id. `None` when the server has no such job.
|
||||||
|
async fn get_job(&self, _job_id: &str) -> Result<Option<JobDescription>> {
|
||||||
|
job_op_not_supported("get_job")
|
||||||
|
}
|
||||||
|
/// Request cancellation of a job by id. Returns true if the server
|
||||||
|
/// accepted the cancellation, false if no such job exists. Cancelling an
|
||||||
|
/// already-terminal job is a no-op success.
|
||||||
|
async fn cancel_job(&self, _job_id: &str) -> Result<bool> {
|
||||||
|
job_op_not_supported("cancel_job")
|
||||||
|
}
|
||||||
|
/// The lifecycle event history of a job (all jobs when `job_id` is
|
||||||
|
/// `None`), as recorded Arrow batches.
|
||||||
|
async fn job_history(&self, _job_id: Option<&str>) -> Result<Vec<RecordBatch>> {
|
||||||
|
job_op_not_supported("job_history")
|
||||||
|
}
|
||||||
/// Open a table in the database
|
/// Open a table in the database
|
||||||
async fn open_table(&self, request: OpenTableRequest) -> Result<Arc<dyn BaseTable>>;
|
async fn open_table(&self, request: OpenTableRequest) -> Result<Arc<dyn BaseTable>>;
|
||||||
/// Rename a table in the database
|
/// Rename a table in the database
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use lance::dataset::refs::Ref;
|
|||||||
use lance::dataset::{ReadParams, WriteMode, builder::DatasetBuilder};
|
use lance::dataset::{ReadParams, WriteMode, builder::DatasetBuilder};
|
||||||
use lance::io::{ObjectStore, ObjectStoreParams, WrappingObjectStore};
|
use lance::io::{ObjectStore, ObjectStoreParams, WrappingObjectStore};
|
||||||
use lance_datafusion::utils::StreamingWriteSource;
|
use lance_datafusion::utils::StreamingWriteSource;
|
||||||
use lance_encoding::version::LanceFileVersion;
|
use lance_file::version::LanceFileVersion;
|
||||||
use lance_io::object_store::{StorageOptionsAccessor, StorageOptionsProvider};
|
use lance_io::object_store::{StorageOptionsAccessor, StorageOptionsProvider};
|
||||||
use lance_table::io::commit::commit_handler_from_url;
|
use lance_table::io::commit::commit_handler_from_url;
|
||||||
use object_store::local::LocalFileSystem;
|
use object_store::local::LocalFileSystem;
|
||||||
@@ -1294,9 +1294,11 @@ mod tests {
|
|||||||
use crate::connection::ConnectRequest;
|
use crate::connection::ConnectRequest;
|
||||||
use crate::data::scannable::Scannable;
|
use crate::data::scannable::Scannable;
|
||||||
use crate::database::{CreateTableMode, CreateTableRequest};
|
use crate::database::{CreateTableMode, CreateTableRequest};
|
||||||
use crate::table::WriteOptions;
|
use crate::query::QueryRequest;
|
||||||
|
use crate::table::{AnyQuery, WriteOptions};
|
||||||
use arrow_array::{Int32Array, RecordBatch, StringArray};
|
use arrow_array::{Int32Array, RecordBatch, StringArray};
|
||||||
use arrow_schema::{DataType, Field, Schema};
|
use arrow_schema::{DataType, Field, Schema};
|
||||||
|
use futures::TryStreamExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
@@ -1376,6 +1378,156 @@ mod tests {
|
|||||||
assert!(!tempdir.path().join("__manifest").exists());
|
assert!(!tempdir.path().join("__manifest").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Regression test for https://github.com/lancedb/lancedb/issues/1600.
|
||||||
|
///
|
||||||
|
/// Opening a table used to create a separate object-store client instead of
|
||||||
|
/// reusing the one that successfully connected to the database. Repeating
|
||||||
|
/// credential discovery made S3 table opens intermittent, especially in AWS
|
||||||
|
/// Lambda, and the failed open was reported as `TableNotFound`.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_open_table_reuses_connection_object_store() {
|
||||||
|
let tempdir = tempdir().unwrap();
|
||||||
|
let uri = tempdir.path().to_str().unwrap();
|
||||||
|
let registry = Arc::new(lance_io::object_store::ObjectStoreRegistry::default());
|
||||||
|
let session = Arc::new(lance::session::Session::new(16, 16, registry.clone()));
|
||||||
|
|
||||||
|
let request = ConnectRequest {
|
||||||
|
uri: uri.to_string(),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
client_config: Default::default(),
|
||||||
|
options: Default::default(),
|
||||||
|
namespace_client_properties: Default::default(),
|
||||||
|
manifest_enabled: false,
|
||||||
|
read_consistency_interval: None,
|
||||||
|
session: Some(session),
|
||||||
|
};
|
||||||
|
let db = ListingDatabase::connect_with_options(&request)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)]));
|
||||||
|
db.create_table(CreateTableRequest {
|
||||||
|
name: "test".to_string(),
|
||||||
|
namespace_path: vec![],
|
||||||
|
data: Box::new(RecordBatch::new_empty(schema)) as Box<dyn Scannable>,
|
||||||
|
mode: CreateTableMode::Create,
|
||||||
|
write_options: Default::default(),
|
||||||
|
location: None,
|
||||||
|
namespace_client: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let before_open = registry.stats();
|
||||||
|
for _ in 0..3 {
|
||||||
|
let table = db
|
||||||
|
.open_table(OpenTableRequest {
|
||||||
|
name: "test".to_string(),
|
||||||
|
namespace_path: vec![],
|
||||||
|
index_cache_size: None,
|
||||||
|
lance_read_params: None,
|
||||||
|
location: None,
|
||||||
|
namespace_client: None,
|
||||||
|
managed_versioning: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(table.count_rows(None).await.unwrap(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let after_open = registry.stats();
|
||||||
|
assert_eq!(after_open.misses, before_open.misses);
|
||||||
|
assert!(after_open.hits >= before_open.hits + 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Regression test for https://github.com/lancedb/lancedb/issues/3197.
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_open_table_follows_hugging_face_symlinks() {
|
||||||
|
let (tempdir, db) = setup_database().await;
|
||||||
|
let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)]));
|
||||||
|
db.create_table(CreateTableRequest {
|
||||||
|
name: "test".to_string(),
|
||||||
|
namespace_path: vec![],
|
||||||
|
data: Box::new(
|
||||||
|
RecordBatch::try_new(schema, vec![Arc::new(Int32Array::from(vec![1, 2, 3]))])
|
||||||
|
.unwrap(),
|
||||||
|
) as Box<dyn Scannable>,
|
||||||
|
mode: CreateTableMode::Create,
|
||||||
|
write_options: Default::default(),
|
||||||
|
location: None,
|
||||||
|
namespace_client: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let table_dir = tempdir.path().join("test.lance");
|
||||||
|
let versions_dir = table_dir.join("_versions");
|
||||||
|
let manifest_path = std::fs::read_dir(&versions_dir)
|
||||||
|
.unwrap()
|
||||||
|
.map(|entry| entry.unwrap().path())
|
||||||
|
.find(|path| path.extension().is_some_and(|ext| ext == "manifest"))
|
||||||
|
.unwrap();
|
||||||
|
let data_path = std::fs::read_dir(table_dir.join("data"))
|
||||||
|
.unwrap()
|
||||||
|
.map(|entry| entry.unwrap().path())
|
||||||
|
.find(|path| path.extension().is_some_and(|ext| ext == "lance"))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Hugging Face snapshots keep dataset objects in a separate blob directory and
|
||||||
|
// expose them through relative symlinks.
|
||||||
|
let blobs_dir = tempdir.path().join("blobs");
|
||||||
|
std::fs::create_dir(&blobs_dir).unwrap();
|
||||||
|
let manifest_blob = "9b603c63d0e692e05d58be25605f2f2064cc781e5ff94fe983a405059547b816";
|
||||||
|
let data_blob = "be64f20e5723bd0a27cfdbdb41cf7d6fad94cd572a71973b717fb8340f4310c5";
|
||||||
|
std::fs::rename(&manifest_path, blobs_dir.join(manifest_blob)).unwrap();
|
||||||
|
std::fs::rename(&data_path, blobs_dir.join(data_blob)).unwrap();
|
||||||
|
std::os::unix::fs::symlink(Path::new("../../blobs").join(manifest_blob), &manifest_path)
|
||||||
|
.unwrap();
|
||||||
|
std::os::unix::fs::symlink(Path::new("../../blobs").join(data_blob), &data_path).unwrap();
|
||||||
|
let symlink_len = std::fs::symlink_metadata(&manifest_path).unwrap().len();
|
||||||
|
let target_len = std::fs::metadata(&manifest_path).unwrap().len();
|
||||||
|
assert_ne!(symlink_len, target_len);
|
||||||
|
|
||||||
|
drop(db);
|
||||||
|
let db = ListingDatabase::connect_with_options(&ConnectRequest {
|
||||||
|
uri: tempdir.path().to_str().unwrap().to_string(),
|
||||||
|
#[cfg(feature = "remote")]
|
||||||
|
client_config: Default::default(),
|
||||||
|
options: Default::default(),
|
||||||
|
namespace_client_properties: Default::default(),
|
||||||
|
manifest_enabled: false,
|
||||||
|
read_consistency_interval: None,
|
||||||
|
session: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let table = db
|
||||||
|
.open_table(OpenTableRequest {
|
||||||
|
name: "test".to_string(),
|
||||||
|
namespace_path: vec![],
|
||||||
|
index_cache_size: None,
|
||||||
|
lance_read_params: None,
|
||||||
|
location: None,
|
||||||
|
namespace_client: None,
|
||||||
|
managed_versioning: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let batches = table
|
||||||
|
.query(
|
||||||
|
&AnyQuery::Query(QueryRequest::default()),
|
||||||
|
Default::default(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(batches.iter().map(RecordBatch::num_rows).sum::<usize>(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_clone_table_basic() {
|
async fn test_clone_table_basic() {
|
||||||
let (_tempdir, db) = setup_database().await;
|
let (_tempdir, db) = setup_database().await;
|
||||||
@@ -2280,7 +2432,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_table_uri() {
|
async fn test_table_uri() {
|
||||||
let (_tempdir, db) = setup_database().await;
|
let (_tempdir, mut db) = setup_database().await;
|
||||||
|
|
||||||
let mut pb = PathBuf::new();
|
let mut pb = PathBuf::new();
|
||||||
pb.push(db.uri.clone());
|
pb.push(db.uri.clone());
|
||||||
@@ -2289,6 +2441,18 @@ mod tests {
|
|||||||
let expected = pb.to_str().unwrap();
|
let expected = pb.to_str().unwrap();
|
||||||
let uri = db.table_uri("test").ok().unwrap();
|
let uri = db.table_uri("test").ok().unwrap();
|
||||||
assert_eq!(uri, expected);
|
assert_eq!(uri, expected);
|
||||||
|
|
||||||
|
// URI paths always use forward slashes, even on Windows. Using
|
||||||
|
// `Path::join` here used to produce `az://container/prefix\\test.lance`,
|
||||||
|
// which Azure treated as a different object from the table returned by
|
||||||
|
// `table_names` (https://github.com/lancedb/lancedb/issues/1072).
|
||||||
|
for base_uri in ["az://container/prefix", "az://container/prefix/"] {
|
||||||
|
db.uri = base_uri.to_string();
|
||||||
|
assert_eq!(
|
||||||
|
db.table_uri("test").unwrap(),
|
||||||
|
"az://container/prefix/test.lance"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Regression: connecting via a URL-style URI (which goes through
|
/// Regression: connecting via a URL-style URI (which goes through
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ impl LanceNamespaceDatabase {
|
|||||||
&self,
|
&self,
|
||||||
request: &DbCreateTableRequest,
|
request: &DbCreateTableRequest,
|
||||||
) -> Result<(
|
) -> Result<(
|
||||||
Option<lance_encoding::version::LanceFileVersion>,
|
Option<lance_file::version::LanceFileVersion>,
|
||||||
Option<bool>,
|
Option<bool>,
|
||||||
Option<bool>,
|
Option<bool>,
|
||||||
)> {
|
)> {
|
||||||
@@ -214,7 +214,7 @@ impl LanceNamespaceDatabase {
|
|||||||
|
|
||||||
let storage_version_override = storage_options
|
let storage_version_override = storage_options
|
||||||
.and_then(|opts| opts.get(OPT_NEW_TABLE_STORAGE_VERSION))
|
.and_then(|opts| opts.get(OPT_NEW_TABLE_STORAGE_VERSION))
|
||||||
.map(|s| s.parse::<lance_encoding::version::LanceFileVersion>())
|
.map(|s| s.parse::<lance_file::version::LanceFileVersion>())
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let v2_manifest_override = storage_options
|
let v2_manifest_override = storage_options
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ use lance_core::{cache::LanceCache, utils::futures::FinallyStreamExt};
|
|||||||
use lance_encoding::decoder::{DecoderPlugins, FilterExpression};
|
use lance_encoding::decoder::{DecoderPlugins, FilterExpression};
|
||||||
use lance_file::{
|
use lance_file::{
|
||||||
reader::{FileReader, FileReaderOptions},
|
reader::{FileReader, FileReaderOptions},
|
||||||
writer::{FileWriter, FileWriterOptions},
|
version::ConcreteFileVersion,
|
||||||
|
versions,
|
||||||
|
writer::FileWriterOptions,
|
||||||
};
|
};
|
||||||
use lance_io::{
|
use lance_io::{
|
||||||
ReadBatchParams,
|
ReadBatchParams,
|
||||||
@@ -152,8 +154,12 @@ impl Shuffler {
|
|||||||
source: None,
|
source: None,
|
||||||
})?;
|
})?;
|
||||||
let object_writer = object_store.create(&path).await?;
|
let object_writer = object_store.create(&path).await?;
|
||||||
let writer =
|
let writer = versions::create_writer(
|
||||||
FileWriter::try_new(object_writer, schema.clone(), FileWriterOptions::default())?;
|
ConcreteFileVersion::V2_1,
|
||||||
|
object_writer,
|
||||||
|
schema.clone(),
|
||||||
|
FileWriterOptions::default(),
|
||||||
|
)?;
|
||||||
file_writers.push(writer);
|
file_writers.push(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ pub fn compute_output_schema(
|
|||||||
let field_name = ed
|
let field_name = ed
|
||||||
.dest_column
|
.dest_column
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| format!("{}_embedding", &ed.source_column));
|
.unwrap_or_else(|| format!("{}_embedding", ed.source_column));
|
||||||
|
|
||||||
sb.push(Field::new(
|
sb.push(Field::new(
|
||||||
field_name,
|
field_name,
|
||||||
@@ -291,7 +291,7 @@ pub fn compute_embeddings_for_batch(
|
|||||||
let dst_field_name = fld
|
let dst_field_name = fld
|
||||||
.dest_column
|
.dest_column
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| format!("{}_embedding", &fld.source_column));
|
.unwrap_or_else(|| format!("{}_embedding", fld.source_column));
|
||||||
|
|
||||||
let dst_field = Field::new(
|
let dst_field = Field::new(
|
||||||
dst_field_name,
|
dst_field_name,
|
||||||
@@ -315,7 +315,7 @@ impl<R: RecordBatchReader> WithEmbeddings<R> {
|
|||||||
let field_name = ed
|
let field_name = ed
|
||||||
.dest_column
|
.dest_column
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| format!("{}_embedding", &ed.source_column));
|
.unwrap_or_else(|| format!("{}_embedding", ed.source_column));
|
||||||
Ok(Field::new(
|
Ok(Field::new(
|
||||||
field_name,
|
field_name,
|
||||||
func.dest_type()?.into_owned(),
|
func.dest_type()?.into_owned(),
|
||||||
|
|||||||
+126
-1
@@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
use std::sync::PoisonError;
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
use std::sync::{Arc, PoisonError};
|
||||||
|
|
||||||
use arrow_schema::ArrowError;
|
use arrow_schema::ArrowError;
|
||||||
use datafusion_common::DataFusionError;
|
use datafusion_common::DataFusionError;
|
||||||
@@ -9,6 +10,46 @@ use snafu::Snafu;
|
|||||||
|
|
||||||
pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
|
/// Why a job failed, to whatever precision the backend provides.
|
||||||
|
///
|
||||||
|
/// A job run in this process carries the error it failed with in [`Self::source`].
|
||||||
|
/// A job run remotely carries whatever the server reported, which older servers
|
||||||
|
/// do not report at all. Every field is absent rather than invented when the
|
||||||
|
/// backend does not supply it.
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct JobFailure {
|
||||||
|
/// The stage the job was in, when known.
|
||||||
|
pub phase: Option<String>,
|
||||||
|
/// A human-readable reason, when known.
|
||||||
|
pub message: Option<String>,
|
||||||
|
/// Whether a retry could clear the failure, when known.
|
||||||
|
pub retryable: Option<bool>,
|
||||||
|
/// The error the job failed with, when it ran in this process.
|
||||||
|
pub source: Option<Arc<Error>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JobFailure {
|
||||||
|
/// A failure whose only known detail is the error that caused it.
|
||||||
|
pub(crate) fn from_source(source: Arc<Error>) -> Self {
|
||||||
|
Self {
|
||||||
|
message: Some(source.to_string()),
|
||||||
|
source: Some(source),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for JobFailure {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
match (&self.message, &self.phase) {
|
||||||
|
(Some(message), Some(phase)) => write!(f, ": {message} (in {phase})"),
|
||||||
|
(Some(message), None) => write!(f, ": {message}"),
|
||||||
|
(None, Some(phase)) => write!(f, " in {phase}"),
|
||||||
|
(None, None) => Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
#[snafu(visibility(pub(crate)))]
|
#[snafu(visibility(pub(crate)))]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@@ -18,6 +59,10 @@ pub enum Error {
|
|||||||
InvalidInput { message: String },
|
InvalidInput { message: String },
|
||||||
#[snafu(display("Table '{name}' was not found"))]
|
#[snafu(display("Table '{name}' was not found"))]
|
||||||
TableNotFound { name: String, source: BoxError },
|
TableNotFound { name: String, source: BoxError },
|
||||||
|
#[snafu(display(
|
||||||
|
"Table '{name}' exists but could not be loaded (it may be corrupt or incomplete): {source}"
|
||||||
|
))]
|
||||||
|
TableCorrupted { name: String, source: BoxError },
|
||||||
#[snafu(display("Database '{name}' was not found"))]
|
#[snafu(display("Database '{name}' was not found"))]
|
||||||
DatabaseNotFound { name: String },
|
DatabaseNotFound { name: String },
|
||||||
#[snafu(display("Database '{name}' already exists."))]
|
#[snafu(display("Database '{name}' already exists."))]
|
||||||
@@ -40,6 +85,13 @@ pub enum Error {
|
|||||||
Runtime { message: String },
|
Runtime { message: String },
|
||||||
#[snafu(display("Timeout error: {message}"))]
|
#[snafu(display("Timeout error: {message}"))]
|
||||||
Timeout { message: String },
|
Timeout { message: String },
|
||||||
|
#[snafu(display("Job{} failed{failure}", job_id.as_ref().map(|id| format!(" {id}")).unwrap_or_default()))]
|
||||||
|
JobFailed {
|
||||||
|
job_id: Option<String>,
|
||||||
|
failure: JobFailure,
|
||||||
|
},
|
||||||
|
#[snafu(display("Job{} was cancelled", job_id.as_ref().map(|id| format!(" {id}")).unwrap_or_default()))]
|
||||||
|
JobCancelled { job_id: Option<String> },
|
||||||
|
|
||||||
// 3rd party / external errors
|
// 3rd party / external errors
|
||||||
#[snafu(display("object_store error: {source}"))]
|
#[snafu(display("object_store error: {source}"))]
|
||||||
@@ -117,15 +169,45 @@ impl From<DataFusionError> for Error {
|
|||||||
|
|
||||||
impl From<lance::Error> for Error {
|
impl From<lance::Error> for Error {
|
||||||
fn from(source: lance::Error) -> Self {
|
fn from(source: lance::Error) -> Self {
|
||||||
|
if has_unsupported_local_filesystem_source(&source) {
|
||||||
|
return Self::NotSupported {
|
||||||
|
message: "the filesystem does not support an operation required for safe Lance commits (such as atomic rename). Object-storage mounts such as Mountpoint for Amazon S3 are not supported; use the native object-store URI (for example, s3://bucket/path) instead".to_string(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Try to unwrap external errors that were wrapped by lance
|
// Try to unwrap external errors that were wrapped by lance
|
||||||
match source {
|
match source {
|
||||||
lance::Error::Wrapped { error, .. } => Self::from_box_error(error),
|
lance::Error::Wrapped { error, .. } => Self::from_box_error(error),
|
||||||
lance::Error::External { source } => Self::from_box_error(source),
|
lance::Error::External { source } => Self::from_box_error(source),
|
||||||
|
lance::Error::InvalidInput { source, .. } => Self::InvalidInput {
|
||||||
|
message: source.to_string(),
|
||||||
|
},
|
||||||
_ => Self::Lance { source },
|
_ => Self::Lance { source },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_unsupported_local_filesystem_source(error: &(dyn std::error::Error + 'static)) -> bool {
|
||||||
|
let mut current = Some(error);
|
||||||
|
let mut is_local_filesystem = false;
|
||||||
|
let mut is_unsupported = false;
|
||||||
|
while let Some(error) = current {
|
||||||
|
is_local_filesystem |= error
|
||||||
|
.downcast_ref::<object_store::Error>()
|
||||||
|
.is_some_and(|error| {
|
||||||
|
matches!(error, object_store::Error::Generic { store, .. } if *store == "LocalFileSystem")
|
||||||
|
});
|
||||||
|
is_unsupported |= error
|
||||||
|
.downcast_ref::<std::io::Error>()
|
||||||
|
.is_some_and(|error| error.kind() == std::io::ErrorKind::Unsupported);
|
||||||
|
if is_local_filesystem && is_unsupported {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
current = error.source();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
fn from_box_error(mut source: Box<dyn std::error::Error + Send + Sync>) -> Self {
|
fn from_box_error(mut source: Box<dyn std::error::Error + Send + Sync>) -> Self {
|
||||||
source = match source.downcast::<Self>() {
|
source = match source.downcast::<Self>() {
|
||||||
@@ -215,3 +297,46 @@ impl From<candle_core::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsupported_filesystem_operations_have_actionable_error() {
|
||||||
|
let object_store_error = object_store::Error::Generic {
|
||||||
|
store: "LocalFileSystem",
|
||||||
|
source: Box::new(std::io::Error::from(std::io::ErrorKind::Unsupported)),
|
||||||
|
};
|
||||||
|
let lance_error = lance::Error::io_source(Box::new(object_store_error));
|
||||||
|
|
||||||
|
let error = Error::from(lance_error);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
error,
|
||||||
|
Error::NotSupported { message }
|
||||||
|
if message.contains("Mountpoint for Amazon S3")
|
||||||
|
&& message.contains("s3://bucket/path")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn other_io_errors_remain_lance_errors() {
|
||||||
|
let object_store_error = object_store::Error::Generic {
|
||||||
|
store: "LocalFileSystem",
|
||||||
|
source: Box::new(std::io::Error::from(std::io::ErrorKind::PermissionDenied)),
|
||||||
|
};
|
||||||
|
let lance_error = lance::Error::io_source(Box::new(object_store_error));
|
||||||
|
|
||||||
|
assert!(matches!(Error::from(lance_error), Error::Lance { .. }));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsupported_non_filesystem_errors_remain_lance_errors() {
|
||||||
|
let lance_error = lance::Error::io_source(Box::new(std::io::Error::from(
|
||||||
|
std::io::ErrorKind::Unsupported,
|
||||||
|
)));
|
||||||
|
|
||||||
|
assert!(matches!(Error::from(lance_error), Error::Lance { .. }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use std::time::Duration;
|
|||||||
use vector::IvfFlatIndexBuilder;
|
use vector::IvfFlatIndexBuilder;
|
||||||
|
|
||||||
use crate::index::vector::IvfRqIndexBuilder;
|
use crate::index::vector::IvfRqIndexBuilder;
|
||||||
use crate::{DistanceType, Error, Result, table::BaseTable};
|
use crate::{DistanceType, Error, Result, job::Job, table::BaseTable};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
scalar::{BTreeIndexBuilder, BitmapIndexBuilder, FmIndexBuilder, LabelListIndexBuilder},
|
scalar::{BTreeIndexBuilder, BitmapIndexBuilder, FmIndexBuilder, LabelListIndexBuilder},
|
||||||
@@ -305,6 +305,14 @@ impl IndexBuilder {
|
|||||||
pub async fn execute(self) -> Result<()> {
|
pub async fn execute(self) -> Result<()> {
|
||||||
self.parent.clone().create_index(self).await
|
self.parent.clone().create_index(self).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates the index, returning a [`Job`] tracking the operation.
|
||||||
|
///
|
||||||
|
/// The job may already be complete when returned, and callers must not
|
||||||
|
/// assume the index exists until [`Job::wait`] resolves.
|
||||||
|
pub async fn execute_async(self) -> Result<Job> {
|
||||||
|
self.parent.clone().create_index_async(self).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
|
|||||||
@@ -132,9 +132,14 @@ impl ObjectStore for MirroringObjectStore {
|
|||||||
if to.primary_only() {
|
if to.primary_only() {
|
||||||
self.primary.copy_opts(from, to, options).await
|
self.primary.copy_opts(from, to, options).await
|
||||||
} else {
|
} else {
|
||||||
self.secondary.copy_opts(from, to, options.clone()).await?;
|
// The secondary store can be process-local and less durable than the
|
||||||
self.primary.copy_opts(from, to, options).await?;
|
// primary, so a source written by another process may not exist here
|
||||||
Ok(())
|
// or may be evicted before the copy begins.
|
||||||
|
match self.secondary.copy_opts(from, to, options.clone()).await {
|
||||||
|
Ok(()) | Err(Error::NotFound { .. }) => {}
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
}
|
||||||
|
self.primary.copy_opts(from, to, options).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +197,8 @@ mod test {
|
|||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use lance::{dataset::WriteParams, io::ObjectStoreParams};
|
use lance::{dataset::WriteParams, io::ObjectStoreParams};
|
||||||
use lance_testing::datagen::{BatchGenerator, IncrementingInt32, RandomVector};
|
use lance_testing::datagen::{BatchGenerator, IncrementingInt32, RandomVector};
|
||||||
use object_store::local::LocalFileSystem;
|
use object_store::{local::LocalFileSystem, memory::InMemory};
|
||||||
|
use std::time::Duration;
|
||||||
use tempfile;
|
use tempfile;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -201,6 +207,139 @@ mod test {
|
|||||||
table::WriteOptions,
|
table::WriteOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct EvictBeforeCopyStore {
|
||||||
|
inner: Arc<dyn ObjectStore>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for EvictBeforeCopyStore {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "EvictBeforeCopyStore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ObjectStore for EvictBeforeCopyStore {
|
||||||
|
async fn put_opts(
|
||||||
|
&self,
|
||||||
|
location: &Path,
|
||||||
|
payload: PutPayload,
|
||||||
|
options: PutOptions,
|
||||||
|
) -> Result<PutResult> {
|
||||||
|
self.inner.put_opts(location, payload, options).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn put_multipart_opts(
|
||||||
|
&self,
|
||||||
|
location: &Path,
|
||||||
|
options: PutMultipartOptions,
|
||||||
|
) -> Result<Box<dyn MultipartUpload>> {
|
||||||
|
self.inner.put_multipart_opts(location, options).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_opts(&self, location: &Path, options: GetOptions) -> Result<GetResult> {
|
||||||
|
self.inner.get_opts(location, options).await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_stream(
|
||||||
|
&self,
|
||||||
|
locations: BoxStream<'static, Result<Path>>,
|
||||||
|
) -> BoxStream<'static, Result<Path>> {
|
||||||
|
self.inner.delete_stream(locations)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, prefix: Option<&Path>) -> BoxStream<'static, Result<ObjectMeta>> {
|
||||||
|
self.inner.list(prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_with_delimiter(&self, prefix: Option<&Path>) -> Result<ListResult> {
|
||||||
|
self.inner.list_with_delimiter(prefix).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn copy_opts(&self, from: &Path, to: &Path, options: CopyOptions) -> Result<()> {
|
||||||
|
self.inner.delete(from).await?;
|
||||||
|
self.inner.copy_opts(from, to, options).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_copy_when_source_is_missing_from_secondary() {
|
||||||
|
let primary_dir = tempfile::tempdir().unwrap();
|
||||||
|
let secondary_dir = tempfile::tempdir().unwrap();
|
||||||
|
let primary: Arc<dyn ObjectStore> =
|
||||||
|
Arc::new(LocalFileSystem::new_with_prefix(primary_dir.path()).unwrap());
|
||||||
|
let secondary: Arc<dyn ObjectStore> =
|
||||||
|
Arc::new(LocalFileSystem::new_with_prefix(secondary_dir.path()).unwrap());
|
||||||
|
let store = MirroringObjectStore {
|
||||||
|
primary: primary.clone(),
|
||||||
|
secondary: secondary.clone(),
|
||||||
|
};
|
||||||
|
let staging = Path::from("_versions/1.manifest-staging");
|
||||||
|
let finalized = Path::from("_versions/1.manifest");
|
||||||
|
|
||||||
|
primary
|
||||||
|
.put(&staging, "manifest contents".into())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
tokio::time::timeout(Duration::from_secs(5), store.copy(&staging, &finalized))
|
||||||
|
.await
|
||||||
|
.expect("copy should not hang when the secondary source is missing")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let copied = primary
|
||||||
|
.get(&finalized)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.bytes()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(copied, "manifest contents");
|
||||||
|
assert!(matches!(
|
||||||
|
secondary.head(&finalized).await,
|
||||||
|
Err(Error::NotFound { .. })
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_copy_when_secondary_source_disappears_after_head() {
|
||||||
|
let primary: Arc<dyn ObjectStore> = Arc::new(InMemory::new());
|
||||||
|
let secondary_inner: Arc<dyn ObjectStore> = Arc::new(InMemory::new());
|
||||||
|
let secondary: Arc<dyn ObjectStore> = Arc::new(EvictBeforeCopyStore {
|
||||||
|
inner: secondary_inner.clone(),
|
||||||
|
});
|
||||||
|
let store = MirroringObjectStore {
|
||||||
|
primary: primary.clone(),
|
||||||
|
secondary,
|
||||||
|
};
|
||||||
|
let staging = Path::from("_versions/1.manifest-staging");
|
||||||
|
let finalized = Path::from("_versions/1.manifest");
|
||||||
|
|
||||||
|
primary
|
||||||
|
.put(&staging, "manifest contents".into())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
secondary_inner
|
||||||
|
.put(&staging, "manifest contents".into())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
store.copy(&staging, &finalized).await.unwrap();
|
||||||
|
|
||||||
|
let copied = primary
|
||||||
|
.get(&finalized)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.bytes()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(copied, "manifest contents");
|
||||||
|
assert!(matches!(
|
||||||
|
secondary_inner.head(&finalized).await,
|
||||||
|
Err(Error::NotFound { .. })
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// This test is ignored because lance 3.0 introduced LocalWriter optimization
|
// This test is ignored because lance 3.0 introduced LocalWriter optimization
|
||||||
// that bypasses the object store wrapper for local writes. The mirroring feature
|
// that bypasses the object store wrapper for local writes. The mirroring feature
|
||||||
// still works for remote/cloud storage, but can't be tested with local storage.
|
// still works for remote/cloud storage, but can't be tested with local storage.
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
//! Handles to operations a server may run asynchronously.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use tokio::sync::watch;
|
||||||
|
use tokio::task::{AbortHandle, JoinHandle};
|
||||||
|
|
||||||
|
use crate::error::{Error, JobFailure, Result};
|
||||||
|
|
||||||
|
/// Backend-specific tracking for an asynchronous operation.
|
||||||
|
#[async_trait]
|
||||||
|
pub(crate) trait JobHandle: Send + Sync {
|
||||||
|
/// Server-assigned id, when the backend has one.
|
||||||
|
fn id(&self) -> Option<&str> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
async fn status(&self) -> Result<String>;
|
||||||
|
async fn wait(&self) -> Result<()>;
|
||||||
|
async fn cancel(&self) -> Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A handle to an operation that may still be running.
|
||||||
|
///
|
||||||
|
/// The operation may already be complete when the handle is created.
|
||||||
|
pub struct Job {
|
||||||
|
handle: Option<Box<dyn JobHandle>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for Job {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("Job")
|
||||||
|
.field("id", &self.id())
|
||||||
|
.field("done", &self.handle.is_none())
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Job {
|
||||||
|
/// A job whose operation finished before the handle was created.
|
||||||
|
pub(crate) fn new_done() -> Self {
|
||||||
|
Self { handle: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn new(handle: Box<dyn JobHandle>) -> Self {
|
||||||
|
Self {
|
||||||
|
handle: Some(handle),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A job running as a task in this process.
|
||||||
|
pub(crate) fn spawned(task: JoinHandle<Result<()>>) -> Self {
|
||||||
|
Self::new(Box::new(SpawnedJob::new(task)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Identifies the operation on the server that is running it.
|
||||||
|
///
|
||||||
|
/// Returned for correlating with server logs or the jobs API. Operations
|
||||||
|
/// that run in this process have no server id and return `None`. The
|
||||||
|
/// value is opaque: parsing it or storing it to resume the job later is
|
||||||
|
/// not supported.
|
||||||
|
pub fn id(&self) -> Option<&str> {
|
||||||
|
self.handle.as_ref().and_then(|handle| handle.id())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The operation's current lifecycle state: "running", "finished",
|
||||||
|
/// "failed", or "cancelled".
|
||||||
|
///
|
||||||
|
/// A point snapshot; unlike [`Job::wait`] it does not block, raise on a
|
||||||
|
/// terminal failure state, or retry. States a newer server reports that
|
||||||
|
/// this client version does not know pass through as-is.
|
||||||
|
pub async fn status(&self) -> Result<String> {
|
||||||
|
match &self.handle {
|
||||||
|
None => Ok("finished".to_string()),
|
||||||
|
Some(handle) => handle.status().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Waits until the operation reaches a terminal state.
|
||||||
|
///
|
||||||
|
/// Returns [`crate::Error::JobFailed`] if the operation failed and
|
||||||
|
/// [`crate::Error::JobCancelled`] if it was cancelled.
|
||||||
|
pub async fn wait(&self) -> Result<()> {
|
||||||
|
match &self.handle {
|
||||||
|
None => Ok(()),
|
||||||
|
Some(handle) => handle.wait().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Requests cancellation of the operation.
|
||||||
|
///
|
||||||
|
/// Cancelling an operation that already finished is a no-op.
|
||||||
|
pub async fn cancel(&self) -> Result<()> {
|
||||||
|
match &self.handle {
|
||||||
|
None => Ok(()),
|
||||||
|
Some(handle) => handle.cancel().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How an in-process operation ended. Cloneable so every waiter can be given
|
||||||
|
/// the outcome; [`Error`] is not, so failures share one behind an [`Arc`].
|
||||||
|
#[derive(Clone)]
|
||||||
|
enum Outcome {
|
||||||
|
Succeeded,
|
||||||
|
Failed(Arc<Error>),
|
||||||
|
Cancelled,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Outcome {
|
||||||
|
fn into_result(self) -> Result<()> {
|
||||||
|
match self {
|
||||||
|
Self::Succeeded => Ok(()),
|
||||||
|
Self::Failed(source) => Err(Error::JobFailed {
|
||||||
|
job_id: None,
|
||||||
|
failure: JobFailure::from_source(source),
|
||||||
|
}),
|
||||||
|
Self::Cancelled => Err(Error::JobCancelled { job_id: None }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tracks an operation running as a task in this process. A second task
|
||||||
|
/// watches the first so that aborting it still produces an outcome, and so
|
||||||
|
/// that every caller of `wait` observes the same one.
|
||||||
|
struct SpawnedJob {
|
||||||
|
outcome: watch::Receiver<Option<Outcome>>,
|
||||||
|
abort: AbortHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpawnedJob {
|
||||||
|
fn new(task: JoinHandle<Result<()>>) -> Self {
|
||||||
|
let abort = task.abort_handle();
|
||||||
|
let (tx, outcome) = watch::channel(None);
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let outcome = match task.await {
|
||||||
|
Ok(Ok(())) => Outcome::Succeeded,
|
||||||
|
Ok(Err(err)) => Outcome::Failed(Arc::new(err)),
|
||||||
|
Err(err) if err.is_cancelled() => Outcome::Cancelled,
|
||||||
|
Err(err) => Outcome::Failed(Arc::new(Error::Runtime {
|
||||||
|
message: format!("index job task failed: {err}"),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
let _ = tx.send(Some(outcome));
|
||||||
|
});
|
||||||
|
Self { outcome, abort }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl JobHandle for SpawnedJob {
|
||||||
|
async fn status(&self) -> Result<String> {
|
||||||
|
let label = match &*self.outcome.borrow() {
|
||||||
|
None => "running",
|
||||||
|
Some(Outcome::Succeeded) => "finished",
|
||||||
|
Some(Outcome::Failed(_)) => "failed",
|
||||||
|
Some(Outcome::Cancelled) => "cancelled",
|
||||||
|
};
|
||||||
|
Ok(label.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn wait(&self) -> Result<()> {
|
||||||
|
let mut outcome = self.outcome.clone();
|
||||||
|
let settled = outcome
|
||||||
|
.wait_for(|outcome| outcome.is_some())
|
||||||
|
.await
|
||||||
|
.map_err(|_| Error::Runtime {
|
||||||
|
message: "index job outcome was dropped before it completed".to_string(),
|
||||||
|
})?
|
||||||
|
.clone()
|
||||||
|
.expect("wait_for returns once an outcome is set");
|
||||||
|
settled.into_result()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn cancel(&self) -> Result<()> {
|
||||||
|
self.abort.abort();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -184,6 +184,7 @@ pub mod expr;
|
|||||||
pub mod index;
|
pub mod index;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod ipc;
|
pub mod ipc;
|
||||||
|
pub mod job;
|
||||||
#[cfg(feature = "metrics-otel")]
|
#[cfg(feature = "metrics-otel")]
|
||||||
pub mod metrics_otel;
|
pub mod metrics_otel;
|
||||||
#[cfg(feature = "polars")]
|
#[cfg(feature = "polars")]
|
||||||
@@ -203,7 +204,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
pub use blob::{BlobRangeRequest, blob, is_blob};
|
pub use blob::{BlobRangeRequest, blob, is_blob};
|
||||||
pub use connection::{ConnectNamespaceBuilder, Connection};
|
pub use connection::{ConnectNamespaceBuilder, Connection};
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, JobFailure, Result};
|
||||||
|
pub use job::Job;
|
||||||
use lance_index::vector::ApproxMode as LanceApproxMode;
|
use lance_index::vector::ApproxMode as LanceApproxMode;
|
||||||
use lance_linalg::distance::DistanceType as LanceDistanceType;
|
use lance_linalg::distance::DistanceType as LanceDistanceType;
|
||||||
/// Re-export of the [`metrics`](https://docs.rs/metrics) crate facade. Enable
|
/// Re-export of the [`metrics`](https://docs.rs/metrics) crate facade. Enable
|
||||||
|
|||||||
@@ -1661,14 +1661,8 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_setters_getters() {
|
async fn test_setters_getters() {
|
||||||
// TODO: Switch back to memory://foo after https://github.com/lancedb/lancedb/issues/1051
|
|
||||||
// is fixed
|
|
||||||
let tmp_dir = tempdir().unwrap();
|
|
||||||
let dataset_path = tmp_dir.path().join("test.lance");
|
|
||||||
let uri = dataset_path.to_str().unwrap();
|
|
||||||
|
|
||||||
let batches = make_test_batches();
|
let batches = make_test_batches();
|
||||||
let conn = connect(uri).execute().await.unwrap();
|
let conn = connect("memory://foo").execute().await.unwrap();
|
||||||
let table = conn
|
let table = conn
|
||||||
.create_table("my_table", batches)
|
.create_table("my_table", batches)
|
||||||
.execute()
|
.execute()
|
||||||
@@ -1763,14 +1757,8 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_execute() {
|
async fn test_execute() {
|
||||||
// TODO: Switch back to memory://foo after https://github.com/lancedb/lancedb/issues/1051
|
|
||||||
// is fixed
|
|
||||||
let tmp_dir = tempdir().unwrap();
|
|
||||||
let dataset_path = tmp_dir.path().join("test.lance");
|
|
||||||
let uri = dataset_path.to_str().unwrap();
|
|
||||||
|
|
||||||
let batches = make_non_empty_batches();
|
let batches = make_non_empty_batches();
|
||||||
let conn = connect(uri).execute().await.unwrap();
|
let conn = connect("memory://foo").execute().await.unwrap();
|
||||||
let table = conn
|
let table = conn
|
||||||
.create_table("my_table", batches)
|
.create_table("my_table", batches)
|
||||||
.execute()
|
.execute()
|
||||||
@@ -1889,14 +1877,8 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_select_with_transform() {
|
async fn test_select_with_transform() {
|
||||||
// TODO: Switch back to memory://foo after https://github.com/lancedb/lancedb/issues/1051
|
|
||||||
// is fixed
|
|
||||||
let tmp_dir = tempdir().unwrap();
|
|
||||||
let dataset_path = tmp_dir.path().join("test.lance");
|
|
||||||
let uri = dataset_path.to_str().unwrap();
|
|
||||||
|
|
||||||
let batches = make_non_empty_batches();
|
let batches = make_non_empty_batches();
|
||||||
let conn = connect(uri).execute().await.unwrap();
|
let conn = connect("memory://foo").execute().await.unwrap();
|
||||||
let table = conn
|
let table = conn
|
||||||
.create_table("my_table", batches)
|
.create_table("my_table", batches)
|
||||||
.execute()
|
.execute()
|
||||||
@@ -1993,15 +1975,9 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_execute_no_vector() {
|
async fn test_execute_no_vector() {
|
||||||
// TODO: Switch back to memory://foo after https://github.com/lancedb/lancedb/issues/1051
|
|
||||||
// is fixed
|
|
||||||
let tmp_dir = tempdir().unwrap();
|
|
||||||
let dataset_path = tmp_dir.path().join("test.lance");
|
|
||||||
let uri = dataset_path.to_str().unwrap();
|
|
||||||
|
|
||||||
// test that it's ok to not specify a query vector (just filter / limit)
|
// test that it's ok to not specify a query vector (just filter / limit)
|
||||||
let batches = make_non_empty_batches();
|
let batches = make_non_empty_batches();
|
||||||
let conn = connect(uri).execute().await.unwrap();
|
let conn = connect("memory://foo").execute().await.unwrap();
|
||||||
let table = conn
|
let table = conn
|
||||||
.create_table("my_table", batches)
|
.create_table("my_table", batches)
|
||||||
.execute()
|
.execute()
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
pub(crate) mod client;
|
pub(crate) mod client;
|
||||||
pub(crate) mod db;
|
pub(crate) mod db;
|
||||||
|
pub(crate) mod job;
|
||||||
pub mod oauth;
|
pub mod oauth;
|
||||||
mod retry;
|
mod retry;
|
||||||
pub(crate) mod table;
|
pub(crate) mod table;
|
||||||
pub(crate) mod util;
|
pub(crate) mod util;
|
||||||
|
|
||||||
const ARROW_STREAM_CONTENT_TYPE: &str = "application/vnd.apache.arrow.stream";
|
const ARROW_STREAM_CONTENT_TYPE: &str = "application/vnd.apache.arrow.stream";
|
||||||
#[cfg(test)]
|
|
||||||
const ARROW_FILE_CONTENT_TYPE: &str = "application/vnd.apache.arrow.file";
|
const ARROW_FILE_CONTENT_TYPE: &str = "application/vnd.apache.arrow.file";
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
const JSON_CONTENT_TYPE: &str = "application/json";
|
const JSON_CONTENT_TYPE: &str = "application/json";
|
||||||
|
|||||||
@@ -373,6 +373,37 @@ pub fn parse_db_url(db_url: &str) -> Result<ParsedDbUrl> {
|
|||||||
Ok(ParsedDbUrl { db_name, db_prefix })
|
Ok(ParsedDbUrl { db_name, db_prefix })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_dns_hostname(hostname: &str) -> Result<()> {
|
||||||
|
let ascii_hostname = match url::Host::parse(hostname) {
|
||||||
|
Ok(url::Host::Domain(hostname)) => hostname,
|
||||||
|
Ok(_) => {
|
||||||
|
return Err(Error::InvalidInput {
|
||||||
|
message: "LanceDB Cloud database URI or region produced a non-DNS hostname"
|
||||||
|
.to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(Error::InvalidInput {
|
||||||
|
message: format!(
|
||||||
|
"LanceDB Cloud database URI or region produced an invalid hostname: {err}"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if ascii_hostname.len() > 253
|
||||||
|
|| ascii_hostname
|
||||||
|
.split('.')
|
||||||
|
.any(|label| label.is_empty() || label.len() > 63)
|
||||||
|
{
|
||||||
|
return Err(Error::InvalidInput {
|
||||||
|
message: "LanceDB Cloud database URI or region produced an invalid hostname: DNS labels must contain 1 to 63 bytes and the full hostname must not exceed 253 bytes".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
impl RestfulLanceDbClient<Sender> {
|
impl RestfulLanceDbClient<Sender> {
|
||||||
fn get_timeout(passed: Option<Duration>, env_var: &str) -> Result<Option<Duration>> {
|
fn get_timeout(passed: Option<Duration>, env_var: &str) -> Result<Option<Duration>> {
|
||||||
if let Some(passed) = passed {
|
if let Some(passed) = passed {
|
||||||
@@ -480,7 +511,11 @@ impl RestfulLanceDbClient<Sender> {
|
|||||||
|
|
||||||
let host = match host_override {
|
let host = match host_override {
|
||||||
Some(host_override) => host_override,
|
Some(host_override) => host_override,
|
||||||
None => format!("https://{}.{}.api.lancedb.com", parsed_url.db_name, region),
|
None => {
|
||||||
|
let hostname = format!("{}.{}.api.lancedb.com", parsed_url.db_name, region);
|
||||||
|
validate_dns_hostname(&hostname)?;
|
||||||
|
format!("https://{hostname}")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
debug!("Created client for host: {}", host);
|
debug!("Created client for host: {}", host);
|
||||||
let retry_config = client_config.retry_config.clone().try_into()?;
|
let retry_config = client_config.retry_config.clone().try_into()?;
|
||||||
@@ -706,7 +741,7 @@ impl<S: HttpSend> RestfulLanceDbClient<S> {
|
|||||||
.err_to_http(request_id.clone())?;
|
.err_to_http(request_id.clone())?;
|
||||||
debug!(
|
debug!(
|
||||||
"Received response for request_id={}: {:?}",
|
"Received response for request_id={}: {:?}",
|
||||||
request_id, &response
|
request_id, response
|
||||||
);
|
);
|
||||||
Ok((request_id, response))
|
Ok((request_id, response))
|
||||||
}
|
}
|
||||||
@@ -768,7 +803,7 @@ impl<S: HttpSend> RestfulLanceDbClient<S> {
|
|||||||
Ok((status, response)) if status.is_success() => {
|
Ok((status, response)) if status.is_success() => {
|
||||||
debug!(
|
debug!(
|
||||||
"Received response for request_id={}: {:?}",
|
"Received response for request_id={}: {:?}",
|
||||||
retry_counter.request_id, &response
|
retry_counter.request_id, response
|
||||||
);
|
);
|
||||||
return Ok((retry_counter.request_id, response));
|
return Ok((retry_counter.request_id, response));
|
||||||
}
|
}
|
||||||
@@ -1157,6 +1192,29 @@ mod tests {
|
|||||||
assert_eq!(headers.get("x-api-key").unwrap(), "api-key");
|
assert_eq!(headers.get("x-api-key").unwrap(), "api-key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rejects_invalid_cloud_dns_hostname() {
|
||||||
|
let invalid_database_names = ["a".repeat(64), "invalid..database".to_string()];
|
||||||
|
|
||||||
|
for db_name in invalid_database_names {
|
||||||
|
let parsed_url = parse_db_url(&format!("db://{db_name}")).unwrap();
|
||||||
|
let error = RestfulLanceDbClient::<Sender>::try_new(
|
||||||
|
&parsed_url,
|
||||||
|
"us-east-1",
|
||||||
|
None,
|
||||||
|
HeaderMap::new(),
|
||||||
|
ClientConfig::default(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap_err();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
matches!(error, Error::InvalidInput { ref message } if message.contains("DNS labels must contain 1 to 63 bytes")),
|
||||||
|
"unexpected error: {error}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test implementation of HeaderProvider
|
// Test implementation of HeaderProvider
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct TestHeaderProvider {
|
struct TestHeaderProvider {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use lance_namespace::models::{
|
|||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
CloneTableRequest, CreateTableMode, CreateTableRequest, Database, DatabaseOptions,
|
CloneTableRequest, CreateTableMode, CreateTableRequest, Database, DatabaseOptions,
|
||||||
OpenTableRequest, ReadConsistency, TableNamesRequest,
|
JobDescription, JobInfo, OpenTableRequest, ReadConsistency, TableNamesRequest,
|
||||||
};
|
};
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::remote::util::stream_as_body;
|
use crate::remote::util::stream_as_body;
|
||||||
@@ -79,6 +79,10 @@ impl ServerVersion {
|
|||||||
pub fn support_multipart_write(&self) -> bool {
|
pub fn support_multipart_write(&self) -> bool {
|
||||||
self.0 >= semver::Version::new(0, 4, 0)
|
self.0 >= semver::Version::new(0, 4, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn support_blobs(&self) -> bool {
|
||||||
|
self.0 >= semver::Version::new(0, 5, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const OPT_REMOTE_PREFIX: &str = "remote_database_";
|
pub const OPT_REMOTE_PREFIX: &str = "remote_database_";
|
||||||
@@ -428,6 +432,73 @@ fn build_cache_key(name: &str, namespace: &[String]) -> String {
|
|||||||
key.iter().map(|b| format!("{:02x}", b)).collect()
|
key.iter().map(|b| format!("{:02x}", b)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct RemoteListJobRow {
|
||||||
|
job_id: String,
|
||||||
|
#[serde(default)]
|
||||||
|
table: String,
|
||||||
|
#[serde(default)]
|
||||||
|
job_type: String,
|
||||||
|
#[serde(default)]
|
||||||
|
state: String,
|
||||||
|
#[serde(default)]
|
||||||
|
created_at_millis: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct RemoteListJobsResponse {
|
||||||
|
#[serde(default)]
|
||||||
|
jobs: Vec<RemoteListJobRow>,
|
||||||
|
#[serde(default)]
|
||||||
|
page_token: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The server's account of why a job failed. Absent from older servers,
|
||||||
|
/// which report only the terminal state.
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct RemoteReportedFailure {
|
||||||
|
#[serde(default)]
|
||||||
|
phase: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
message: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
retryable: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct RemoteDescribeJobResponse {
|
||||||
|
job_id: String,
|
||||||
|
#[serde(default)]
|
||||||
|
job_type: String,
|
||||||
|
job_state: String,
|
||||||
|
#[serde(default)]
|
||||||
|
creation_ms: i64,
|
||||||
|
#[serde(default)]
|
||||||
|
spec: serde_json::Value,
|
||||||
|
#[serde(default)]
|
||||||
|
failure: Option<RemoteReportedFailure>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Server job states -> the client vocabulary ("running" / "finished" /
|
||||||
|
/// "failed" / "cancelled"). Covers both the describe enum (IN_PROGRESS /
|
||||||
|
/// DONE / FAILED / CANCELLED) and the registry's lowercase list-row states
|
||||||
|
/// (in_progress / succeeded / failed / canceled / timed_out). States this
|
||||||
|
/// client version does not know (e.g. created, queued) pass through as-is.
|
||||||
|
fn job_state_to_client(state: &str) -> String {
|
||||||
|
match state {
|
||||||
|
"IN_PROGRESS" | "in_progress" => "running",
|
||||||
|
"DONE" | "done" | "succeeded" => "finished",
|
||||||
|
"FAILED" | "failed" | "TIMED_OUT" | "timed_out" => "failed",
|
||||||
|
"CANCELLED" | "cancelled" | "canceled" => "cancelled",
|
||||||
|
other => other,
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bound on `list_jobs` page walking; a warning is logged when the listing
|
||||||
|
/// is truncated at this many pages.
|
||||||
|
const MAX_LIST_JOBS_PAGES: usize = 100;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<S: HttpSend> Database for RemoteDatabase<S> {
|
impl<S: HttpSend> Database for RemoteDatabase<S> {
|
||||||
fn uri(&self) -> &str {
|
fn uri(&self) -> &str {
|
||||||
@@ -441,6 +512,108 @@ impl<S: HttpSend> Database for RemoteDatabase<S> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn job(&self, job_id: &str) -> Result<crate::job::Job> {
|
||||||
|
Ok(crate::job::Job::new(Box::new(super::job::RemoteJob::new(
|
||||||
|
self.client.clone(),
|
||||||
|
job_id.to_string(),
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_jobs(&self) -> Result<Vec<JobInfo>> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
let mut page_token: Option<String> = None;
|
||||||
|
for page in 0..MAX_LIST_JOBS_PAGES {
|
||||||
|
let mut body = serde_json::json!({});
|
||||||
|
if let Some(token) = &page_token {
|
||||||
|
body["page_token"] = serde_json::Value::String(token.clone());
|
||||||
|
}
|
||||||
|
let req = self.client.post("/v1/jobs/list").json(&body);
|
||||||
|
let (request_id, rsp) = self.client.send(req).await?;
|
||||||
|
let rsp = self.client.check_response(&request_id, rsp).await?;
|
||||||
|
let body: RemoteListJobsResponse = rsp.json().await.err_to_http(request_id)?;
|
||||||
|
out.extend(body.jobs.into_iter().map(|row| JobInfo {
|
||||||
|
job_id: row.job_id,
|
||||||
|
table: row.table,
|
||||||
|
job_type: row.job_type,
|
||||||
|
state: job_state_to_client(&row.state),
|
||||||
|
created_at_millis: row.created_at_millis,
|
||||||
|
}));
|
||||||
|
page_token = body.page_token;
|
||||||
|
if page_token.is_none() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if page + 1 == MAX_LIST_JOBS_PAGES {
|
||||||
|
log::warn!(
|
||||||
|
"list_jobs truncated after {} pages ({} jobs)",
|
||||||
|
MAX_LIST_JOBS_PAGES,
|
||||||
|
out.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_job(&self, job_id: &str) -> Result<Option<JobDescription>> {
|
||||||
|
let req = self
|
||||||
|
.client
|
||||||
|
.post("/v1/jobs/describe")
|
||||||
|
.json(&serde_json::json!({ "job_id": job_id }));
|
||||||
|
let (request_id, rsp) = self.client.send(req).await?;
|
||||||
|
let rsp = match self.client.check_response(&request_id, rsp).await {
|
||||||
|
Ok(rsp) => rsp,
|
||||||
|
Err(Error::Http {
|
||||||
|
status_code: Some(StatusCode::NOT_FOUND),
|
||||||
|
..
|
||||||
|
}) => return Ok(None),
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
};
|
||||||
|
let body: RemoteDescribeJobResponse = rsp.json().await.err_to_http(request_id)?;
|
||||||
|
Ok(Some(JobDescription {
|
||||||
|
job_id: body.job_id,
|
||||||
|
job_type: body.job_type,
|
||||||
|
state: job_state_to_client(&body.job_state),
|
||||||
|
creation_ms: body.creation_ms,
|
||||||
|
spec: body.spec,
|
||||||
|
failure: body.failure.map(|reported| crate::error::JobFailure {
|
||||||
|
phase: reported.phase,
|
||||||
|
message: reported.message,
|
||||||
|
retryable: reported.retryable,
|
||||||
|
source: None,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn cancel_job(&self, job_id: &str) -> Result<bool> {
|
||||||
|
let req = self
|
||||||
|
.client
|
||||||
|
.post("/v1/jobs/cancel")
|
||||||
|
.json(&serde_json::json!({ "job_id": job_id }));
|
||||||
|
let (request_id, rsp) = self.client.send(req).await?;
|
||||||
|
match self.client.check_response(&request_id, rsp).await {
|
||||||
|
Ok(_) => Ok(true),
|
||||||
|
Err(Error::Http {
|
||||||
|
status_code: Some(StatusCode::NOT_FOUND),
|
||||||
|
..
|
||||||
|
}) => Ok(false),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn job_history(&self, job_id: Option<&str>) -> Result<Vec<arrow_array::RecordBatch>> {
|
||||||
|
let mut body = serde_json::json!({});
|
||||||
|
if let Some(job_id) = job_id {
|
||||||
|
body["job_id"] = serde_json::Value::String(job_id.to_string());
|
||||||
|
}
|
||||||
|
let req = self.client.post("/v1/jobs/query_events").json(&body);
|
||||||
|
let (request_id, rsp) = self.client.send(req).await?;
|
||||||
|
let rsp = self.client.check_response(&request_id, rsp).await?;
|
||||||
|
let bytes = rsp.bytes().await.err_to_http(request_id)?;
|
||||||
|
let reader = arrow_ipc::reader::StreamReader::try_new(std::io::Cursor::new(bytes), None)?;
|
||||||
|
reader
|
||||||
|
.collect::<std::result::Result<Vec<_>, _>>()
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
async fn table_names(&self, request: TableNamesRequest) -> Result<Vec<String>> {
|
async fn table_names(&self, request: TableNamesRequest) -> Result<Vec<String>> {
|
||||||
let mut req = if !request.namespace_path.is_empty() {
|
let mut req = if !request.namespace_path.is_empty() {
|
||||||
let namespace_id =
|
let namespace_id =
|
||||||
@@ -661,6 +834,7 @@ impl<S: HttpSend> Database for RemoteDatabase<S> {
|
|||||||
RemoteTable::<S>::handle_table_not_found(&request.name, rsp, &request_id).await?;
|
RemoteTable::<S>::handle_table_not_found(&request.name, rsp, &request_id).await?;
|
||||||
let rsp = self.client.check_response(&request_id, rsp).await?;
|
let rsp = self.client.check_response(&request_id, rsp).await?;
|
||||||
let version = parse_server_version(&request_id, &rsp)?;
|
let version = parse_server_version(&request_id, &rsp)?;
|
||||||
|
let describe_body = rsp.text().await.ok();
|
||||||
let table_identifier = build_table_identifier(
|
let table_identifier = build_table_identifier(
|
||||||
&request.name,
|
&request.name,
|
||||||
&request.namespace_path,
|
&request.namespace_path,
|
||||||
@@ -673,6 +847,12 @@ impl<S: HttpSend> Database for RemoteDatabase<S> {
|
|||||||
table_identifier,
|
table_identifier,
|
||||||
version,
|
version,
|
||||||
));
|
));
|
||||||
|
// This describe already carries the schema, so hand it to the table
|
||||||
|
// instead of making the first schema read fetch it again. A version or
|
||||||
|
// branch pin applied after this invalidates the cache.
|
||||||
|
if let Some(body) = &describe_body {
|
||||||
|
table.seed_schema(body);
|
||||||
|
}
|
||||||
let cache_key = build_cache_key(&request.name, &request.namespace_path);
|
let cache_key = build_cache_key(&request.name, &request.namespace_path);
|
||||||
self.table_cache.insert(cache_key, table.clone()).await;
|
self.table_cache.insert(cache_key, table.clone()).await;
|
||||||
Ok(table)
|
Ok(table)
|
||||||
@@ -923,6 +1103,7 @@ impl From<StorageOptions> for RemoteOptions {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::{NamespaceHeaderProviderContext, build_cache_key};
|
use super::{NamespaceHeaderProviderContext, build_cache_key};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::{Arc, OnceLock};
|
use std::sync::{Arc, OnceLock};
|
||||||
|
|
||||||
use arrow_array::{Int32Array, RecordBatch};
|
use arrow_array::{Int32Array, RecordBatch};
|
||||||
@@ -1073,6 +1254,46 @@ mod tests {
|
|||||||
assert_eq!(table.name(), "table1");
|
assert_eq!(table.name(), "table1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_open_table_seeds_the_schema_from_its_describe() {
|
||||||
|
let describe_calls = Arc::new(AtomicUsize::new(0));
|
||||||
|
let counted = describe_calls.clone();
|
||||||
|
let conn = Connection::new_with_handler(move |request| {
|
||||||
|
assert_eq!(request.url().path(), "/v1/table/table1/describe/");
|
||||||
|
counted.fetch_add(1, Ordering::SeqCst);
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(
|
||||||
|
r#"{"version": 1, "schema": {"fields": [
|
||||||
|
{"name": "id", "type": {"type": "int64"}, "nullable": false}
|
||||||
|
]}}"#
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
let table = conn.open_table("table1").execute().await.unwrap();
|
||||||
|
let schema = table.schema().await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(schema.field(0).name(), "id");
|
||||||
|
assert_eq!(describe_calls.load(Ordering::SeqCst), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_open_table_survives_a_describe_body_it_cannot_parse() {
|
||||||
|
let conn = Connection::new_with_handler(|request| {
|
||||||
|
assert_eq!(request.url().path(), "/v1/table/table1/describe/");
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(r#"{"table": "table1"}"#.to_string())
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
let table = conn.open_table("table1").execute().await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(table.name(), "table1");
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_open_table_branch_and_version() {
|
async fn test_open_table_branch_and_version() {
|
||||||
let conn = Connection::new_with_handler(|request| {
|
let conn = Connection::new_with_handler(|request| {
|
||||||
@@ -2042,4 +2263,165 @@ mod tests {
|
|||||||
assert!(list_response.tables.contains(&"table3".to_string()));
|
assert!(list_response.tables.contains(&"table3".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_list_jobs_paginates() {
|
||||||
|
let page = Arc::new(AtomicUsize::new(0));
|
||||||
|
let conn = Connection::new_with_handler(move |request| {
|
||||||
|
assert_eq!(request.method(), &reqwest::Method::POST);
|
||||||
|
assert_eq!(request.url().path(), "/v1/jobs/list");
|
||||||
|
let body: serde_json::Value =
|
||||||
|
serde_json::from_slice(request.body().unwrap().as_bytes().unwrap()).unwrap();
|
||||||
|
match page.fetch_add(1, Ordering::SeqCst) {
|
||||||
|
0 => {
|
||||||
|
assert!(body.get("page_token").is_none());
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(
|
||||||
|
r#"{"jobs": [{"job_id": "job-1", "table": "t1", "job_type": "create_index", "state": "in_progress", "created_at_millis": 1000}], "page_token": "next"}"#,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
assert_eq!(body["page_token"], "next");
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(
|
||||||
|
r#"{"jobs": [{"job_id": "job-2", "table": "t2", "job_type": "create_index", "state": "succeeded", "created_at_millis": 2000}, {"job_id": "job-3", "table": "t3", "job_type": "create_index", "state": "timed_out", "created_at_millis": 3000}]}"#,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let jobs = conn.list_jobs().await.unwrap();
|
||||||
|
assert_eq!(jobs.len(), 3);
|
||||||
|
assert_eq!(jobs[0].job_id, "job-1");
|
||||||
|
assert_eq!(jobs[0].table, "t1");
|
||||||
|
assert_eq!(jobs[0].state, "running");
|
||||||
|
assert_eq!(jobs[1].job_id, "job-2");
|
||||||
|
assert_eq!(jobs[1].state, "finished");
|
||||||
|
assert_eq!(jobs[1].created_at_millis, 2000);
|
||||||
|
assert_eq!(jobs[2].job_id, "job-3");
|
||||||
|
assert_eq!(jobs[2].state, "failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_job() {
|
||||||
|
let conn = Connection::new_with_handler(|request| {
|
||||||
|
assert_eq!(request.method(), &reqwest::Method::POST);
|
||||||
|
assert_eq!(request.url().path(), "/v1/jobs/describe");
|
||||||
|
let body: serde_json::Value =
|
||||||
|
serde_json::from_slice(request.body().unwrap().as_bytes().unwrap()).unwrap();
|
||||||
|
assert_eq!(body["job_id"], "job-1");
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(
|
||||||
|
r#"{"job_id": "job-1", "job_type": "create_index", "job_state": "FAILED", "creation_ms": 1000, "spec": {"column": "vec"}, "failure": {"phase": "execute", "message": "worker died", "retryable": true}}"#,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
let job = conn.get_job("job-1").await.unwrap().unwrap();
|
||||||
|
assert_eq!(job.job_id, "job-1");
|
||||||
|
assert_eq!(job.job_type, "create_index");
|
||||||
|
assert_eq!(job.state, "failed");
|
||||||
|
assert_eq!(job.creation_ms, 1000);
|
||||||
|
assert_eq!(job.spec["column"], "vec");
|
||||||
|
let failure = job.failure.unwrap();
|
||||||
|
assert_eq!(failure.phase.as_deref(), Some("execute"));
|
||||||
|
assert_eq!(failure.message.as_deref(), Some("worker died"));
|
||||||
|
assert_eq!(failure.retryable, Some(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_job_missing_is_none() {
|
||||||
|
let conn = Connection::new_with_handler(|_| {
|
||||||
|
http::Response::builder()
|
||||||
|
.status(404)
|
||||||
|
.body("no such job")
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
assert!(conn.get_job("nope").await.unwrap().is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_cancel_job() {
|
||||||
|
let conn = Connection::new_with_handler(|request| {
|
||||||
|
assert_eq!(request.url().path(), "/v1/jobs/cancel");
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(r#"{"job_id": "job-1"}"#)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
assert!(conn.cancel_job("job-1").await.unwrap());
|
||||||
|
|
||||||
|
let conn = Connection::new_with_handler(|_| {
|
||||||
|
http::Response::builder()
|
||||||
|
.status(404)
|
||||||
|
.body("no such job")
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
assert!(!conn.cancel_job("nope").await.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_job_history_parses_arrow_stream() {
|
||||||
|
let schema = Arc::new(Schema::new(vec![Field::new(
|
||||||
|
"state",
|
||||||
|
DataType::Utf8,
|
||||||
|
false,
|
||||||
|
)]));
|
||||||
|
let batch = RecordBatch::try_new(
|
||||||
|
schema.clone(),
|
||||||
|
vec![Arc::new(arrow_array::StringArray::from(vec![
|
||||||
|
"created", "done",
|
||||||
|
]))],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let mut body = Vec::new();
|
||||||
|
{
|
||||||
|
let mut writer = arrow_ipc::writer::StreamWriter::try_new(&mut body, &schema).unwrap();
|
||||||
|
writer.write(&batch).unwrap();
|
||||||
|
writer.finish().unwrap();
|
||||||
|
}
|
||||||
|
let conn = Connection::new_with_handler(move |request| {
|
||||||
|
assert_eq!(request.url().path(), "/v1/jobs/query_events");
|
||||||
|
let req_body: serde_json::Value =
|
||||||
|
serde_json::from_slice(request.body().unwrap().as_bytes().unwrap()).unwrap();
|
||||||
|
assert_eq!(req_body["job_id"], "job-1");
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(body.clone())
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
let batches = conn.job_history(Some("job-1")).await.unwrap();
|
||||||
|
assert_eq!(batches.len(), 1);
|
||||||
|
assert_eq!(batches[0].num_rows(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_conn_job_waits_to_done() {
|
||||||
|
let polls = Arc::new(AtomicUsize::new(0));
|
||||||
|
let polls_ref = polls.clone();
|
||||||
|
let conn = Connection::new_with_handler(move |request| {
|
||||||
|
assert_eq!(request.url().path(), "/v1/jobs/describe");
|
||||||
|
let state = if polls_ref.fetch_add(1, Ordering::SeqCst) == 0 {
|
||||||
|
"IN_PROGRESS"
|
||||||
|
} else {
|
||||||
|
"DONE"
|
||||||
|
};
|
||||||
|
http::Response::builder()
|
||||||
|
.status(200)
|
||||||
|
.body(format!(
|
||||||
|
r#"{{"job_id": "job-1", "job_type": "create_index", "job_state": "{}", "creation_ms": 1}}"#,
|
||||||
|
state
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
let job = conn.job("job-1").unwrap();
|
||||||
|
assert_eq!(job.id(), Some("job-1"));
|
||||||
|
assert_eq!(job.status().await.unwrap(), "running");
|
||||||
|
job.wait().await.unwrap();
|
||||||
|
assert_eq!(job.status().await.unwrap(), "finished");
|
||||||
|
assert!(polls.load(Ordering::SeqCst) >= 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,170 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||||
|
|
||||||
|
//! Tracking for server-side jobs through the `/v1/jobs` API.
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
|
use crate::error::{Error, JobFailure, Result};
|
||||||
|
use crate::job::JobHandle;
|
||||||
|
use crate::remote::client::{HttpSend, RequestResultExt, RestfulLanceDbClient};
|
||||||
|
|
||||||
|
/// Delay before the second job-state poll; doubles up to [`MAX_POLL_INTERVAL`].
|
||||||
|
const INITIAL_POLL_INTERVAL: Duration = Duration::from_millis(200);
|
||||||
|
const MAX_POLL_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
enum JobState {
|
||||||
|
InProgress,
|
||||||
|
Cancelled,
|
||||||
|
Failed,
|
||||||
|
Done,
|
||||||
|
/// A state this client version does not know; treated as still running
|
||||||
|
/// and reported as-is if the job never settles.
|
||||||
|
Other(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for JobState {
|
||||||
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> {
|
||||||
|
Ok(Self::from(String::deserialize(deserializer)?.as_str()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JobState {
|
||||||
|
/// The client vocabulary label for this state.
|
||||||
|
fn client_label(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::InProgress => "running".to_string(),
|
||||||
|
Self::Done => "finished".to_string(),
|
||||||
|
Self::Failed => "failed".to_string(),
|
||||||
|
Self::Cancelled => "cancelled".to_string(),
|
||||||
|
Self::Other(state) => state.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for JobState {
|
||||||
|
fn from(state: &str) -> Self {
|
||||||
|
match state {
|
||||||
|
"IN_PROGRESS" => Self::InProgress,
|
||||||
|
"CANCELLED" => Self::Cancelled,
|
||||||
|
// The server reports a timed-out job as FAILED on describe;
|
||||||
|
// accept the raw registry state too in case a future server
|
||||||
|
// stops folding it.
|
||||||
|
"FAILED" | "TIMED_OUT" => Self::Failed,
|
||||||
|
"DONE" => Self::Done,
|
||||||
|
other => Self::Other(other.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The server's account of why a job failed. Absent from older servers, which
|
||||||
|
/// report only the terminal state.
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ReportedFailure {
|
||||||
|
#[serde(default)]
|
||||||
|
phase: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
message: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
retryable: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct DescribeJobResponse {
|
||||||
|
job_state: JobState,
|
||||||
|
#[serde(default)]
|
||||||
|
failure: Option<ReportedFailure>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RemoteJob<S: HttpSend> {
|
||||||
|
client: RestfulLanceDbClient<S>,
|
||||||
|
job_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: HttpSend> RemoteJob<S> {
|
||||||
|
pub fn new(client: RestfulLanceDbClient<S>, job_id: String) -> Self {
|
||||||
|
Self { client, job_id }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One `/v1/jobs/describe` round trip.
|
||||||
|
async fn describe(&self) -> Result<DescribeJobResponse> {
|
||||||
|
let request = self
|
||||||
|
.client
|
||||||
|
.post("/v1/jobs/describe")
|
||||||
|
.json(&serde_json::json!({ "job_id": self.job_id }));
|
||||||
|
let (request_id, response) = self.client.send(request).await?;
|
||||||
|
let response = self.client.check_response(&request_id, response).await?;
|
||||||
|
let body = response.text().await.err_to_http(request_id.clone())?;
|
||||||
|
let description: DescribeJobResponse =
|
||||||
|
serde_json::from_str(&body).map_err(|e| Error::Http {
|
||||||
|
source: format!("failed to parse job description: {}", e).into(),
|
||||||
|
request_id,
|
||||||
|
status_code: None,
|
||||||
|
})?;
|
||||||
|
Ok(description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<S: HttpSend> JobHandle for RemoteJob<S> {
|
||||||
|
fn id(&self) -> Option<&str> {
|
||||||
|
Some(&self.job_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn status(&self) -> Result<String> {
|
||||||
|
Ok(self.describe().await?.job_state.client_label())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn wait(&self) -> Result<()> {
|
||||||
|
let mut interval = INITIAL_POLL_INTERVAL;
|
||||||
|
loop {
|
||||||
|
let description = self.describe().await?;
|
||||||
|
match description.job_state {
|
||||||
|
JobState::Done => return Ok(()),
|
||||||
|
JobState::Failed => {
|
||||||
|
return Err(Error::JobFailed {
|
||||||
|
job_id: Some(self.job_id.clone()),
|
||||||
|
failure: description
|
||||||
|
.failure
|
||||||
|
.map(|reported| JobFailure {
|
||||||
|
phase: reported.phase,
|
||||||
|
message: reported.message,
|
||||||
|
retryable: reported.retryable,
|
||||||
|
source: None,
|
||||||
|
})
|
||||||
|
.unwrap_or_default(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
JobState::Cancelled => {
|
||||||
|
return Err(Error::JobCancelled {
|
||||||
|
job_id: Some(self.job_id.clone()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
JobState::InProgress => {}
|
||||||
|
JobState::Other(ref state) => {
|
||||||
|
log::debug!("job {} is in unrecognized state {state}", self.job_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(interval).await;
|
||||||
|
interval = (interval * 2).min(MAX_POLL_INTERVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn cancel(&self) -> Result<()> {
|
||||||
|
let request = self
|
||||||
|
.client
|
||||||
|
.post("/v1/jobs/cancel")
|
||||||
|
.json(&serde_json::json!({ "job_id": self.job_id }));
|
||||||
|
let (request_id, response) = self.client.send(request).await?;
|
||||||
|
self.client
|
||||||
|
.check_response(&request_id, response)
|
||||||
|
.await
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
}
|
||||||
+1070
-257
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user