mirror of
https://github.com/lancedb/lancedb.git
synced 2025-12-23 13:29:57 +00:00
Compare commits
2 Commits
python-v0.
...
docs_enhan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8debf26b81 | ||
|
|
d2af9fd81d |
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.4.11
|
current_version = 0.4.10
|
||||||
commit = True
|
commit = True
|
||||||
message = Bump version: {current_version} → {new_version}
|
message = Bump version: {current_version} → {new_version}
|
||||||
tag = True
|
tag = True
|
||||||
@@ -9,4 +9,4 @@ tag_name = v{new_version}
|
|||||||
|
|
||||||
[bumpversion:file:rust/ffi/node/Cargo.toml]
|
[bumpversion:file:rust/ffi/node/Cargo.toml]
|
||||||
|
|
||||||
[bumpversion:file:rust/lancedb/Cargo.toml]
|
[bumpversion:file:rust/vectordb/Cargo.toml]
|
||||||
|
|||||||
@@ -33,8 +33,3 @@ rustflags = ["-C", "target-cpu=haswell", "-C", "target-feature=+avx2,+fma,+f16c"
|
|||||||
|
|
||||||
[target.aarch64-apple-darwin]
|
[target.aarch64-apple-darwin]
|
||||||
rustflags = ["-C", "target-cpu=apple-m1", "-C", "target-feature=+neon,+fp16,+fhm,+dotprod"]
|
rustflags = ["-C", "target-cpu=apple-m1", "-C", "target-feature=+neon,+fp16,+fhm,+dotprod"]
|
||||||
|
|
||||||
# Not all Windows systems have the C runtime installed, so this avoids library
|
|
||||||
# not found errors on systems that are missing it.
|
|
||||||
[target.x86_64-pc-windows-msvc]
|
|
||||||
rustflags = ["-Ctarget-feature=+crt-static"]
|
|
||||||
|
|||||||
58
.github/workflows/build_linux_wheel/action.yml
vendored
58
.github/workflows/build_linux_wheel/action.yml
vendored
@@ -1,58 +0,0 @@
|
|||||||
# We create a composite action to be re-used both for testing and for releasing
|
|
||||||
name: build-linux-wheel
|
|
||||||
description: "Build a manylinux wheel for lance"
|
|
||||||
inputs:
|
|
||||||
python-minor-version:
|
|
||||||
description: "8, 9, 10, 11, 12"
|
|
||||||
required: true
|
|
||||||
args:
|
|
||||||
description: "--release"
|
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
arm-build:
|
|
||||||
description: "Build for arm64 instead of x86_64"
|
|
||||||
# Note: this does *not* mean the host is arm64, since we might be cross-compiling.
|
|
||||||
required: false
|
|
||||||
default: "false"
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: CONFIRM ARM BUILD
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "ARM BUILD: ${{ inputs.arm-build }}"
|
|
||||||
- name: Build x86_64 Manylinux wheel
|
|
||||||
if: ${{ inputs.arm-build == 'false' }}
|
|
||||||
uses: PyO3/maturin-action@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
working-directory: python
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
manylinux: "2_17"
|
|
||||||
args: ${{ inputs.args }}
|
|
||||||
before-script-linux: |
|
|
||||||
set -e
|
|
||||||
yum install -y openssl-devel \
|
|
||||||
&& curl -L https://github.com/protocolbuffers/protobuf/releases/download/v24.4/protoc-24.4-linux-$(uname -m).zip > /tmp/protoc.zip \
|
|
||||||
&& unzip /tmp/protoc.zip -d /usr/local \
|
|
||||||
&& rm /tmp/protoc.zip
|
|
||||||
- name: Build Arm Manylinux Wheel
|
|
||||||
if: ${{ inputs.arm-build == 'true' }}
|
|
||||||
uses: PyO3/maturin-action@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
working-directory: python
|
|
||||||
target: aarch64-unknown-linux-gnu
|
|
||||||
manylinux: "2_24"
|
|
||||||
args: ${{ inputs.args }}
|
|
||||||
before-script-linux: |
|
|
||||||
set -e
|
|
||||||
apt install -y unzip
|
|
||||||
if [ $(uname -m) = "x86_64" ]; then
|
|
||||||
PROTOC_ARCH="x86_64"
|
|
||||||
else
|
|
||||||
PROTOC_ARCH="aarch_64"
|
|
||||||
fi
|
|
||||||
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v24.4/protoc-24.4-linux-$PROTOC_ARCH.zip > /tmp/protoc.zip \
|
|
||||||
&& unzip /tmp/protoc.zip -d /usr/local \
|
|
||||||
&& rm /tmp/protoc.zip
|
|
||||||
25
.github/workflows/build_mac_wheel/action.yml
vendored
25
.github/workflows/build_mac_wheel/action.yml
vendored
@@ -1,25 +0,0 @@
|
|||||||
# We create a composite action to be re-used both for testing and for releasing
|
|
||||||
name: build_wheel
|
|
||||||
description: "Build a lance wheel"
|
|
||||||
inputs:
|
|
||||||
python-minor-version:
|
|
||||||
description: "8, 9, 10, 11"
|
|
||||||
required: true
|
|
||||||
args:
|
|
||||||
description: "--release"
|
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Install macos dependency
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
brew install protobuf
|
|
||||||
- name: Build wheel
|
|
||||||
uses: PyO3/maturin-action@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
args: ${{ inputs.args }}
|
|
||||||
working-directory: python
|
|
||||||
interpreter: 3.${{ inputs.python-minor-version }}
|
|
||||||
33
.github/workflows/build_windows_wheel/action.yml
vendored
33
.github/workflows/build_windows_wheel/action.yml
vendored
@@ -1,33 +0,0 @@
|
|||||||
# We create a composite action to be re-used both for testing and for releasing
|
|
||||||
name: build_wheel
|
|
||||||
description: "Build a lance wheel"
|
|
||||||
inputs:
|
|
||||||
python-minor-version:
|
|
||||||
description: "8, 9, 10, 11"
|
|
||||||
required: true
|
|
||||||
args:
|
|
||||||
description: "--release"
|
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Install Protoc v21.12
|
|
||||||
working-directory: C:\
|
|
||||||
run: |
|
|
||||||
New-Item -Path 'C:\protoc' -ItemType Directory
|
|
||||||
Set-Location C:\protoc
|
|
||||||
Invoke-WebRequest https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-win64.zip -OutFile C:\protoc\protoc.zip
|
|
||||||
7z x protoc.zip
|
|
||||||
Add-Content $env:GITHUB_PATH "C:\protoc\bin"
|
|
||||||
shell: powershell
|
|
||||||
- name: Build wheel
|
|
||||||
uses: PyO3/maturin-action@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
args: ${{ inputs.args }}
|
|
||||||
working-directory: python
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: windows-wheels
|
|
||||||
path: python\target\wheels
|
|
||||||
2
.github/workflows/cargo-publish.yml
vendored
2
.github/workflows/cargo-publish.yml
vendored
@@ -26,4 +26,4 @@ jobs:
|
|||||||
sudo apt install -y protobuf-compiler libssl-dev
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
- name: Publish the package
|
- name: Publish the package
|
||||||
run: |
|
run: |
|
||||||
cargo publish -p lancedb --all-features --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
cargo publish -p vectordb --all-features --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||||
|
|||||||
101
.github/workflows/pypi-publish.yml
vendored
101
.github/workflows/pypi-publish.yml
vendored
@@ -2,91 +2,30 @@ name: PyPI Publish
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [ published ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
linux:
|
publish:
|
||||||
timeout-minutes: 60
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
# Only runs on tags that matches the python-make-release action
|
||||||
matrix:
|
if: startsWith(github.ref, 'refs/tags/python-v')
|
||||||
python-minor-version: ["8"]
|
defaults:
|
||||||
platform:
|
run:
|
||||||
- x86_64
|
shell: bash
|
||||||
- aarch64
|
working-directory: python
|
||||||
runs-on: "ubuntu-22.04"
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: 3.${{ matrix.python-minor-version }}
|
python-version: "3.8"
|
||||||
- uses: ./.github/workflows/build_linux_wheel
|
- name: Build distribution
|
||||||
|
run: |
|
||||||
|
ls -la
|
||||||
|
pip install wheel setuptools --upgrade
|
||||||
|
python setup.py sdist bdist_wheel
|
||||||
|
- name: Publish
|
||||||
|
uses: pypa/gh-action-pypi-publish@v1.8.5
|
||||||
with:
|
with:
|
||||||
python-minor-version: ${{ matrix.python-minor-version }}
|
password: ${{ secrets.LANCEDB_PYPI_API_TOKEN }}
|
||||||
args: "--release --strip"
|
packages-dir: python/dist
|
||||||
arm-build: ${{ matrix.platform == 'aarch64' }}
|
|
||||||
- uses: ./.github/workflows/upload_wheel
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.LANCEDB_PYPI_API_TOKEN }}
|
|
||||||
repo: "pypi"
|
|
||||||
mac:
|
|
||||||
timeout-minutes: 60
|
|
||||||
runs-on: ${{ matrix.config.runner }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
python-minor-version: ["8"]
|
|
||||||
config:
|
|
||||||
- target: x86_64-apple-darwin
|
|
||||||
runner: macos-13
|
|
||||||
- target: aarch64-apple-darwin
|
|
||||||
runner: macos-14
|
|
||||||
env:
|
|
||||||
MACOSX_DEPLOYMENT_TARGET: 10.15
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ inputs.ref }}
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: 3.12
|
|
||||||
- uses: ./.github/workflows/build_mac_wheel
|
|
||||||
with:
|
|
||||||
python-minor-version: ${{ matrix.python-minor-version }}
|
|
||||||
args: "--release --strip --target ${{ matrix.config.target }}"
|
|
||||||
- uses: ./.github/workflows/upload_wheel
|
|
||||||
with:
|
|
||||||
python-minor-version: ${{ matrix.python-minor-version }}
|
|
||||||
token: ${{ secrets.LANCEDB_PYPI_API_TOKEN }}
|
|
||||||
repo: "pypi"
|
|
||||||
windows:
|
|
||||||
timeout-minutes: 60
|
|
||||||
runs-on: windows-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
python-minor-version: ["8"]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ inputs.ref }}
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: 3.${{ matrix.python-minor-version }}
|
|
||||||
- uses: ./.github/workflows/build_windows_wheel
|
|
||||||
with:
|
|
||||||
python-minor-version: ${{ matrix.python-minor-version }}
|
|
||||||
args: "--release --strip"
|
|
||||||
vcpkg_token: ${{ secrets.VCPKG_GITHUB_PACKAGES }}
|
|
||||||
- uses: ./.github/workflows/upload_wheel
|
|
||||||
with:
|
|
||||||
python-minor-version: ${{ matrix.python-minor-version }}
|
|
||||||
token: ${{ secrets.LANCEDB_PYPI_API_TOKEN }}
|
|
||||||
repo: "pypi"
|
|
||||||
|
|||||||
204
.github/workflows/python.yml
vendored
204
.github/workflows/python.yml
vendored
@@ -14,133 +14,49 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
|
||||||
name: "Lint"
|
|
||||||
timeout-minutes: 30
|
|
||||||
runs-on: "ubuntu-22.04"
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
working-directory: python
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
- name: Install ruff
|
|
||||||
run: |
|
|
||||||
pip install ruff==0.2.2
|
|
||||||
- name: Format check
|
|
||||||
run: ruff format --check .
|
|
||||||
- name: Lint
|
|
||||||
run: ruff .
|
|
||||||
doctest:
|
|
||||||
name: "Doctest"
|
|
||||||
timeout-minutes: 30
|
|
||||||
runs-on: "ubuntu-22.04"
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
working-directory: python
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
cache: "pip"
|
|
||||||
- name: Install protobuf
|
|
||||||
run: |
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install -y protobuf-compiler
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
with:
|
|
||||||
workspaces: python
|
|
||||||
- name: Install
|
|
||||||
run: |
|
|
||||||
pip install -e .[tests,dev,embeddings]
|
|
||||||
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
|
||||||
pip install mlx
|
|
||||||
- name: Doctest
|
|
||||||
run: pytest --doctest-modules python/lancedb
|
|
||||||
linux:
|
linux:
|
||||||
name: "Linux: python-3.${{ matrix.python-minor-version }}"
|
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-minor-version: ["8", "11"]
|
python-minor-version: [ "8", "11" ]
|
||||||
runs-on: "ubuntu-22.04"
|
runs-on: "ubuntu-22.04"
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: python
|
working-directory: python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Install protobuf
|
- name: Set up Python
|
||||||
run: |
|
uses: actions/setup-python@v5
|
||||||
sudo apt update
|
with:
|
||||||
sudo apt install -y protobuf-compiler
|
python-version: 3.${{ matrix.python-minor-version }}
|
||||||
- name: Set up Python
|
- name: Install lancedb
|
||||||
uses: actions/setup-python@v5
|
run: |
|
||||||
with:
|
pip install -e .[tests]
|
||||||
python-version: 3.${{ matrix.python-minor-version }}
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
- uses: Swatinem/rust-cache@v2
|
pip install pytest pytest-mock ruff
|
||||||
with:
|
- name: Format check
|
||||||
workspaces: python
|
run: ruff format --check .
|
||||||
- uses: ./.github/workflows/build_linux_wheel
|
- name: Lint
|
||||||
- uses: ./.github/workflows/run_tests
|
run: ruff .
|
||||||
# Make sure wheels are not included in the Rust cache
|
- name: Run tests
|
||||||
- name: Delete wheels
|
run: pytest -m "not slow" -x -v --durations=30 tests
|
||||||
run: rm -rf target/wheels
|
- name: doctest
|
||||||
|
run: pytest --doctest-modules lancedb
|
||||||
platform:
|
platform:
|
||||||
name: "Mac: ${{ matrix.config.name }}"
|
name: "Platform: ${{ matrix.config.name }}"
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
config:
|
config:
|
||||||
- name: x86
|
- name: x86 Mac
|
||||||
runner: macos-13
|
runner: macos-13
|
||||||
- name: Arm
|
- name: Arm Mac
|
||||||
runner: macos-14
|
runner: macos-14
|
||||||
runs-on: "${{ matrix.config.runner }}"
|
- name: x86 Windows
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
working-directory: python
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
with:
|
|
||||||
workspaces: python
|
|
||||||
- uses: ./.github/workflows/build_mac_wheel
|
|
||||||
- uses: ./.github/workflows/run_tests
|
|
||||||
# Make sure wheels are not included in the Rust cache
|
|
||||||
- name: Delete wheels
|
|
||||||
run: rm -rf target/wheels
|
|
||||||
windows:
|
|
||||||
name: "Windows: ${{ matrix.config.name }}"
|
|
||||||
timeout-minutes: 30
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
config:
|
|
||||||
- name: x86
|
|
||||||
runner: windows-latest
|
runner: windows-latest
|
||||||
runs-on: "${{ matrix.config.runner }}"
|
runs-on: "${{ matrix.config.runner }}"
|
||||||
defaults:
|
defaults:
|
||||||
@@ -148,22 +64,21 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
working-directory: python
|
working-directory: python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.11"
|
python-version: "3.11"
|
||||||
- uses: Swatinem/rust-cache@v2
|
- name: Install lancedb
|
||||||
with:
|
run: |
|
||||||
workspaces: python
|
pip install -e .[tests]
|
||||||
- uses: ./.github/workflows/build_windows_wheel
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
- uses: ./.github/workflows/run_tests
|
pip install pytest pytest-mock
|
||||||
# Make sure wheels are not included in the Rust cache
|
- name: Run tests
|
||||||
- name: Delete wheels
|
run: pytest -m "not slow" -x -v --durations=30 tests
|
||||||
run: rm -rf target/wheels
|
|
||||||
pydantic1x:
|
pydantic1x:
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
runs-on: "ubuntu-22.04"
|
runs-on: "ubuntu-22.04"
|
||||||
@@ -172,22 +87,21 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
working-directory: python
|
working-directory: python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Install dependencies
|
- name: Set up Python
|
||||||
run: |
|
uses: actions/setup-python@v5
|
||||||
sudo apt update
|
with:
|
||||||
sudo apt install -y protobuf-compiler
|
python-version: 3.9
|
||||||
- name: Set up Python
|
- name: Install lancedb
|
||||||
uses: actions/setup-python@v5
|
run: |
|
||||||
with:
|
pip install "pydantic<2"
|
||||||
python-version: 3.9
|
pip install -e .[tests]
|
||||||
- name: Install lancedb
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
run: |
|
pip install pytest pytest-mock
|
||||||
pip install "pydantic<2"
|
- name: Run tests
|
||||||
pip install -e .[tests]
|
run: pytest -m "not slow" -x -v --durations=30 tests
|
||||||
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
- name: doctest
|
||||||
- name: Run tests
|
run: pytest --doctest-modules lancedb
|
||||||
run: pytest -m "not slow" -x -v --durations=30 python/tests
|
|
||||||
|
|||||||
37
.github/workflows/remote-integration.yml
vendored
37
.github/workflows/remote-integration.yml
vendored
@@ -1,37 +0,0 @@
|
|||||||
name: LanceDb Cloud Integration Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows: [Rust]
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
env:
|
|
||||||
LANCEDB_PROJECT: ${{ secrets.LANCEDB_PROJECT }}
|
|
||||||
LANCEDB_API_KEY: ${{ secrets.LANCEDB_API_KEY }}
|
|
||||||
LANCEDB_REGION: ${{ secrets.LANCEDB_REGION }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
timeout-minutes: 30
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
working-directory: rust
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
lfs: true
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
with:
|
|
||||||
workspaces: rust
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install -y protobuf-compiler libssl-dev
|
|
||||||
- name: Build
|
|
||||||
run: cargo build --all-features
|
|
||||||
- name: Run Integration test
|
|
||||||
run: cargo test --tests -- --ignored
|
|
||||||
17
.github/workflows/run_tests/action.yml
vendored
17
.github/workflows/run_tests/action.yml
vendored
@@ -1,17 +0,0 @@
|
|||||||
name: run-tests
|
|
||||||
|
|
||||||
description: "Install lance wheel and run unit tests"
|
|
||||||
inputs:
|
|
||||||
python-minor-version:
|
|
||||||
required: true
|
|
||||||
description: "8 9 10 11 12"
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Install lancedb
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
pip3 install $(ls target/wheels/lancedb-*.whl)[tests,dev]
|
|
||||||
- name: pytest
|
|
||||||
shell: bash
|
|
||||||
run: pytest -m "not slow" -x -v --durations=30 python/python/tests
|
|
||||||
1
.github/workflows/rust.yml
vendored
1
.github/workflows/rust.yml
vendored
@@ -119,4 +119,3 @@ jobs:
|
|||||||
$env:VCPKG_ROOT = $env:VCPKG_INSTALLATION_ROOT
|
$env:VCPKG_ROOT = $env:VCPKG_INSTALLATION_ROOT
|
||||||
cargo build
|
cargo build
|
||||||
cargo test
|
cargo test
|
||||||
|
|
||||||
29
.github/workflows/upload_wheel/action.yml
vendored
29
.github/workflows/upload_wheel/action.yml
vendored
@@ -1,29 +0,0 @@
|
|||||||
name: upload-wheel
|
|
||||||
|
|
||||||
description: "Upload wheels to Pypi"
|
|
||||||
inputs:
|
|
||||||
os:
|
|
||||||
required: true
|
|
||||||
description: "ubuntu-22.04 or macos-13"
|
|
||||||
repo:
|
|
||||||
required: false
|
|
||||||
description: "pypi or testpypi"
|
|
||||||
default: "pypi"
|
|
||||||
token:
|
|
||||||
required: true
|
|
||||||
description: "release token for the repo"
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Install dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install twine
|
|
||||||
- name: Publish wheel
|
|
||||||
env:
|
|
||||||
TWINE_USERNAME: __token__
|
|
||||||
TWINE_PASSWORD: ${{ inputs.token }}
|
|
||||||
shell: bash
|
|
||||||
run: twine upload --repository ${{ inputs.repo }} target/wheels/lancedb-*.whl
|
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -22,11 +22,6 @@ python/dist
|
|||||||
|
|
||||||
**/.hypothesis
|
**/.hypothesis
|
||||||
|
|
||||||
# Compiled Dynamic libraries
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
*.dll
|
|
||||||
|
|
||||||
## Javascript
|
## Javascript
|
||||||
*.node
|
*.node
|
||||||
**/node_modules
|
**/node_modules
|
||||||
@@ -39,6 +34,4 @@ dist
|
|||||||
## Rust
|
## Rust
|
||||||
target
|
target
|
||||||
|
|
||||||
**/sccache.log
|
|
||||||
|
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|||||||
@@ -5,8 +5,17 @@ repos:
|
|||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 22.12.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
# Ruff version.
|
# Ruff version.
|
||||||
rev: v0.2.2
|
rev: v0.0.277
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
|
- repo: https://github.com/pycqa/isort
|
||||||
|
rev: 5.12.0
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
name: isort (python)
|
||||||
10
Cargo.toml
10
Cargo.toml
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["rust/ffi/node", "rust/lancedb", "nodejs", "python"]
|
members = ["rust/ffi/node", "rust/vectordb", "nodejs"]
|
||||||
# Python package needs to be built by maturin.
|
# Python package needs to be built by maturin.
|
||||||
exclude = ["python"]
|
exclude = ["python"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
@@ -14,10 +14,10 @@ keywords = ["lancedb", "lance", "database", "vector", "search"]
|
|||||||
categories = ["database-implementations"]
|
categories = ["database-implementations"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
lance = { "version" = "=0.10.1", "features" = ["dynamodb"] }
|
lance = { "version" = "=0.9.16", "features" = ["dynamodb"] }
|
||||||
lance-index = { "version" = "=0.10.1" }
|
lance-index = { "version" = "=0.9.16" }
|
||||||
lance-linalg = { "version" = "=0.10.1" }
|
lance-linalg = { "version" = "=0.9.16" }
|
||||||
lance-testing = { "version" = "=0.10.1" }
|
lance-testing = { "version" = "=0.9.16" }
|
||||||
# Note that this one does not include pyarrow
|
# Note that this one does not include pyarrow
|
||||||
arrow = { version = "50.0", optional = false }
|
arrow = { version = "50.0", optional = false }
|
||||||
arrow-array = "50.0"
|
arrow-array = "50.0"
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
#Simple base dockerfile that supports basic dependencies required to run lance with FTS and Hybrid Search
|
|
||||||
#Usage docker build -t lancedb:latest -f Dockerfile .
|
|
||||||
FROM python:3.10-slim-buster
|
|
||||||
|
|
||||||
# Install Rust
|
|
||||||
RUN apt-get update && apt-get install -y curl build-essential && \
|
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
|
||||||
|
|
||||||
# Set the environment variable for Rust
|
|
||||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
|
||||||
|
|
||||||
# Install protobuf compiler
|
|
||||||
RUN apt-get install -y protobuf-compiler && \
|
|
||||||
apt-get clean && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
RUN apt-get -y update &&\
|
|
||||||
apt-get -y upgrade && \
|
|
||||||
apt-get -y install git
|
|
||||||
|
|
||||||
|
|
||||||
# Verify installations
|
|
||||||
RUN python --version && \
|
|
||||||
rustc --version && \
|
|
||||||
protoc --version
|
|
||||||
|
|
||||||
RUN pip install tantivy lancedb
|
|
||||||
@@ -57,16 +57,6 @@ plugins:
|
|||||||
- https://arrow.apache.org/docs/objects.inv
|
- https://arrow.apache.org/docs/objects.inv
|
||||||
- https://pandas.pydata.org/docs/objects.inv
|
- https://pandas.pydata.org/docs/objects.inv
|
||||||
- mkdocs-jupyter
|
- mkdocs-jupyter
|
||||||
- ultralytics:
|
|
||||||
verbose: True
|
|
||||||
enabled: True
|
|
||||||
default_image: "assets/lancedb_and_lance.png" # Default image for all pages
|
|
||||||
add_image: True # Automatically add meta image
|
|
||||||
add_keywords: True # Add page keywords in the header tag
|
|
||||||
add_share_buttons: True # Add social share buttons
|
|
||||||
add_authors: False # Display page authors
|
|
||||||
add_desc: False
|
|
||||||
add_dates: False
|
|
||||||
|
|
||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
- admonition
|
- admonition
|
||||||
@@ -109,9 +99,10 @@ nav:
|
|||||||
- Configuring Storage: guides/storage.md
|
- Configuring Storage: guides/storage.md
|
||||||
- 🧬 Managing embeddings:
|
- 🧬 Managing embeddings:
|
||||||
- Overview: embeddings/index.md
|
- Overview: embeddings/index.md
|
||||||
- Embedding functions: embeddings/embedding_functions.md
|
- Explicit management: embeddings/embedding_explicit.md
|
||||||
- Available models: embeddings/default_embedding_functions.md
|
- Implicit management: embeddings/embedding_functions.md
|
||||||
- User-defined embedding functions: embeddings/custom_embedding_function.md
|
- Available Functions: embeddings/default_embedding_functions.md
|
||||||
|
- Custom Embedding Functions: embeddings/api.md
|
||||||
- "Example: Multi-lingual semantic search": notebooks/multi_lingual_example.ipynb
|
- "Example: Multi-lingual semantic search": notebooks/multi_lingual_example.ipynb
|
||||||
- "Example: MultiModal CLIP Embeddings": notebooks/DisappearingEmbeddingFunction.ipynb
|
- "Example: MultiModal CLIP Embeddings": notebooks/DisappearingEmbeddingFunction.ipynb
|
||||||
- 🔌 Integrations:
|
- 🔌 Integrations:
|
||||||
@@ -173,9 +164,10 @@ nav:
|
|||||||
- Configuring Storage: guides/storage.md
|
- Configuring Storage: guides/storage.md
|
||||||
- Managing Embeddings:
|
- Managing Embeddings:
|
||||||
- Overview: embeddings/index.md
|
- Overview: embeddings/index.md
|
||||||
- Embedding functions: embeddings/embedding_functions.md
|
- Explicit management: embeddings/embedding_explicit.md
|
||||||
- Available models: embeddings/default_embedding_functions.md
|
- Implicit management: embeddings/embedding_functions.md
|
||||||
- User-defined embedding functions: embeddings/custom_embedding_function.md
|
- Available Functions: embeddings/default_embedding_functions.md
|
||||||
|
- Custom Embedding Functions: embeddings/api.md
|
||||||
- "Example: Multi-lingual semantic search": notebooks/multi_lingual_example.ipynb
|
- "Example: Multi-lingual semantic search": notebooks/multi_lingual_example.ipynb
|
||||||
- "Example: MultiModal CLIP Embeddings": notebooks/DisappearingEmbeddingFunction.ipynb
|
- "Example: MultiModal CLIP Embeddings": notebooks/DisappearingEmbeddingFunction.ipynb
|
||||||
- Integrations:
|
- Integrations:
|
||||||
|
|||||||
@@ -2,5 +2,4 @@ mkdocs==1.5.3
|
|||||||
mkdocs-jupyter==0.24.1
|
mkdocs-jupyter==0.24.1
|
||||||
mkdocs-material==9.5.3
|
mkdocs-material==9.5.3
|
||||||
mkdocstrings[python]==0.20.0
|
mkdocstrings[python]==0.20.0
|
||||||
pydantic
|
pydantic
|
||||||
mkdocs-ultralytics-plugin==0.0.44
|
|
||||||
141
docs/src/embeddings/embedding_explicit.md
Normal file
141
docs/src/embeddings/embedding_explicit.md
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
In this workflow, you define your own embedding function and pass it as a callable to LanceDB, invoking it in your code to generate the embeddings. Let's look at some examples.
|
||||||
|
|
||||||
|
### Hugging Face
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Currently, the Hugging Face method is only supported in the Python SDK.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
The most popular open source option is to use the [sentence-transformers](https://www.sbert.net/)
|
||||||
|
library, which can be installed via pip.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install sentence-transformers
|
||||||
|
```
|
||||||
|
|
||||||
|
The example below shows how to use the `paraphrase-albert-small-v2` model to generate embeddings
|
||||||
|
for a given document.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from sentence_transformers import SentenceTransformer
|
||||||
|
|
||||||
|
name="paraphrase-albert-small-v2"
|
||||||
|
model = SentenceTransformer(name)
|
||||||
|
|
||||||
|
# used for both training and querying
|
||||||
|
def embed_func(batch):
|
||||||
|
return [model.encode(sentence) for sentence in batch]
|
||||||
|
```
|
||||||
|
|
||||||
|
### OpenAI
|
||||||
|
|
||||||
|
Another popular alternative is to use an external API like OpenAI's [embeddings API](https://platform.openai.com/docs/guides/embeddings/what-are-embeddings).
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
```python
|
||||||
|
import openai
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Configuring the environment variable OPENAI_API_KEY
|
||||||
|
if "OPENAI_API_KEY" not in os.environ:
|
||||||
|
# OR set the key here as a variable
|
||||||
|
openai.api_key = "sk-..."
|
||||||
|
|
||||||
|
# verify that the API key is working
|
||||||
|
assert len(openai.Model.list()["data"]) > 0
|
||||||
|
|
||||||
|
def embed_func(c):
|
||||||
|
rs = openai.Embedding.create(input=c, engine="text-embedding-ada-002")
|
||||||
|
return [record["embedding"] for record in rs["data"]]
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("vectordb");
|
||||||
|
|
||||||
|
// You need to provide an OpenAI API key
|
||||||
|
const apiKey = "sk-..."
|
||||||
|
// The embedding function will create embeddings for the 'text' column
|
||||||
|
const embedding = new lancedb.OpenAIEmbeddingFunction('text', apiKey)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Applying an embedding function to data
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
Using an embedding function, you can apply it to raw data
|
||||||
|
to generate embeddings for each record.
|
||||||
|
|
||||||
|
Say you have a pandas DataFrame with a `text` column that you want embedded,
|
||||||
|
you can use the `with_embeddings` function to generate embeddings and add them to
|
||||||
|
an existing table.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pandas as pd
|
||||||
|
from lancedb.embeddings import with_embeddings
|
||||||
|
|
||||||
|
df = pd.DataFrame(
|
||||||
|
[
|
||||||
|
{"text": "pepperoni"},
|
||||||
|
{"text": "pineapple"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data = with_embeddings(embed_func, df)
|
||||||
|
|
||||||
|
# The output is used to create / append to a table
|
||||||
|
# db.create_table("my_table", data=data)
|
||||||
|
```
|
||||||
|
|
||||||
|
If your data is in a different column, you can specify the `column` kwarg to `with_embeddings`.
|
||||||
|
|
||||||
|
By default, LanceDB calls the function with batches of 1000 rows. This can be configured
|
||||||
|
using the `batch_size` parameter to `with_embeddings`.
|
||||||
|
|
||||||
|
LanceDB automatically wraps the function with retry and rate-limit logic to ensure the OpenAI
|
||||||
|
API call is reliable.
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
Using an embedding function, you can apply it to raw data
|
||||||
|
to generate embeddings for each record.
|
||||||
|
|
||||||
|
Simply pass the embedding function created above and LanceDB will use it to generate
|
||||||
|
embeddings for your data.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const db = await lancedb.connect("data/sample-lancedb");
|
||||||
|
const data = [
|
||||||
|
{ text: "pepperoni"},
|
||||||
|
{ text: "pineapple"}
|
||||||
|
]
|
||||||
|
|
||||||
|
const table = await db.createTable("vectors", data, embedding)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Querying using an embedding function
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
At query time, you **must** use the same embedding function you used to vectorize your data.
|
||||||
|
If you use a different embedding function, the embeddings will not reside in the same vector
|
||||||
|
space and the results will be nonsensical.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
```python
|
||||||
|
query = "What's the best pizza topping?"
|
||||||
|
query_vector = embed_func([query])[0]
|
||||||
|
results = (
|
||||||
|
tbl.search(query_vector)
|
||||||
|
.limit(10)
|
||||||
|
.to_pandas()
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
The above snippet returns a pandas DataFrame with the 10 closest vectors to the query.
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
```javascript
|
||||||
|
const results = await table
|
||||||
|
.search("What's the best pizza topping?")
|
||||||
|
.limit(10)
|
||||||
|
.execute()
|
||||||
|
```
|
||||||
|
|
||||||
|
The above snippet returns an array of records with the top 10 nearest neighbors to the query.
|
||||||
@@ -3,126 +3,61 @@ Representing multi-modal data as vector embeddings is becoming a standard practi
|
|||||||
For this purpose, LanceDB introduces an **embedding functions API**, that allow you simply set up once, during the configuration stage of your project. After this, the table remembers it, effectively making the embedding functions *disappear in the background* so you don't have to worry about manually passing callables, and instead, simply focus on the rest of your data engineering pipeline.
|
For this purpose, LanceDB introduces an **embedding functions API**, that allow you simply set up once, during the configuration stage of your project. After this, the table remembers it, effectively making the embedding functions *disappear in the background* so you don't have to worry about manually passing callables, and instead, simply focus on the rest of your data engineering pipeline.
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
Using the embedding function registry means that you don't have to explicitly generate the embeddings yourself.
|
Using the implicit embeddings management approach means that you can forget about the manually passing around embedding
|
||||||
However, if your embedding function changes, you'll have to re-configure your table with the new embedding function
|
functions in your code, as long as you don't intend to change it at a later time. If your embedding function changes,
|
||||||
and regenerate the embeddings. In the future, we plan to support the ability to change the embedding function via
|
you'll have to re-configure your table with the new embedding function and regenerate the embeddings.
|
||||||
table metadata and have LanceDB automatically take care of regenerating the embeddings.
|
|
||||||
|
|
||||||
|
|
||||||
## 1. Define the embedding function
|
## 1. Define the embedding function
|
||||||
|
We have some pre-defined embedding functions in the global registry, with more coming soon. Here's let's an implementation of CLIP as example.
|
||||||
|
```
|
||||||
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
clip = registry.get("open-clip").create()
|
||||||
|
|
||||||
=== "Python"
|
```
|
||||||
In the LanceDB python SDK, we define a global embedding function registry with
|
You can also define your own embedding function by implementing the `EmbeddingFunction` abstract base interface. It subclasses Pydantic Model which can be utilized to write complex schemas simply as we'll see next!
|
||||||
many different embedding models and even more coming soon.
|
|
||||||
Here's let's an implementation of CLIP as example.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from lancedb.embeddings import get_registry
|
|
||||||
|
|
||||||
registry = get_registry()
|
|
||||||
clip = registry.get("open-clip").create()
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also define your own embedding function by implementing the `EmbeddingFunction`
|
|
||||||
abstract base interface. It subclasses Pydantic Model which can be utilized to write complex schemas simply as we'll see next!
|
|
||||||
|
|
||||||
=== "JavaScript""
|
|
||||||
In the TypeScript SDK, the choices are more limited. For now, only the OpenAI
|
|
||||||
embedding function is available.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const lancedb = require("vectordb");
|
|
||||||
|
|
||||||
// You need to provide an OpenAI API key
|
|
||||||
const apiKey = "sk-..."
|
|
||||||
// The embedding function will create embeddings for the 'text' column
|
|
||||||
const embedding = new lancedb.OpenAIEmbeddingFunction('text', apiKey)
|
|
||||||
```
|
|
||||||
|
|
||||||
## 2. Define the data model or schema
|
## 2. Define the data model or schema
|
||||||
|
The embedding function defined above abstracts away all the details about the models and dimensions required to define the schema. You can simply set a field as **source** or **vector** column. Here's how:
|
||||||
|
|
||||||
=== "Python"
|
```python
|
||||||
The embedding function defined above abstracts away all the details about the models and dimensions required to define the schema. You can simply set a field as **source** or **vector** column. Here's how:
|
class Pets(LanceModel):
|
||||||
|
vector: Vector(clip.ndims) = clip.VectorField()
|
||||||
|
image_uri: str = clip.SourceField()
|
||||||
|
```
|
||||||
|
|
||||||
```python
|
`VectorField` tells LanceDB to use the clip embedding function to generate query embeddings for the `vector` column and `SourceField` ensures that when adding data, we automatically use the specified embedding function to encode `image_uri`.
|
||||||
class Pets(LanceModel):
|
|
||||||
vector: Vector(clip.ndims) = clip.VectorField()
|
|
||||||
image_uri: str = clip.SourceField()
|
|
||||||
```
|
|
||||||
|
|
||||||
`VectorField` tells LanceDB to use the clip embedding function to generate query embeddings for the `vector` column and `SourceField` ensures that when adding data, we automatically use the specified embedding function to encode `image_uri`.
|
## 3. Create LanceDB table
|
||||||
|
Now that we have chosen/defined our embedding function and the schema, we can create the table:
|
||||||
|
|
||||||
=== "JavaScript"
|
```python
|
||||||
|
db = lancedb.connect("~/lancedb")
|
||||||
|
table = db.create_table("pets", schema=Pets)
|
||||||
|
|
||||||
For the TypeScript SDK, a schema can be inferred from input data, or an explicit
|
```
|
||||||
Arrow schema can be provided.
|
|
||||||
|
|
||||||
## 3. Create table and add data
|
That's it! We've provided all the information needed to embed the source and query inputs. We can now forget about the model and dimension details and start to build our VectorDB pipeline.
|
||||||
|
|
||||||
Now that we have chosen/defined our embedding function and the schema,
|
## 4. Ingest lots of data and query your table
|
||||||
we can create the table and ingest data without needing to explicitly generate
|
Any new or incoming data can just be added and it'll be vectorized automatically.
|
||||||
the embeddings at all:
|
|
||||||
|
|
||||||
=== "Python"
|
```python
|
||||||
```python
|
table.add([{"image_uri": u} for u in uris])
|
||||||
db = lancedb.connect("~/lancedb")
|
```
|
||||||
table = db.create_table("pets", schema=Pets)
|
|
||||||
|
|
||||||
table.add([{"image_uri": u} for u in uris])
|
Our OpenCLIP query embedding function supports querying via both text and images:
|
||||||
```
|
|
||||||
|
|
||||||
=== "JavaScript"
|
```python
|
||||||
|
result = table.search("dog")
|
||||||
|
```
|
||||||
|
|
||||||
```javascript
|
Let's query an image:
|
||||||
const db = await lancedb.connect("data/sample-lancedb");
|
|
||||||
const data = [
|
|
||||||
{ text: "pepperoni"},
|
|
||||||
{ text: "pineapple"}
|
|
||||||
]
|
|
||||||
|
|
||||||
const table = await db.createTable("vectors", data, embedding)
|
```python
|
||||||
```
|
p = Path("path/to/images/samoyed_100.jpg")
|
||||||
|
query_image = Image.open(p)
|
||||||
## 4. Querying your table
|
table.search(query_image)
|
||||||
Not only can you forget about the embeddings during ingestion, you also don't
|
```
|
||||||
need to worry about it when you query the table:
|
|
||||||
|
|
||||||
=== "Python"
|
|
||||||
|
|
||||||
Our OpenCLIP query embedding function supports querying via both text and images:
|
|
||||||
|
|
||||||
```python
|
|
||||||
results = (
|
|
||||||
table.search("dog")
|
|
||||||
.limit(10)
|
|
||||||
.to_pandas()
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
Or we can search using an image:
|
|
||||||
|
|
||||||
```python
|
|
||||||
p = Path("path/to/images/samoyed_100.jpg")
|
|
||||||
query_image = Image.open(p)
|
|
||||||
results = (
|
|
||||||
table.search(query_image)
|
|
||||||
.limit(10)
|
|
||||||
.to_pandas()
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
Both of the above snippet returns a pandas DataFrame with the 10 closest vectors to the query.
|
|
||||||
|
|
||||||
=== "JavaScript"
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const results = await table
|
|
||||||
.search("What's the best pizza topping?")
|
|
||||||
.limit(10)
|
|
||||||
.execute()
|
|
||||||
```
|
|
||||||
|
|
||||||
The above snippet returns an array of records with the top 10 nearest neighbors to the query.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -165,5 +100,4 @@ rs[2].image
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Now that you have the basic idea about LanceDB embedding functions and the embedding function registry,
|
Now that you have the basic idea about implicit management via embedding functions, let's dive deeper into a [custom API](./api.md) that you can use to implement your own embedding functions.
|
||||||
let's dive deeper into defining your own [custom functions](./custom_embedding_function.md).
|
|
||||||
@@ -1,14 +1,8 @@
|
|||||||
Due to the nature of vector embeddings, they can be used to represent any kind of data, from text to images to audio.
|
Due to the nature of vector embeddings, they can be used to represent any kind of data, from text to images to audio. This makes them a very powerful tool for machine learning practitioners. However, there's no one-size-fits-all solution for generating embeddings - there are many different libraries and APIs (both commercial and open source) that can be used to generate embeddings from structured/unstructured data.
|
||||||
This makes them a very powerful tool for machine learning practitioners.
|
|
||||||
However, there's no one-size-fits-all solution for generating embeddings - there are many different libraries and APIs
|
|
||||||
(both commercial and open source) that can be used to generate embeddings from structured/unstructured data.
|
|
||||||
|
|
||||||
LanceDB supports 3 methods of working with embeddings.
|
LanceDB supports 2 methods of vectorizing your raw data into embeddings.
|
||||||
|
|
||||||
1. You can manually generate embeddings for the data and queries. This is done outside of LanceDB.
|
1. **Explicit**: By manually calling LanceDB's `with_embedding` function to vectorize your data via an `embed_func` of your choice
|
||||||
2. You can use the built-in [embedding functions](./embedding_functions.md) to embed the data and queries in the background.
|
2. **Implicit**: Allow LanceDB to embed the data and queries in the background as they come in, by using the table's `EmbeddingRegistry` information
|
||||||
3. For python users, you can define your own [custom embedding function](./custom_embedding_function.md)
|
|
||||||
that extends the default embedding functions.
|
|
||||||
|
|
||||||
For python users, there is also a legacy [with_embeddings API](./legacy.md).
|
See the [explicit](embedding_explicit.md) and [implicit](embedding_functions.md) embedding sections for more details.
|
||||||
It is retained for compatibility and will be removed in a future version.
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
The legacy `with_embeddings` API is for Python only and is deprecated.
|
|
||||||
|
|
||||||
### Hugging Face
|
|
||||||
|
|
||||||
The most popular open source option is to use the [sentence-transformers](https://www.sbert.net/)
|
|
||||||
library, which can be installed via pip.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pip install sentence-transformers
|
|
||||||
```
|
|
||||||
|
|
||||||
The example below shows how to use the `paraphrase-albert-small-v2` model to generate embeddings
|
|
||||||
for a given document.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from sentence_transformers import SentenceTransformer
|
|
||||||
|
|
||||||
name="paraphrase-albert-small-v2"
|
|
||||||
model = SentenceTransformer(name)
|
|
||||||
|
|
||||||
# used for both training and querying
|
|
||||||
def embed_func(batch):
|
|
||||||
return [model.encode(sentence) for sentence in batch]
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### OpenAI
|
|
||||||
|
|
||||||
Another popular alternative is to use an external API like OpenAI's [embeddings API](https://platform.openai.com/docs/guides/embeddings/what-are-embeddings).
|
|
||||||
|
|
||||||
```python
|
|
||||||
import openai
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Configuring the environment variable OPENAI_API_KEY
|
|
||||||
if "OPENAI_API_KEY" not in os.environ:
|
|
||||||
# OR set the key here as a variable
|
|
||||||
openai.api_key = "sk-..."
|
|
||||||
|
|
||||||
client = openai.OpenAI()
|
|
||||||
|
|
||||||
def embed_func(c):
|
|
||||||
rs = client.embeddings.create(input=c, model="text-embedding-ada-002")
|
|
||||||
return [record.embedding for record in rs["data"]]
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Applying an embedding function to data
|
|
||||||
|
|
||||||
Using an embedding function, you can apply it to raw data
|
|
||||||
to generate embeddings for each record.
|
|
||||||
|
|
||||||
Say you have a pandas DataFrame with a `text` column that you want embedded,
|
|
||||||
you can use the `with_embeddings` function to generate embeddings and add them to
|
|
||||||
an existing table.
|
|
||||||
|
|
||||||
```python
|
|
||||||
import pandas as pd
|
|
||||||
from lancedb.embeddings import with_embeddings
|
|
||||||
|
|
||||||
df = pd.DataFrame(
|
|
||||||
[
|
|
||||||
{"text": "pepperoni"},
|
|
||||||
{"text": "pineapple"}
|
|
||||||
]
|
|
||||||
)
|
|
||||||
data = with_embeddings(embed_func, df)
|
|
||||||
|
|
||||||
# The output is used to create / append to a table
|
|
||||||
tbl = db.create_table("my_table", data=data)
|
|
||||||
```
|
|
||||||
|
|
||||||
If your data is in a different column, you can specify the `column` kwarg to `with_embeddings`.
|
|
||||||
|
|
||||||
By default, LanceDB calls the function with batches of 1000 rows. This can be configured
|
|
||||||
using the `batch_size` parameter to `with_embeddings`.
|
|
||||||
|
|
||||||
LanceDB automatically wraps the function with retry and rate-limit logic to ensure the OpenAI
|
|
||||||
API call is reliable.
|
|
||||||
|
|
||||||
## Querying using an embedding function
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
At query time, you **must** use the same embedding function you used to vectorize your data.
|
|
||||||
If you use a different embedding function, the embeddings will not reside in the same vector
|
|
||||||
space and the results will be nonsensical.
|
|
||||||
|
|
||||||
=== "Python"
|
|
||||||
```python
|
|
||||||
query = "What's the best pizza topping?"
|
|
||||||
query_vector = embed_func([query])[0]
|
|
||||||
results = (
|
|
||||||
tbl.search(query_vector)
|
|
||||||
.limit(10)
|
|
||||||
.to_pandas()
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
The above snippet returns a pandas DataFrame with the 10 closest vectors to the query.
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import pickle
|
import pickle
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|||||||
@@ -636,70 +636,6 @@ The `values` parameter is used to provide the new values for the columns as lite
|
|||||||
|
|
||||||
When rows are updated, they are moved out of the index. The row will still show up in ANN queries, but the query will not be as fast as it would be if the row was in the index. If you update a large proportion of rows, consider rebuilding the index afterwards.
|
When rows are updated, they are moved out of the index. The row will still show up in ANN queries, but the query will not be as fast as it would be if the row was in the index. If you update a large proportion of rows, consider rebuilding the index afterwards.
|
||||||
|
|
||||||
## Consistency
|
|
||||||
|
|
||||||
In LanceDB OSS, users can set the `read_consistency_interval` parameter on connections to achieve different levels of read consistency. This parameter determines how frequently the database synchronizes with the underlying storage system to check for updates made by other processes. If another process updates a table, the database will not see the changes until the next synchronization.
|
|
||||||
|
|
||||||
There are three possible settings for `read_consistency_interval`:
|
|
||||||
|
|
||||||
1. **Unset (default)**: The database does not check for updates to tables made by other processes. This provides the best query performance, but means that clients may not see the most up-to-date data. This setting is suitable for applications where the data does not change during the lifetime of the table reference.
|
|
||||||
2. **Zero seconds (Strong consistency)**: The database checks for updates on every read. This provides the strongest consistency guarantees, ensuring that all clients see the latest committed data. However, it has the most overhead. This setting is suitable when consistency matters more than having high QPS.
|
|
||||||
3. **Custom interval (Eventual consistency)**: The database checks for updates at a custom interval, such as every 5 seconds. This provides eventual consistency, allowing for some lag between write and read operations. Performance wise, this is a middle ground between strong consistency and no consistency check. This setting is suitable for applications where immediate consistency is not critical, but clients should see updated data eventually.
|
|
||||||
|
|
||||||
!!! tip "Consistency in LanceDB Cloud"
|
|
||||||
|
|
||||||
This is only tune-able in LanceDB OSS. In LanceDB Cloud, readers are always eventually consistent.
|
|
||||||
|
|
||||||
=== "Python"
|
|
||||||
|
|
||||||
To set strong consistency, use `timedelta(0)`:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from datetime import timedelta
|
|
||||||
db = lancedb.connect("./.lancedb",. read_consistency_interval=timedelta(0))
|
|
||||||
table = db.open_table("my_table")
|
|
||||||
```
|
|
||||||
|
|
||||||
For eventual consistency, use a custom `timedelta`:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from datetime import timedelta
|
|
||||||
db = lancedb.connect("./.lancedb", read_consistency_interval=timedelta(seconds=5))
|
|
||||||
table = db.open_table("my_table")
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, a `Table` will never check for updates from other writers. To manually check for updates you can use `checkout_latest`:
|
|
||||||
|
|
||||||
```python
|
|
||||||
db = lancedb.connect("./.lancedb")
|
|
||||||
table = db.open_table("my_table")
|
|
||||||
|
|
||||||
# (Other writes happen to my_table from another process)
|
|
||||||
|
|
||||||
# Check for updates
|
|
||||||
table.checkout_latest()
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "JavaScript/Typescript"
|
|
||||||
|
|
||||||
To set strong consistency, use `0`:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const db = await lancedb.connect({ uri: "./.lancedb", readConsistencyInterval: 0 });
|
|
||||||
const table = await db.openTable("my_table");
|
|
||||||
```
|
|
||||||
|
|
||||||
For eventual consistency, specify the update interval as seconds:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const db = await lancedb.connect({ uri: "./.lancedb", readConsistencyInterval: 5 });
|
|
||||||
const table = await db.openTable("my_table");
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- Node doesn't yet support the version time travel: https://github.com/lancedb/lancedb/issues/1007
|
|
||||||
Once it does, we can show manual consistency check for Node as well.
|
|
||||||
-->
|
|
||||||
|
|
||||||
## What's next?
|
## What's next?
|
||||||
|
|
||||||
Learn the best practices on creating an ANN index and getting the most out of it.
|
Learn the best practices on creating an ANN index and getting the most out of it.
|
||||||
@@ -290,7 +290,7 @@
|
|||||||
"from lancedb.pydantic import LanceModel, Vector\n",
|
"from lancedb.pydantic import LanceModel, Vector\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class Pets(LanceModel):\n",
|
"class Pets(LanceModel):\n",
|
||||||
" vector: Vector(clip.ndims()) = clip.VectorField()\n",
|
" vector: Vector(clip.ndims) = clip.VectorField()\n",
|
||||||
" image_uri: str = clip.SourceField()\n",
|
" image_uri: str = clip.SourceField()\n",
|
||||||
"\n",
|
"\n",
|
||||||
" @property\n",
|
" @property\n",
|
||||||
@@ -360,7 +360,7 @@
|
|||||||
" table = db.create_table(\"pets\", schema=Pets)\n",
|
" table = db.create_table(\"pets\", schema=Pets)\n",
|
||||||
" # use a sampling of 1000 images\n",
|
" # use a sampling of 1000 images\n",
|
||||||
" p = Path(\"~/Downloads/images\").expanduser()\n",
|
" p = Path(\"~/Downloads/images\").expanduser()\n",
|
||||||
" uris = [str(f) for f in p.glob(\"*.jpg\")]\n",
|
" uris = [str(f) for f in p.iterdir()]\n",
|
||||||
" uris = sample(uris, 1000)\n",
|
" uris = sample(uris, 1000)\n",
|
||||||
" table.add(pd.DataFrame({\"image_uri\": uris}))"
|
" table.add(pd.DataFrame({\"image_uri\": uris}))"
|
||||||
]
|
]
|
||||||
@@ -543,7 +543,7 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"from PIL import Image\n",
|
"from PIL import Image\n",
|
||||||
"p = Path(\"~/Downloads/images/samoyed_100.jpg\").expanduser()\n",
|
"p = Path(\"/Users/changshe/Downloads/images/samoyed_100.jpg\")\n",
|
||||||
"query_image = Image.open(p)\n",
|
"query_image = Image.open(p)\n",
|
||||||
"query_image"
|
"query_image"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ from multiprocessing import Pool
|
|||||||
import lance
|
import lance
|
||||||
import pyarrow as pa
|
import pyarrow as pa
|
||||||
from datasets import load_dataset
|
from datasets import load_dataset
|
||||||
|
from PIL import Image
|
||||||
from transformers import CLIPModel, CLIPProcessor, CLIPTokenizerFast
|
from transformers import CLIPModel, CLIPProcessor, CLIPTokenizerFast
|
||||||
|
|
||||||
|
import lancedb
|
||||||
|
|
||||||
MODEL_ID = "openai/clip-vit-base-patch32"
|
MODEL_ID = "openai/clip-vit-base-patch32"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
# DuckDB
|
# DuckDB
|
||||||
|
|
||||||
In Python, LanceDB tables can also be queried with [DuckDB](https://duckdb.org/), an in-process SQL OLAP database. This means you can write complex SQL queries to analyze your data in LanceDB.
|
LanceDB is very well-integrated with [DuckDB](https://duckdb.org/), an in-process SQL OLAP database. This integration is done via [Arrow](https://duckdb.org/docs/guides/python/sql_on_arrow) .
|
||||||
|
|
||||||
This integration is done via [Apache Arrow](https://duckdb.org/docs/guides/python/sql_on_arrow), which provides zero-copy data sharing between LanceDB and DuckDB. DuckDB is capable of passing down column selections and basic filters to LanceDB, reducing the amount of data that needs to be scanned to perform your query. Finally, the integration allows streaming data from LanceDB tables, allowing you to aggregate tables that won't fit into memory. All of this uses the same mechanism described in DuckDB's blog post *[DuckDB quacks Arrow](https://duckdb.org/2021/12/03/duck-arrow.html)*.
|
|
||||||
|
|
||||||
|
|
||||||
We can demonstrate this by first installing `duckdb` and `lancedb`.
|
We can demonstrate this by first installing `duckdb` and `lancedb`.
|
||||||
|
|
||||||
@@ -22,15 +19,14 @@ data = [
|
|||||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}
|
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}
|
||||||
]
|
]
|
||||||
table = db.create_table("pd_table", data=data)
|
table = db.create_table("pd_table", data=data)
|
||||||
|
arrow_table = table.to_arrow()
|
||||||
```
|
```
|
||||||
|
|
||||||
To query the table, first call `to_lance` to convert the table to a "dataset", which is an object that can be queried by DuckDB. Then all you need to do is reference that dataset by the same name in your SQL query.
|
DuckDB can directly query the `pyarrow.Table` object:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import duckdb
|
import duckdb
|
||||||
|
|
||||||
arrow_table = table.to_lance()
|
|
||||||
|
|
||||||
duckdb.query("SELECT * FROM arrow_table")
|
duckdb.query("SELECT * FROM arrow_table")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
44
node/package-lock.json
generated
44
node/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "vectordb",
|
"name": "vectordb",
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "vectordb",
|
"name": "vectordb",
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64",
|
"x64",
|
||||||
"arm64"
|
"arm64"
|
||||||
@@ -53,11 +53,11 @@
|
|||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@lancedb/vectordb-darwin-arm64": "0.4.11",
|
"@lancedb/vectordb-darwin-arm64": "0.4.10",
|
||||||
"@lancedb/vectordb-darwin-x64": "0.4.11",
|
"@lancedb/vectordb-darwin-x64": "0.4.10",
|
||||||
"@lancedb/vectordb-linux-arm64-gnu": "0.4.11",
|
"@lancedb/vectordb-linux-arm64-gnu": "0.4.10",
|
||||||
"@lancedb/vectordb-linux-x64-gnu": "0.4.11",
|
"@lancedb/vectordb-linux-x64-gnu": "0.4.10",
|
||||||
"@lancedb/vectordb-win32-x64-msvc": "0.4.11"
|
"@lancedb/vectordb-win32-x64-msvc": "0.4.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@75lb/deep-merge": {
|
"node_modules/@75lb/deep-merge": {
|
||||||
@@ -329,9 +329,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lancedb/vectordb-darwin-arm64": {
|
"node_modules/@lancedb/vectordb-darwin-arm64": {
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.10.tgz",
|
||||||
"integrity": "sha512-JDOKmFnuJPFkA7ZmrzBJolROwSjWr7yMvAbi40uLBc25YbbVezodd30u2EFtIwWwtk1GqNYRZ49FZOElKYeC/Q==",
|
"integrity": "sha512-y/uHOGb0g15pvqv5tdTyZ6oN+0QVpBmZDzKFWW6pPbuSZjB2uPqcs+ti0RB+AUdmS21kavVQqaNsw/HLKEGrHA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
@@ -341,9 +341,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@lancedb/vectordb-darwin-x64": {
|
"node_modules/@lancedb/vectordb-darwin-x64": {
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-x64/-/vectordb-darwin-x64-0.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-x64/-/vectordb-darwin-x64-0.4.10.tgz",
|
||||||
"integrity": "sha512-iy6r+8tp2v1EFgJV52jusXtxgO6NY6SkpOdX41xPqN2mQWMkfUAR9Xtks1mgknjPOIKH4MRc8ZS0jcW/UWmilQ==",
|
"integrity": "sha512-XbfR58OkQpAe0xMSTrwJh9ZjGSzG9EZ7zwO6HfYem8PxcLYAcC6eWRWoSG/T0uObyrPTcYYyvHsp0eNQWYBFAQ==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
@@ -353,9 +353,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@lancedb/vectordb-linux-arm64-gnu": {
|
"node_modules/@lancedb/vectordb-linux-arm64-gnu": {
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-arm64-gnu/-/vectordb-linux-arm64-gnu-0.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-arm64-gnu/-/vectordb-linux-arm64-gnu-0.4.10.tgz",
|
||||||
"integrity": "sha512-5K6IVcTMuH0SZBjlqB5Gg39WC889FpTwIWKufxzQMMXrzxo5J3lKUHVoR28RRlNhDF2d9kZXBEyCpIfDFsV9iQ==",
|
"integrity": "sha512-x40WKH9b+KxorRmKr9G7fv8p5mMj8QJQvRMA0v6v+nbZHr2FLlAZV+9mvhHOnm4AGIkPP5335cUgv6Qz6hgwkQ==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
@@ -365,9 +365,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@lancedb/vectordb-linux-x64-gnu": {
|
"node_modules/@lancedb/vectordb-linux-x64-gnu": {
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.4.10.tgz",
|
||||||
"integrity": "sha512-hF9ZChsdqKqqnivOzd9mE7lC3PmhZadXtwThi2RrsPiOLoEaGDfmr6Ni3amVQnB3bR8YEJtTxdQxe0NC4uW/8g==",
|
"integrity": "sha512-CTGPpuzlqq2nVjUxI9gAJOT1oBANIovtIaFsOmBSnEAHgX7oeAxKy2b6L/kJzsgqSzvR5vfLwYcWFrr6ZmBxSA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
@@ -377,9 +377,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@lancedb/vectordb-win32-x64-msvc": {
|
"node_modules/@lancedb/vectordb-win32-x64-msvc": {
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-win32-x64-msvc/-/vectordb-win32-x64-msvc-0.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-win32-x64-msvc/-/vectordb-win32-x64-msvc-0.4.10.tgz",
|
||||||
"integrity": "sha512-0+9ut1ccKoqIyGxsVixwx3771Z+DXpl5WfSmOeA8kf3v3jlOg2H+0YUahiXLDid2ju+yeLPrAUYm7A1gKHVhew==",
|
"integrity": "sha512-Fd7r74coZyrKzkfXg4WthqOL+uKyJyPTia6imcrMNqKOlTGdKmHf02Qi2QxWZrFaabkRYo4Tpn5FeRJ3yYX8CA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "vectordb",
|
"name": "vectordb",
|
||||||
"version": "0.4.11",
|
"version": "0.4.10",
|
||||||
"description": " Serverless, low-latency vector database for AI applications",
|
"description": " Serverless, low-latency vector database for AI applications",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tsc": "tsc -b",
|
"tsc": "tsc -b",
|
||||||
"build": "npm run tsc && cargo-cp-artifact --artifact cdylib lancedb-node index.node -- cargo build --message-format=json",
|
"build": "npm run tsc && cargo-cp-artifact --artifact cdylib vectordb-node index.node -- cargo build --message-format=json",
|
||||||
"build-release": "npm run build -- --release",
|
"build-release": "npm run build -- --release",
|
||||||
"test": "npm run tsc && mocha -recursive dist/test",
|
"test": "npm run tsc && mocha -recursive dist/test",
|
||||||
"integration-test": "npm run tsc && mocha -recursive dist/integration_test",
|
"integration-test": "npm run tsc && mocha -recursive dist/integration_test",
|
||||||
@@ -61,12 +61,10 @@
|
|||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@neon-rs/load": "^0.0.74",
|
|
||||||
"axios": "^1.4.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@apache-arrow/ts": "^14.0.2",
|
"@apache-arrow/ts": "^14.0.2",
|
||||||
"apache-arrow": "^14.0.2"
|
"@neon-rs/load": "^0.0.74",
|
||||||
|
"apache-arrow": "^14.0.2",
|
||||||
|
"axios": "^1.4.0"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"darwin",
|
"darwin",
|
||||||
@@ -87,10 +85,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@lancedb/vectordb-darwin-arm64": "0.4.11",
|
"@lancedb/vectordb-darwin-arm64": "0.4.10",
|
||||||
"@lancedb/vectordb-darwin-x64": "0.4.11",
|
"@lancedb/vectordb-darwin-x64": "0.4.10",
|
||||||
"@lancedb/vectordb-linux-arm64-gnu": "0.4.11",
|
"@lancedb/vectordb-linux-arm64-gnu": "0.4.10",
|
||||||
"@lancedb/vectordb-linux-x64-gnu": "0.4.11",
|
"@lancedb/vectordb-linux-x64-gnu": "0.4.10",
|
||||||
"@lancedb/vectordb-win32-x64-msvc": "0.4.11"
|
"@lancedb/vectordb-win32-x64-msvc": "0.4.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,7 @@ const {
|
|||||||
tableCompactFiles,
|
tableCompactFiles,
|
||||||
tableListIndices,
|
tableListIndices,
|
||||||
tableIndexStats,
|
tableIndexStats,
|
||||||
tableSchema,
|
tableSchema
|
||||||
tableAddColumns,
|
|
||||||
tableAlterColumns,
|
|
||||||
tableDropColumns
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
} = require('../native.js')
|
} = require('../native.js')
|
||||||
|
|
||||||
@@ -99,19 +96,6 @@ export interface ConnectionOptions {
|
|||||||
* This is useful for local testing.
|
* This is useful for local testing.
|
||||||
*/
|
*/
|
||||||
hostOverride?: string
|
hostOverride?: string
|
||||||
|
|
||||||
/**
|
|
||||||
* (For LanceDB OSS only): The interval, in seconds, at which to check for
|
|
||||||
* updates to the table from other processes. If None, then consistency is not
|
|
||||||
* checked. For performance reasons, this is the default. For strong
|
|
||||||
* consistency, set this to zero seconds. Then every read will check for
|
|
||||||
* updates from other processes. As a compromise, you can set this to a
|
|
||||||
* non-zero value for eventual consistency. If more than that interval
|
|
||||||
* has passed since the last check, then the table will be checked for updates.
|
|
||||||
* Note: this consistency only applies to read operations. Write operations are
|
|
||||||
* always consistent.
|
|
||||||
*/
|
|
||||||
readConsistencyInterval?: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAwsArgs (opts: ConnectionOptions): any[] {
|
function getAwsArgs (opts: ConnectionOptions): any[] {
|
||||||
@@ -197,8 +181,7 @@ export async function connect (
|
|||||||
opts.awsCredentials?.accessKeyId,
|
opts.awsCredentials?.accessKeyId,
|
||||||
opts.awsCredentials?.secretKey,
|
opts.awsCredentials?.secretKey,
|
||||||
opts.awsCredentials?.sessionToken,
|
opts.awsCredentials?.sessionToken,
|
||||||
opts.awsRegion,
|
opts.awsRegion
|
||||||
opts.readConsistencyInterval
|
|
||||||
)
|
)
|
||||||
return new LocalConnection(db, opts)
|
return new LocalConnection(db, opts)
|
||||||
}
|
}
|
||||||
@@ -503,59 +486,6 @@ export interface Table<T = number[]> {
|
|||||||
filter(value: string): Query<T>
|
filter(value: string): Query<T>
|
||||||
|
|
||||||
schema: Promise<Schema>
|
schema: Promise<Schema>
|
||||||
|
|
||||||
// TODO: Support BatchUDF
|
|
||||||
/**
|
|
||||||
* Add new columns with defined values.
|
|
||||||
*
|
|
||||||
* @param newColumnTransforms pairs of column names and the SQL expression to use
|
|
||||||
* to calculate the value of the new column. These
|
|
||||||
* expressions will be evaluated for each row in the
|
|
||||||
* table, and can reference existing columns in the table.
|
|
||||||
*/
|
|
||||||
addColumns(newColumnTransforms: Array<{ name: string, valueSql: string }>): Promise<void>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alter the name or nullability of columns.
|
|
||||||
*
|
|
||||||
* @param columnAlterations One or more alterations to apply to columns.
|
|
||||||
*/
|
|
||||||
alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop one or more columns from the dataset
|
|
||||||
*
|
|
||||||
* This is a metadata-only operation and does not remove the data from the
|
|
||||||
* underlying storage. In order to remove the data, you must subsequently
|
|
||||||
* call ``compact_files`` to rewrite the data without the removed columns and
|
|
||||||
* then call ``cleanup_files`` to remove the old files.
|
|
||||||
*
|
|
||||||
* @param columnNames The names of the columns to drop. These can be nested
|
|
||||||
* column references (e.g. "a.b.c") or top-level column
|
|
||||||
* names (e.g. "a").
|
|
||||||
*/
|
|
||||||
dropColumns(columnNames: string[]): Promise<void>
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A definition of a column alteration. The alteration changes the column at
|
|
||||||
* `path` to have the new name `name`, to be nullable if `nullable` is true,
|
|
||||||
* and to have the data type `data_type`. At least one of `rename` or `nullable`
|
|
||||||
* must be provided.
|
|
||||||
*/
|
|
||||||
export interface ColumnAlteration {
|
|
||||||
/**
|
|
||||||
* The path to the column to alter. This is a dot-separated path to the column.
|
|
||||||
* If it is a top-level column then it is just the name of the column. If it is
|
|
||||||
* a nested column then it is the path to the column, e.g. "a.b.c" for a column
|
|
||||||
* `c` nested inside a column `b` nested inside a column `a`.
|
|
||||||
*/
|
|
||||||
path: string
|
|
||||||
rename?: string
|
|
||||||
/**
|
|
||||||
* Set the new nullability. Note that a nullable column cannot be made non-nullable.
|
|
||||||
*/
|
|
||||||
nullable?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateArgs {
|
export interface UpdateArgs {
|
||||||
@@ -1084,18 +1014,6 @@ export class LocalTable<T = number[]> implements Table<T> {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addColumns (newColumnTransforms: Array<{ name: string, valueSql: string }>): Promise<void> {
|
|
||||||
return tableAddColumns.call(this._tbl, newColumnTransforms)
|
|
||||||
}
|
|
||||||
|
|
||||||
async alterColumns (columnAlterations: ColumnAlteration[]): Promise<void> {
|
|
||||||
return tableAlterColumns.call(this._tbl, columnAlterations)
|
|
||||||
}
|
|
||||||
|
|
||||||
async dropColumns (columnNames: string[]): Promise<void> {
|
|
||||||
return tableDropColumns.call(this._tbl, columnNames)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CleanupStats {
|
export interface CleanupStats {
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ import {
|
|||||||
type UpdateArgs,
|
type UpdateArgs,
|
||||||
type UpdateSqlArgs,
|
type UpdateSqlArgs,
|
||||||
makeArrowTable,
|
makeArrowTable,
|
||||||
type MergeInsertArgs,
|
type MergeInsertArgs
|
||||||
type ColumnAlteration
|
|
||||||
} from '../index'
|
} from '../index'
|
||||||
import { Query } from '../query'
|
import { Query } from '../query'
|
||||||
|
|
||||||
@@ -475,16 +474,4 @@ export class RemoteTable<T = number[]> implements Table<T> {
|
|||||||
numUnindexedRows: results.data.num_unindexed_rows
|
numUnindexedRows: results.data.num_unindexed_rows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addColumns (newColumnTransforms: Array<{ name: string, valueSql: string }>): Promise<void> {
|
|
||||||
throw new Error('Add columns is not yet supported in LanceDB Cloud.')
|
|
||||||
}
|
|
||||||
|
|
||||||
async alterColumns (columnAlterations: ColumnAlteration[]): Promise<void> {
|
|
||||||
throw new Error('Alter columns is not yet supported in LanceDB Cloud.')
|
|
||||||
}
|
|
||||||
|
|
||||||
async dropColumns (columnNames: string[]): Promise<void> {
|
|
||||||
throw new Error('Drop columns is not yet supported in LanceDB Cloud.')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,8 @@ import {
|
|||||||
Utf8,
|
Utf8,
|
||||||
Table as ArrowTable,
|
Table as ArrowTable,
|
||||||
vectorFromArray,
|
vectorFromArray,
|
||||||
Float64,
|
|
||||||
Float32,
|
Float32,
|
||||||
Float16,
|
Float16
|
||||||
Int64
|
|
||||||
} from 'apache-arrow'
|
} from 'apache-arrow'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
@@ -198,7 +196,7 @@ describe('LanceDB client', function () {
|
|||||||
const table = await con.openTable('vectors')
|
const table = await con.openTable('vectors')
|
||||||
const results = await table
|
const results = await table
|
||||||
.search([0.1, 0.1])
|
.search([0.1, 0.1])
|
||||||
.select(['is_active', 'vector'])
|
.select(['is_active'])
|
||||||
.execute()
|
.execute()
|
||||||
assert.equal(results.length, 2)
|
assert.equal(results.length, 2)
|
||||||
// vector and _distance are always returned
|
// vector and _distance are always returned
|
||||||
@@ -1059,63 +1057,3 @@ describe('Compact and cleanup', function () {
|
|||||||
assert.equal(await table.countRows(), 3)
|
assert.equal(await table.countRows(), 3)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('schema evolution', function () {
|
|
||||||
// Create a new sample table
|
|
||||||
it('can add a new column to the schema', async function () {
|
|
||||||
const dir = await track().mkdir('lancejs')
|
|
||||||
const con = await lancedb.connect(dir)
|
|
||||||
const table = await con.createTable('vectors', [
|
|
||||||
{ id: 1n, vector: [0.1, 0.2] }
|
|
||||||
])
|
|
||||||
|
|
||||||
await table.addColumns([{ name: 'price', valueSql: 'cast(10.0 as float)' }])
|
|
||||||
|
|
||||||
const expectedSchema = new Schema([
|
|
||||||
new Field('id', new Int64()),
|
|
||||||
new Field('vector', new FixedSizeList(2, new Field('item', new Float32(), true))),
|
|
||||||
new Field('price', new Float32())
|
|
||||||
])
|
|
||||||
expect(await table.schema).to.deep.equal(expectedSchema)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can alter the columns in the schema', async function () {
|
|
||||||
const dir = await track().mkdir('lancejs')
|
|
||||||
const con = await lancedb.connect(dir)
|
|
||||||
const schema = new Schema([
|
|
||||||
new Field('id', new Int64(), false),
|
|
||||||
new Field('vector', new FixedSizeList(2, new Field('item', new Float32(), true))),
|
|
||||||
new Field('price', new Float64(), false)
|
|
||||||
])
|
|
||||||
const table = await con.createTable('vectors', [
|
|
||||||
{ id: 1n, vector: [0.1, 0.2], price: 10.0 }
|
|
||||||
])
|
|
||||||
expect(await table.schema).to.deep.equal(schema)
|
|
||||||
|
|
||||||
await table.alterColumns([
|
|
||||||
{ path: 'id', rename: 'new_id' },
|
|
||||||
{ path: 'price', nullable: true }
|
|
||||||
])
|
|
||||||
|
|
||||||
const expectedSchema = new Schema([
|
|
||||||
new Field('new_id', new Int64(), false),
|
|
||||||
new Field('vector', new FixedSizeList(2, new Field('item', new Float32(), true))),
|
|
||||||
new Field('price', new Float64(), true)
|
|
||||||
])
|
|
||||||
expect(await table.schema).to.deep.equal(expectedSchema)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can drop a column from the schema', async function () {
|
|
||||||
const dir = await track().mkdir('lancejs')
|
|
||||||
const con = await lancedb.connect(dir)
|
|
||||||
const table = await con.createTable('vectors', [
|
|
||||||
{ id: 1n, vector: [0.1, 0.2] }
|
|
||||||
])
|
|
||||||
await table.dropColumns(['vector'])
|
|
||||||
|
|
||||||
const expectedSchema = new Schema([
|
|
||||||
new Field('id', new Int64(), false)
|
|
||||||
])
|
|
||||||
expect(await table.schema).to.deep.equal(expectedSchema)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ module.exports = {
|
|||||||
"@typescript-eslint/method-signature-style": "off",
|
"@typescript-eslint/method-signature-style": "off",
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
},
|
},
|
||||||
ignorePatterns: ["node_modules/", "dist/", "build/", "lancedb/native.*"],
|
ignorePatterns: ["node_modules/", "dist/", "build/", "vectordb/native.*"],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lancedb-nodejs"
|
name = "vectordb-nodejs"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
@@ -16,7 +16,7 @@ arrow-ipc.workspace = true
|
|||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
lance-linalg.workspace = true
|
lance-linalg.workspace = true
|
||||||
lance.workspace = true
|
lance.workspace = true
|
||||||
lancedb = { path = "../rust/lancedb" }
|
vectordb = { path = "../rust/vectordb" }
|
||||||
napi = { version = "2.15", default-features = false, features = [
|
napi = { version = "2.15", default-features = false, features = [
|
||||||
"napi7",
|
"napi7",
|
||||||
"async"
|
"async"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { makeArrowTable, toBuffer } from "../lancedb/arrow";
|
import { makeArrowTable, toBuffer } from "../vectordb/arrow";
|
||||||
import {
|
import {
|
||||||
Int64,
|
Int64,
|
||||||
Field,
|
Field,
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ test("open database", async () => {
|
|||||||
const tbl = await db.createTable("test", [{ id: 1 }, { id: 2 }]);
|
const tbl = await db.createTable("test", [{ id: 1 }, { id: 2 }]);
|
||||||
expect(await db.tableNames()).toStrictEqual(["test"]);
|
expect(await db.tableNames()).toStrictEqual(["test"]);
|
||||||
|
|
||||||
const schema = await tbl.schema();
|
const schema = tbl.schema;
|
||||||
expect(schema).toEqual(new Schema([new Field("id", new Float64(), true)]));
|
expect(schema).toEqual(new Schema([new Field("id", new Float64(), true)]));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import * as path from "path";
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
|
||||||
import { connect } from "../dist";
|
import { connect } from "../dist";
|
||||||
import { Schema, Field, Float32, Int32, FixedSizeList, Int64, Float64 } from "apache-arrow";
|
import { Schema, Field, Float32, Int32, FixedSizeList } from "apache-arrow";
|
||||||
import { makeArrowTable } from "../dist/arrow";
|
import { makeArrowTable } from "../dist/arrow";
|
||||||
|
|
||||||
describe("Test creating index", () => {
|
describe("Test creating index", () => {
|
||||||
@@ -181,102 +181,3 @@ describe("Test creating index", () => {
|
|||||||
// TODO: check index type.
|
// TODO: check index type.
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Read consistency interval", () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
beforeEach(() => {
|
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "read-consistency-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
// const intervals = [undefined, 0, 0.1];
|
|
||||||
const intervals = [0];
|
|
||||||
test.each(intervals)("read consistency interval %p", async (interval) => {
|
|
||||||
const db = await connect({ uri: tmpDir });
|
|
||||||
const table = await db.createTable("my_table", [{ id: 1 }]);
|
|
||||||
|
|
||||||
const db2 = await connect({ uri: tmpDir, readConsistencyInterval: interval });
|
|
||||||
const table2 = await db2.openTable("my_table");
|
|
||||||
expect(await table2.countRows()).toEqual(await table.countRows());
|
|
||||||
|
|
||||||
await table.add([{ id: 2 }]);
|
|
||||||
|
|
||||||
if (interval === undefined) {
|
|
||||||
expect(await table2.countRows()).toEqual(1n);
|
|
||||||
// TODO: once we implement time travel we can uncomment this part of the test.
|
|
||||||
// await table2.checkout_latest();
|
|
||||||
// expect(await table2.countRows()).toEqual(2);
|
|
||||||
} else if (interval === 0) {
|
|
||||||
expect(await table2.countRows()).toEqual(2n);
|
|
||||||
} else {
|
|
||||||
// interval == 0.1
|
|
||||||
expect(await table2.countRows()).toEqual(1n);
|
|
||||||
await new Promise(r => setTimeout(r, 100));
|
|
||||||
expect(await table2.countRows()).toEqual(2n);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('schema evolution', function () {
|
|
||||||
let tmpDir: string;
|
|
||||||
beforeEach(() => {
|
|
||||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "schema-evolution-"));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create a new sample table
|
|
||||||
it('can add a new column to the schema', async function () {
|
|
||||||
const con = await connect(tmpDir)
|
|
||||||
const table = await con.createTable('vectors', [
|
|
||||||
{ id: 1n, vector: [0.1, 0.2] }
|
|
||||||
])
|
|
||||||
|
|
||||||
await table.addColumns([{ name: 'price', valueSql: 'cast(10.0 as float)' }])
|
|
||||||
|
|
||||||
const expectedSchema = new Schema([
|
|
||||||
new Field('id', new Int64(), true),
|
|
||||||
new Field('vector', new FixedSizeList(2, new Field('item', new Float32(), true)), true),
|
|
||||||
new Field('price', new Float32(), false)
|
|
||||||
])
|
|
||||||
expect(await table.schema()).toEqual(expectedSchema)
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can alter the columns in the schema', async function () {
|
|
||||||
const con = await connect(tmpDir)
|
|
||||||
const schema = new Schema([
|
|
||||||
new Field('id', new Int64(), true),
|
|
||||||
new Field('vector', new FixedSizeList(2, new Field('item', new Float32(), true)), true),
|
|
||||||
new Field('price', new Float64(), false)
|
|
||||||
])
|
|
||||||
const table = await con.createTable('vectors', [
|
|
||||||
{ id: 1n, vector: [0.1, 0.2] }
|
|
||||||
])
|
|
||||||
// Can create a non-nullable column only through addColumns at the moment.
|
|
||||||
await table.addColumns([{ name: 'price', valueSql: 'cast(10.0 as double)' }])
|
|
||||||
expect(await table.schema()).toEqual(schema)
|
|
||||||
|
|
||||||
await table.alterColumns([
|
|
||||||
{ path: 'id', rename: 'new_id' },
|
|
||||||
{ path: 'price', nullable: true }
|
|
||||||
])
|
|
||||||
|
|
||||||
const expectedSchema = new Schema([
|
|
||||||
new Field('new_id', new Int64(), true),
|
|
||||||
new Field('vector', new FixedSizeList(2, new Field('item', new Float32(), true)), true),
|
|
||||||
new Field('price', new Float64(), true)
|
|
||||||
])
|
|
||||||
expect(await table.schema()).toEqual(expectedSchema)
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can drop a column from the schema', async function () {
|
|
||||||
const con = await connect(tmpDir)
|
|
||||||
const table = await con.createTable('vectors', [
|
|
||||||
{ id: 1n, vector: [0.1, 0.2] }
|
|
||||||
])
|
|
||||||
await table.dropColumns(['vector'])
|
|
||||||
|
|
||||||
const expectedSchema = new Schema([
|
|
||||||
new Field('id', new Int64(), true)
|
|
||||||
])
|
|
||||||
expect(await table.schema()).toEqual(expectedSchema)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# `lancedb-darwin-arm64`
|
# `vectordb-darwin-arm64`
|
||||||
|
|
||||||
This is the **aarch64-apple-darwin** binary for `lancedb`
|
This is the **aarch64-apple-darwin** binary for `vectordb`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "lancedb-darwin-arm64",
|
"name": "vectordb-darwin-arm64",
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"main": "lancedb.darwin-arm64.node",
|
"main": "vectordb.darwin-arm64.node",
|
||||||
"files": [
|
"files": [
|
||||||
"lancedb.darwin-arm64.node"
|
"vectordb.darwin-arm64.node"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# `lancedb-darwin-x64`
|
# `vectordb-darwin-x64`
|
||||||
|
|
||||||
This is the **x86_64-apple-darwin** binary for `lancedb`
|
This is the **x86_64-apple-darwin** binary for `vectordb`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "lancedb-darwin-x64",
|
"name": "vectordb-darwin-x64",
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"main": "lancedb.darwin-x64.node",
|
"main": "vectordb.darwin-x64.node",
|
||||||
"files": [
|
"files": [
|
||||||
"lancedb.darwin-x64.node"
|
"vectordb.darwin-x64.node"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# `lancedb-linux-arm64-gnu`
|
# `vectordb-linux-arm64-gnu`
|
||||||
|
|
||||||
This is the **aarch64-unknown-linux-gnu** binary for `lancedb`
|
This is the **aarch64-unknown-linux-gnu** binary for `vectordb`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "lancedb-linux-arm64-gnu",
|
"name": "vectordb-linux-arm64-gnu",
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"main": "lancedb.linux-arm64-gnu.node",
|
"main": "vectordb.linux-arm64-gnu.node",
|
||||||
"files": [
|
"files": [
|
||||||
"lancedb.linux-arm64-gnu.node"
|
"vectordb.linux-arm64-gnu.node"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# `lancedb-linux-x64-gnu`
|
# `vectordb-linux-x64-gnu`
|
||||||
|
|
||||||
This is the **x86_64-unknown-linux-gnu** binary for `lancedb`
|
This is the **x86_64-unknown-linux-gnu** binary for `vectordb`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "lancedb-linux-x64-gnu",
|
"name": "vectordb-linux-x64-gnu",
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"main": "lancedb.linux-x64-gnu.node",
|
"main": "vectordb.linux-x64-gnu.node",
|
||||||
"files": [
|
"files": [
|
||||||
"lancedb.linux-x64-gnu.node"
|
"vectordb.linux-x64-gnu.node"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
1087
nodejs/package-lock.json
generated
1087
nodejs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "lancedb",
|
"name": "vectordb",
|
||||||
"version": "0.4.3",
|
"version": "0.4.3",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"napi": {
|
"napi": {
|
||||||
"name": "lancedb-nodejs",
|
"name": "vectordb-nodejs",
|
||||||
"triples": {
|
"triples": {
|
||||||
"defaults": false,
|
"defaults": false,
|
||||||
"additional": [
|
"additional": [
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"license": "Apache 2.0",
|
"license": "Apache 2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@napi-rs/cli": "^2.18.0",
|
"@napi-rs/cli": "^2.18.0",
|
||||||
"@types/jest": "^29.1.2",
|
"@types/jest": "^29.5.11",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
||||||
"@typescript-eslint/parser": "^6.19.0",
|
"@typescript-eslint/parser": "^6.19.0",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.56.0",
|
||||||
@@ -45,24 +45,23 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"artifacts": "napi artifacts",
|
"artifacts": "napi artifacts",
|
||||||
"build:native": "napi build --platform --release --js lancedb/native.js --dts lancedb/native.d.ts dist/",
|
"build:native": "napi build --platform --release --js vectordb/native.js --dts vectordb/native.d.ts dist/",
|
||||||
"build:debug": "napi build --platform --dts ../lancedb/native.d.ts --js ../lancedb/native.js dist/",
|
"build:debug": "napi build --platform --dts ../vectordb/native.d.ts --js ../vectordb/native.js dist/",
|
||||||
"build": "npm run build:debug && tsc -b",
|
"build": "npm run build:debug && tsc -b",
|
||||||
"docs": "typedoc --plugin typedoc-plugin-markdown lancedb/index.ts",
|
"docs": "typedoc --plugin typedoc-plugin-markdown vectordb/index.ts",
|
||||||
"lint": "eslint lancedb --ext .js,.ts",
|
"lint": "eslint vectordb --ext .js,.ts",
|
||||||
"prepublishOnly": "napi prepublish -t npm",
|
"prepublishOnly": "napi prepublish -t npm",
|
||||||
"//": "maxWorkers=1 is workaround for bigint issue in jest: https://github.com/jestjs/jest/issues/11617#issuecomment-1068732414",
|
"test": "npm run build && jest",
|
||||||
"test": "npm run build && jest --maxWorkers=1",
|
|
||||||
"universal": "napi universal",
|
"universal": "napi universal",
|
||||||
"version": "napi version"
|
"version": "napi version"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"lancedb-darwin-arm64": "0.4.3",
|
"vectordb-darwin-arm64": "0.4.3",
|
||||||
"lancedb-darwin-x64": "0.4.3",
|
"vectordb-darwin-x64": "0.4.3",
|
||||||
"lancedb-linux-arm64-gnu": "0.4.3",
|
"vectordb-linux-arm64-gnu": "0.4.3",
|
||||||
"lancedb-linux-x64-gnu": "0.4.3"
|
"vectordb-linux-x64-gnu": "0.4.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"dependencies": {
|
||||||
"apache-arrow": "^15.0.0"
|
"apache-arrow": "^15.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,40 +12,29 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use napi::bindgen_prelude::*;
|
use napi::bindgen_prelude::*;
|
||||||
use napi_derive::*;
|
use napi_derive::*;
|
||||||
|
|
||||||
use crate::table::Table;
|
use crate::table::Table;
|
||||||
use crate::ConnectionOptions;
|
use vectordb::connection::{Connection as LanceDBConnection, Database};
|
||||||
use lancedb::connection::{ConnectBuilder, Connection as LanceDBConnection};
|
use vectordb::ipc::ipc_file_to_batches;
|
||||||
use lancedb::ipc::ipc_file_to_batches;
|
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
conn: LanceDBConnection,
|
conn: Arc<dyn LanceDBConnection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Create a new Connection instance from the given URI.
|
/// Create a new Connection instance from the given URI.
|
||||||
#[napi(factory)]
|
#[napi(factory)]
|
||||||
pub async fn new(options: ConnectionOptions) -> napi::Result<Self> {
|
pub async fn new(uri: String) -> napi::Result<Self> {
|
||||||
let mut builder = ConnectBuilder::new(&options.uri);
|
|
||||||
if let Some(api_key) = options.api_key {
|
|
||||||
builder = builder.api_key(&api_key);
|
|
||||||
}
|
|
||||||
if let Some(host_override) = options.host_override {
|
|
||||||
builder = builder.host_override(&host_override);
|
|
||||||
}
|
|
||||||
if let Some(interval) = options.read_consistency_interval {
|
|
||||||
builder =
|
|
||||||
builder.read_consistency_interval(std::time::Duration::from_secs_f64(interval));
|
|
||||||
}
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
conn: builder
|
conn: Arc::new(Database::connect(&uri).await.map_err(|e| {
|
||||||
.execute()
|
napi::Error::from_reason(format!("Failed to connect to database: {}", e))
|
||||||
.await
|
})?),
|
||||||
.map_err(|e| napi::Error::from_reason(format!("{}", e)))?,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +59,7 @@ impl Connection {
|
|||||||
.map_err(|e| napi::Error::from_reason(format!("Failed to read IPC file: {}", e)))?;
|
.map_err(|e| napi::Error::from_reason(format!("Failed to read IPC file: {}", e)))?;
|
||||||
let tbl = self
|
let tbl = self
|
||||||
.conn
|
.conn
|
||||||
.create_table(&name, Box::new(batches))
|
.create_table(&name, Box::new(batches), None)
|
||||||
.execute()
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| napi::Error::from_reason(format!("{}", e)))?;
|
.map_err(|e| napi::Error::from_reason(format!("{}", e)))?;
|
||||||
Ok(Table::new(tbl))
|
Ok(Table::new(tbl))
|
||||||
@@ -82,7 +70,6 @@ impl Connection {
|
|||||||
let tbl = self
|
let tbl = self
|
||||||
.conn
|
.conn
|
||||||
.open_table(&name)
|
.open_table(&name)
|
||||||
.execute()
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| napi::Error::from_reason(format!("{}", e)))?;
|
.map_err(|e| napi::Error::from_reason(format!("{}", e)))?;
|
||||||
Ok(Table::new(tbl))
|
Ok(Table::new(tbl))
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ impl From<MetricType> for LanceMetricType {
|
|||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub struct IndexBuilder {
|
pub struct IndexBuilder {
|
||||||
inner: lancedb::index::IndexBuilder,
|
inner: vectordb::index::IndexBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
impl IndexBuilder {
|
impl IndexBuilder {
|
||||||
pub fn new(tbl: &dyn lancedb::Table) -> Self {
|
pub fn new(tbl: &dyn vectordb::Table) -> Self {
|
||||||
let inner = tbl.create_index(&[]);
|
let inner = tbl.create_index(&[]);
|
||||||
Self { inner }
|
Self { inner }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use lance::io::RecordBatchStream;
|
use lance::io::RecordBatchStream;
|
||||||
use lancedb::ipc::batches_to_ipc_file;
|
|
||||||
use napi::bindgen_prelude::*;
|
use napi::bindgen_prelude::*;
|
||||||
use napi_derive::napi;
|
use napi_derive::napi;
|
||||||
|
use vectordb::ipc::batches_to_ipc_file;
|
||||||
|
|
||||||
/** Typescript-style Async Iterator over RecordBatches */
|
/** Typescript-style Async Iterator over RecordBatches */
|
||||||
#[napi]
|
#[napi]
|
||||||
|
|||||||
@@ -22,21 +22,10 @@ mod query;
|
|||||||
mod table;
|
mod table;
|
||||||
|
|
||||||
#[napi(object)]
|
#[napi(object)]
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ConnectionOptions {
|
pub struct ConnectionOptions {
|
||||||
pub uri: String,
|
pub uri: String,
|
||||||
pub api_key: Option<String>,
|
pub api_key: Option<String>,
|
||||||
pub host_override: Option<String>,
|
pub host_override: Option<String>,
|
||||||
/// (For LanceDB OSS only): The interval, in seconds, at which to check for
|
|
||||||
/// updates to the table from other processes. If None, then consistency is not
|
|
||||||
/// checked. For performance reasons, this is the default. For strong
|
|
||||||
/// consistency, set this to zero seconds. Then every read will check for
|
|
||||||
/// updates from other processes. As a compromise, you can set this to a
|
|
||||||
/// non-zero value for eventual consistency. If more than that interval
|
|
||||||
/// has passed since the last check, then the table will be checked for updates.
|
|
||||||
/// Note: this consistency only applies to read operations. Write operations are
|
|
||||||
/// always consistent.
|
|
||||||
pub read_consistency_interval: Option<f64>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write mode for writing a table.
|
/// Write mode for writing a table.
|
||||||
@@ -55,5 +44,5 @@ pub struct WriteOptions {
|
|||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub async fn connect(options: ConnectionOptions) -> napi::Result<Connection> {
|
pub async fn connect(options: ConnectionOptions) -> napi::Result<Connection> {
|
||||||
Connection::new(options).await
|
Connection::new(options.uri.clone()).await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use lancedb::query::Query as LanceDBQuery;
|
|
||||||
use napi::bindgen_prelude::*;
|
use napi::bindgen_prelude::*;
|
||||||
use napi_derive::napi;
|
use napi_derive::napi;
|
||||||
|
use vectordb::query::Query as LanceDBQuery;
|
||||||
|
|
||||||
use crate::{iterator::RecordBatchIterator, table::Table};
|
use crate::{iterator::RecordBatchIterator, table::Table};
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use arrow_ipc::writer::FileWriter;
|
use arrow_ipc::writer::FileWriter;
|
||||||
use lance::dataset::ColumnAlteration as LanceColumnAlteration;
|
|
||||||
use lancedb::{
|
|
||||||
ipc::ipc_file_to_batches,
|
|
||||||
table::{AddDataOptions, TableRef},
|
|
||||||
};
|
|
||||||
use napi::bindgen_prelude::*;
|
use napi::bindgen_prelude::*;
|
||||||
use napi_derive::napi;
|
use napi_derive::napi;
|
||||||
|
use vectordb::{ipc::ipc_file_to_batches, table::TableRef};
|
||||||
|
|
||||||
use crate::index::IndexBuilder;
|
use crate::index::IndexBuilder;
|
||||||
use crate::query::Query;
|
use crate::query::Query;
|
||||||
@@ -37,12 +33,8 @@ impl Table {
|
|||||||
|
|
||||||
/// Return Schema as empty Arrow IPC file.
|
/// Return Schema as empty Arrow IPC file.
|
||||||
#[napi]
|
#[napi]
|
||||||
pub async fn schema(&self) -> napi::Result<Buffer> {
|
pub fn schema(&self) -> napi::Result<Buffer> {
|
||||||
let schema =
|
let mut writer = FileWriter::try_new(vec![], &self.table.schema())
|
||||||
self.table.schema().await.map_err(|e| {
|
|
||||||
napi::Error::from_reason(format!("Failed to create IPC file: {}", e))
|
|
||||||
})?;
|
|
||||||
let mut writer = FileWriter::try_new(vec![], &schema)
|
|
||||||
.map_err(|e| napi::Error::from_reason(format!("Failed to create IPC file: {}", e)))?;
|
.map_err(|e| napi::Error::from_reason(format!("Failed to create IPC file: {}", e)))?;
|
||||||
writer
|
writer
|
||||||
.finish()
|
.finish()
|
||||||
@@ -56,15 +48,12 @@ impl Table {
|
|||||||
pub async fn add(&self, buf: Buffer) -> napi::Result<()> {
|
pub async fn add(&self, buf: Buffer) -> napi::Result<()> {
|
||||||
let batches = ipc_file_to_batches(buf.to_vec())
|
let batches = ipc_file_to_batches(buf.to_vec())
|
||||||
.map_err(|e| napi::Error::from_reason(format!("Failed to read IPC file: {}", e)))?;
|
.map_err(|e| napi::Error::from_reason(format!("Failed to read IPC file: {}", e)))?;
|
||||||
self.table
|
self.table.add(Box::new(batches), None).await.map_err(|e| {
|
||||||
.add(Box::new(batches), AddDataOptions::default())
|
napi::Error::from_reason(format!(
|
||||||
.await
|
"Failed to add batches to table {}: {}",
|
||||||
.map_err(|e| {
|
self.table, e
|
||||||
napi::Error::from_reason(format!(
|
))
|
||||||
"Failed to add batches to table {}: {}",
|
})
|
||||||
self.table, e
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
@@ -96,106 +85,4 @@ impl Table {
|
|||||||
pub fn query(&self) -> Query {
|
pub fn query(&self) -> Query {
|
||||||
Query::new(self)
|
Query::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
|
||||||
pub async fn add_columns(&self, transforms: Vec<AddColumnsSql>) -> napi::Result<()> {
|
|
||||||
let transforms = transforms
|
|
||||||
.into_iter()
|
|
||||||
.map(|sql| (sql.name, sql.value_sql))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let transforms = lance::dataset::NewColumnTransform::SqlExpressions(transforms);
|
|
||||||
self.table
|
|
||||||
.add_columns(transforms, None)
|
|
||||||
.await
|
|
||||||
.map_err(|err| {
|
|
||||||
napi::Error::from_reason(format!(
|
|
||||||
"Failed to add columns to table {}: {}",
|
|
||||||
self.table, err
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[napi]
|
|
||||||
pub async fn alter_columns(&self, alterations: Vec<ColumnAlteration>) -> napi::Result<()> {
|
|
||||||
for alteration in &alterations {
|
|
||||||
if alteration.rename.is_none() && alteration.nullable.is_none() {
|
|
||||||
return Err(napi::Error::from_reason(
|
|
||||||
"Alteration must have a 'rename' or 'nullable' field.",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let alterations = alterations
|
|
||||||
.into_iter()
|
|
||||||
.map(LanceColumnAlteration::from)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
self.table
|
|
||||||
.alter_columns(&alterations)
|
|
||||||
.await
|
|
||||||
.map_err(|err| {
|
|
||||||
napi::Error::from_reason(format!(
|
|
||||||
"Failed to alter columns in table {}: {}",
|
|
||||||
self.table, err
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[napi]
|
|
||||||
pub async fn drop_columns(&self, columns: Vec<String>) -> napi::Result<()> {
|
|
||||||
let col_refs = columns.iter().map(String::as_str).collect::<Vec<_>>();
|
|
||||||
self.table.drop_columns(&col_refs).await.map_err(|err| {
|
|
||||||
napi::Error::from_reason(format!(
|
|
||||||
"Failed to drop columns from table {}: {}",
|
|
||||||
self.table, err
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A definition of a column alteration. The alteration changes the column at
|
|
||||||
/// `path` to have the new name `name`, to be nullable if `nullable` is true,
|
|
||||||
/// and to have the data type `data_type`. At least one of `rename` or `nullable`
|
|
||||||
/// must be provided.
|
|
||||||
#[napi(object)]
|
|
||||||
pub struct ColumnAlteration {
|
|
||||||
/// The path to the column to alter. This is a dot-separated path to the column.
|
|
||||||
/// If it is a top-level column then it is just the name of the column. If it is
|
|
||||||
/// a nested column then it is the path to the column, e.g. "a.b.c" for a column
|
|
||||||
/// `c` nested inside a column `b` nested inside a column `a`.
|
|
||||||
pub path: String,
|
|
||||||
/// The new name of the column. If not provided then the name will not be changed.
|
|
||||||
/// This must be distinct from the names of all other columns in the table.
|
|
||||||
pub rename: Option<String>,
|
|
||||||
/// Set the new nullability. Note that a nullable column cannot be made non-nullable.
|
|
||||||
pub nullable: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ColumnAlteration> for LanceColumnAlteration {
|
|
||||||
fn from(js: ColumnAlteration) -> Self {
|
|
||||||
let ColumnAlteration {
|
|
||||||
path,
|
|
||||||
rename,
|
|
||||||
nullable,
|
|
||||||
} = js;
|
|
||||||
Self {
|
|
||||||
path,
|
|
||||||
rename,
|
|
||||||
nullable,
|
|
||||||
// TODO: wire up this field
|
|
||||||
data_type: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A definition of a new column to add to a table.
|
|
||||||
#[napi(object)]
|
|
||||||
pub struct AddColumnsSql {
|
|
||||||
/// The name of the new column.
|
|
||||||
pub name: String,
|
|
||||||
/// The values to populate the new column with, as a SQL expression.
|
|
||||||
/// The expression can reference other columns in the table.
|
|
||||||
pub value_sql: String,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"include": [
|
"include": [
|
||||||
"lancedb/*.ts",
|
"vectordb/*.ts",
|
||||||
"lancedb/**/*.ts",
|
"vectordb/**/*.ts",
|
||||||
"lancedb/*.js",
|
"vectordb/*.js",
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2022",
|
"target": "es2022",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
],
|
],
|
||||||
"typedocOptions": {
|
"typedocOptions": {
|
||||||
"entryPoints": [
|
"entryPoints": [
|
||||||
"lancedb/index.ts"
|
"vectordb/index.ts"
|
||||||
],
|
],
|
||||||
"out": "../docs/src/javascript/",
|
"out": "../docs/src/javascript/",
|
||||||
"visibilityFilters": {
|
"visibilityFilters": {
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ export async function connect(
|
|||||||
opts = Object.assign(
|
opts = Object.assign(
|
||||||
{
|
{
|
||||||
uri: "",
|
uri: "",
|
||||||
apiKey: undefined,
|
apiKey: "",
|
||||||
hostOverride: undefined,
|
hostOverride: "",
|
||||||
},
|
},
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const nativeConn = await NativeConnection.new(opts);
|
const nativeConn = await NativeConnection.new(opts.uri);
|
||||||
return new Connection(nativeConn);
|
return new Connection(nativeConn);
|
||||||
}
|
}
|
||||||
@@ -12,54 +12,10 @@ export const enum MetricType {
|
|||||||
Cosine = 1,
|
Cosine = 1,
|
||||||
Dot = 2
|
Dot = 2
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* A definition of a column alteration. The alteration changes the column at
|
|
||||||
* `path` to have the new name `name`, to be nullable if `nullable` is true,
|
|
||||||
* and to have the data type `data_type`. At least one of `rename` or `nullable`
|
|
||||||
* must be provided.
|
|
||||||
*/
|
|
||||||
export interface ColumnAlteration {
|
|
||||||
/**
|
|
||||||
* The path to the column to alter. This is a dot-separated path to the column.
|
|
||||||
* If it is a top-level column then it is just the name of the column. If it is
|
|
||||||
* a nested column then it is the path to the column, e.g. "a.b.c" for a column
|
|
||||||
* `c` nested inside a column `b` nested inside a column `a`.
|
|
||||||
*/
|
|
||||||
path: string
|
|
||||||
/**
|
|
||||||
* The new name of the column. If not provided then the name will not be changed.
|
|
||||||
* This must be distinct from the names of all other columns in the table.
|
|
||||||
*/
|
|
||||||
rename?: string
|
|
||||||
/** Set the new nullability. Note that a nullable column cannot be made non-nullable. */
|
|
||||||
nullable?: boolean
|
|
||||||
}
|
|
||||||
/** A definition of a new column to add to a table. */
|
|
||||||
export interface AddColumnsSql {
|
|
||||||
/** The name of the new column. */
|
|
||||||
name: string
|
|
||||||
/**
|
|
||||||
* The values to populate the new column with, as a SQL expression.
|
|
||||||
* The expression can reference other columns in the table.
|
|
||||||
*/
|
|
||||||
valueSql: string
|
|
||||||
}
|
|
||||||
export interface ConnectionOptions {
|
export interface ConnectionOptions {
|
||||||
uri: string
|
uri: string
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
hostOverride?: string
|
hostOverride?: string
|
||||||
/**
|
|
||||||
* (For LanceDB OSS only): The interval, in seconds, at which to check for
|
|
||||||
* updates to the table from other processes. If None, then consistency is not
|
|
||||||
* checked. For performance reasons, this is the default. For strong
|
|
||||||
* consistency, set this to zero seconds. Then every read will check for
|
|
||||||
* updates from other processes. As a compromise, you can set this to a
|
|
||||||
* non-zero value for eventual consistency. If more than that interval
|
|
||||||
* has passed since the last check, then the table will be checked for updates.
|
|
||||||
* Note: this consistency only applies to read operations. Write operations are
|
|
||||||
* always consistent.
|
|
||||||
*/
|
|
||||||
readConsistencyInterval?: number
|
|
||||||
}
|
}
|
||||||
/** Write mode for writing a table. */
|
/** Write mode for writing a table. */
|
||||||
export const enum WriteMode {
|
export const enum WriteMode {
|
||||||
@@ -74,7 +30,7 @@ export interface WriteOptions {
|
|||||||
export function connect(options: ConnectionOptions): Promise<Connection>
|
export function connect(options: ConnectionOptions): Promise<Connection>
|
||||||
export class Connection {
|
export class Connection {
|
||||||
/** Create a new Connection instance from the given URI. */
|
/** Create a new Connection instance from the given URI. */
|
||||||
static new(options: ConnectionOptions): Promise<Connection>
|
static new(uri: string): Promise<Connection>
|
||||||
/** List all tables in the dataset. */
|
/** List all tables in the dataset. */
|
||||||
tableNames(): Promise<Array<string>>
|
tableNames(): Promise<Array<string>>
|
||||||
/**
|
/**
|
||||||
@@ -115,13 +71,10 @@ export class Query {
|
|||||||
}
|
}
|
||||||
export class Table {
|
export class Table {
|
||||||
/** Return Schema as empty Arrow IPC file. */
|
/** Return Schema as empty Arrow IPC file. */
|
||||||
schema(): Promise<Buffer>
|
schema(): Buffer
|
||||||
add(buf: Buffer): Promise<void>
|
add(buf: Buffer): Promise<void>
|
||||||
countRows(filter?: string | undefined | null): Promise<bigint>
|
countRows(filter?: string | undefined | null): Promise<bigint>
|
||||||
delete(predicate: string): Promise<void>
|
delete(predicate: string): Promise<void>
|
||||||
createIndex(): IndexBuilder
|
createIndex(): IndexBuilder
|
||||||
query(): Query
|
query(): Query
|
||||||
addColumns(transforms: Array<AddColumnsSql>): Promise<void>
|
|
||||||
alterColumns(alterations: Array<ColumnAlteration>): Promise<void>
|
|
||||||
dropColumns(columns: Array<string>): Promise<void>
|
|
||||||
}
|
}
|
||||||
@@ -32,24 +32,24 @@ switch (platform) {
|
|||||||
case 'android':
|
case 'android':
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
localFileExisted = existsSync(join(__dirname, 'lancedb-nodejs.android-arm64.node'))
|
localFileExisted = existsSync(join(__dirname, 'vectordb-nodejs.android-arm64.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.android-arm64.node')
|
nativeBinding = require('./vectordb-nodejs.android-arm64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-android-arm64')
|
nativeBinding = require('vectordb-android-arm64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'arm':
|
case 'arm':
|
||||||
localFileExisted = existsSync(join(__dirname, 'lancedb-nodejs.android-arm-eabi.node'))
|
localFileExisted = existsSync(join(__dirname, 'vectordb-nodejs.android-arm-eabi.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.android-arm-eabi.node')
|
nativeBinding = require('./vectordb-nodejs.android-arm-eabi.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-android-arm-eabi')
|
nativeBinding = require('vectordb-android-arm-eabi')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -63,13 +63,13 @@ switch (platform) {
|
|||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.win32-x64-msvc.node')
|
join(__dirname, 'vectordb-nodejs.win32-x64-msvc.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.win32-x64-msvc.node')
|
nativeBinding = require('./vectordb-nodejs.win32-x64-msvc.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-win32-x64-msvc')
|
nativeBinding = require('vectordb-win32-x64-msvc')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -77,13 +77,13 @@ switch (platform) {
|
|||||||
break
|
break
|
||||||
case 'ia32':
|
case 'ia32':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.win32-ia32-msvc.node')
|
join(__dirname, 'vectordb-nodejs.win32-ia32-msvc.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.win32-ia32-msvc.node')
|
nativeBinding = require('./vectordb-nodejs.win32-ia32-msvc.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-win32-ia32-msvc')
|
nativeBinding = require('vectordb-win32-ia32-msvc')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -91,13 +91,13 @@ switch (platform) {
|
|||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.win32-arm64-msvc.node')
|
join(__dirname, 'vectordb-nodejs.win32-arm64-msvc.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.win32-arm64-msvc.node')
|
nativeBinding = require('./vectordb-nodejs.win32-arm64-msvc.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-win32-arm64-msvc')
|
nativeBinding = require('vectordb-win32-arm64-msvc')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -108,23 +108,23 @@ switch (platform) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
localFileExisted = existsSync(join(__dirname, 'lancedb-nodejs.darwin-universal.node'))
|
localFileExisted = existsSync(join(__dirname, 'vectordb-nodejs.darwin-universal.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.darwin-universal.node')
|
nativeBinding = require('./vectordb-nodejs.darwin-universal.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-darwin-universal')
|
nativeBinding = require('vectordb-darwin-universal')
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} catch {}
|
} catch {}
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
localFileExisted = existsSync(join(__dirname, 'lancedb-nodejs.darwin-x64.node'))
|
localFileExisted = existsSync(join(__dirname, 'vectordb-nodejs.darwin-x64.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.darwin-x64.node')
|
nativeBinding = require('./vectordb-nodejs.darwin-x64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-darwin-x64')
|
nativeBinding = require('vectordb-darwin-x64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -132,13 +132,13 @@ switch (platform) {
|
|||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.darwin-arm64.node')
|
join(__dirname, 'vectordb-nodejs.darwin-arm64.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.darwin-arm64.node')
|
nativeBinding = require('./vectordb-nodejs.darwin-arm64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-darwin-arm64')
|
nativeBinding = require('vectordb-darwin-arm64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -152,12 +152,12 @@ switch (platform) {
|
|||||||
if (arch !== 'x64') {
|
if (arch !== 'x64') {
|
||||||
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
||||||
}
|
}
|
||||||
localFileExisted = existsSync(join(__dirname, 'lancedb-nodejs.freebsd-x64.node'))
|
localFileExisted = existsSync(join(__dirname, 'vectordb-nodejs.freebsd-x64.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.freebsd-x64.node')
|
nativeBinding = require('./vectordb-nodejs.freebsd-x64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-freebsd-x64')
|
nativeBinding = require('vectordb-freebsd-x64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -168,26 +168,26 @@ switch (platform) {
|
|||||||
case 'x64':
|
case 'x64':
|
||||||
if (isMusl()) {
|
if (isMusl()) {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-x64-musl.node')
|
join(__dirname, 'vectordb-nodejs.linux-x64-musl.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-x64-musl.node')
|
nativeBinding = require('./vectordb-nodejs.linux-x64-musl.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-x64-musl')
|
nativeBinding = require('vectordb-linux-x64-musl')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-x64-gnu.node')
|
join(__dirname, 'vectordb-nodejs.linux-x64-gnu.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-x64-gnu.node')
|
nativeBinding = require('./vectordb-nodejs.linux-x64-gnu.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-x64-gnu')
|
nativeBinding = require('vectordb-linux-x64-gnu')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -197,26 +197,26 @@ switch (platform) {
|
|||||||
case 'arm64':
|
case 'arm64':
|
||||||
if (isMusl()) {
|
if (isMusl()) {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-arm64-musl.node')
|
join(__dirname, 'vectordb-nodejs.linux-arm64-musl.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-arm64-musl.node')
|
nativeBinding = require('./vectordb-nodejs.linux-arm64-musl.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-arm64-musl')
|
nativeBinding = require('vectordb-linux-arm64-musl')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-arm64-gnu.node')
|
join(__dirname, 'vectordb-nodejs.linux-arm64-gnu.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-arm64-gnu.node')
|
nativeBinding = require('./vectordb-nodejs.linux-arm64-gnu.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-arm64-gnu')
|
nativeBinding = require('vectordb-linux-arm64-gnu')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -225,13 +225,13 @@ switch (platform) {
|
|||||||
break
|
break
|
||||||
case 'arm':
|
case 'arm':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-arm-gnueabihf.node')
|
join(__dirname, 'vectordb-nodejs.linux-arm-gnueabihf.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-arm-gnueabihf.node')
|
nativeBinding = require('./vectordb-nodejs.linux-arm-gnueabihf.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-arm-gnueabihf')
|
nativeBinding = require('vectordb-linux-arm-gnueabihf')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -240,26 +240,26 @@ switch (platform) {
|
|||||||
case 'riscv64':
|
case 'riscv64':
|
||||||
if (isMusl()) {
|
if (isMusl()) {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-riscv64-musl.node')
|
join(__dirname, 'vectordb-nodejs.linux-riscv64-musl.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-riscv64-musl.node')
|
nativeBinding = require('./vectordb-nodejs.linux-riscv64-musl.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-riscv64-musl')
|
nativeBinding = require('vectordb-linux-riscv64-musl')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-riscv64-gnu.node')
|
join(__dirname, 'vectordb-nodejs.linux-riscv64-gnu.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-riscv64-gnu.node')
|
nativeBinding = require('./vectordb-nodejs.linux-riscv64-gnu.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-riscv64-gnu')
|
nativeBinding = require('vectordb-linux-riscv64-gnu')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -268,13 +268,13 @@ switch (platform) {
|
|||||||
break
|
break
|
||||||
case 's390x':
|
case 's390x':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'lancedb-nodejs.linux-s390x-gnu.node')
|
join(__dirname, 'vectordb-nodejs.linux-s390x-gnu.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./lancedb-nodejs.linux-s390x-gnu.node')
|
nativeBinding = require('./vectordb-nodejs.linux-s390x-gnu.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('lancedb-linux-s390x-gnu')
|
nativeBinding = require('vectordb-linux-s390x-gnu')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Schema, tableFromIPC } from "apache-arrow";
|
import { Schema, tableFromIPC } from "apache-arrow";
|
||||||
import { AddColumnsSql, ColumnAlteration, Table as _NativeTable } from "./native";
|
import { Table as _NativeTable } from "./native";
|
||||||
import { toBuffer, Data } from "./arrow";
|
import { toBuffer, Data } from "./arrow";
|
||||||
import { Query } from "./query";
|
import { Query } from "./query";
|
||||||
import { IndexBuilder } from "./indexer";
|
import { IndexBuilder } from "./indexer";
|
||||||
@@ -32,8 +32,8 @@ export class Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get the schema of the table. */
|
/** Get the schema of the table. */
|
||||||
async schema(): Promise<Schema> {
|
get schema(): Schema {
|
||||||
const schemaBuf = await this.inner.schema();
|
const schemaBuf = this.inner.schema();
|
||||||
const tbl = tableFromIPC(schemaBuf);
|
const tbl = tableFromIPC(schemaBuf);
|
||||||
return tbl.schema;
|
return tbl.schema;
|
||||||
}
|
}
|
||||||
@@ -150,42 +150,4 @@ export class Table {
|
|||||||
}
|
}
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Support BatchUDF
|
|
||||||
/**
|
|
||||||
* Add new columns with defined values.
|
|
||||||
*
|
|
||||||
* @param newColumnTransforms pairs of column names and the SQL expression to use
|
|
||||||
* to calculate the value of the new column. These
|
|
||||||
* expressions will be evaluated for each row in the
|
|
||||||
* table, and can reference existing columns in the table.
|
|
||||||
*/
|
|
||||||
async addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void> {
|
|
||||||
await this.inner.addColumns(newColumnTransforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alter the name or nullability of columns.
|
|
||||||
*
|
|
||||||
* @param columnAlterations One or more alterations to apply to columns.
|
|
||||||
*/
|
|
||||||
async alterColumns(columnAlterations: ColumnAlteration[]): Promise<void> {
|
|
||||||
await this.inner.alterColumns(columnAlterations);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop one or more columns from the dataset
|
|
||||||
*
|
|
||||||
* This is a metadata-only operation and does not remove the data from the
|
|
||||||
* underlying storage. In order to remove the data, you must subsequently
|
|
||||||
* call ``compact_files`` to rewrite the data without the removed columns and
|
|
||||||
* then call ``cleanup_files`` to remove the old files.
|
|
||||||
*
|
|
||||||
* @param columnNames The names of the columns to drop. These can be nested
|
|
||||||
* column references (e.g. "a.b.c") or top-level column
|
|
||||||
* names (e.g. "a").
|
|
||||||
*/
|
|
||||||
async dropColumns(columnNames: string[]): Promise<void> {
|
|
||||||
await this.inner.dropColumns(columnNames);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.6.1
|
current_version = 0.5.5
|
||||||
commit = True
|
commit = True
|
||||||
message = [python] Bump version: {current_version} → {new_version}
|
message = [python] Bump version: {current_version} → {new_version}
|
||||||
tag = True
|
tag = True
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "lancedb-python"
|
|
||||||
version = "0.4.10"
|
|
||||||
edition.workspace = true
|
|
||||||
description = "Python bindings for LanceDB"
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
keywords.workspace = true
|
|
||||||
categories.workspace = true
|
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "_lancedb"
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
lancedb = { path = "../rust/lancedb" }
|
|
||||||
env_logger = "0.10"
|
|
||||||
pyo3 = { version = "0.20", features = ["extension-module", "abi3-py38"] }
|
|
||||||
pyo3-asyncio = { version = "0.20", features = ["attributes", "tokio-runtime"] }
|
|
||||||
|
|
||||||
# Prevent dynamic linking of lzma, which comes from datafusion
|
|
||||||
lzma-sys = { version = "*", features = ["static"] }
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
pyo3-build-config = { version = "0.20.3", features = ["extension-module", "abi3-py38"] }
|
|
||||||
@@ -20,10 +20,10 @@ results = table.search([0.1, 0.3]).limit(20).to_list()
|
|||||||
print(results)
|
print(results)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
LanceDb is based on the rust crate `lancedb` and is built with maturin. In order to build with maturin
|
Create a virtual environment and activate it:
|
||||||
you will either need a conda environment or a virtual environment (venv).
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
@@ -33,15 +33,7 @@ python -m venv venv
|
|||||||
Install the necessary packages:
|
Install the necessary packages:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m pip install .[tests,dev]
|
python -m pip install .
|
||||||
```
|
|
||||||
|
|
||||||
To build the python package you can use maturin:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# This will build the rust bindings and place them in the appropriate place
|
|
||||||
# in your venv or conda environment
|
|
||||||
matruin develop
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the unit tests:
|
To run the unit tests:
|
||||||
@@ -53,7 +45,7 @@ pytest
|
|||||||
To run the doc tests:
|
To run the doc tests:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pytest --doctest-modules python/lancedb
|
pytest --doctest-modules lancedb
|
||||||
```
|
```
|
||||||
|
|
||||||
To run linter and automatically fix all errors:
|
To run linter and automatically fix all errors:
|
||||||
@@ -69,27 +61,31 @@ If any packages are missing, install them with:
|
|||||||
pip install <PACKAGE_NAME>
|
pip install <PACKAGE_NAME>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
___
|
___
|
||||||
For **Windows** users, there may be errors when installing packages, so these commands may be helpful:
|
For **Windows** users, there may be errors when installing packages, so these commands may be helpful:
|
||||||
|
|
||||||
Activate the virtual environment:
|
Activate the virtual environment:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
. .\venv\Scripts\activate
|
. .\venv\Scripts\activate
|
||||||
```
|
```
|
||||||
|
|
||||||
You may need to run the installs separately:
|
You may need to run the installs separately:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install -e .[tests]
|
pip install -e .[tests]
|
||||||
pip install -e .[dev]
|
pip install -e .[dev]
|
||||||
```
|
```
|
||||||
|
|
||||||
`tantivy` requires `rust` to be installed, so install it with `conda`, as it doesn't support windows installation:
|
|
||||||
|
|
||||||
|
`tantivy` requires `rust` to be installed, so install it with `conda`, as it doesn't support windows installation:
|
||||||
```bash
|
```bash
|
||||||
pip install wheel
|
pip install wheel
|
||||||
pip install cargo
|
pip install cargo
|
||||||
conda install rust
|
conda install rust
|
||||||
pip install tantivy
|
pip install tantivy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To run the unit tests:
|
||||||
|
```bash
|
||||||
|
pytest
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
pyo3_build_config::add_extension_module_link_args();
|
|
||||||
}
|
|
||||||
90
python/lancedb/__init__.py
Normal file
90
python/lancedb/__init__.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
# Copyright 2023 LanceDB Developers
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import importlib.metadata
|
||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
__version__ = importlib.metadata.version("lancedb")
|
||||||
|
|
||||||
|
from .common import URI
|
||||||
|
from .db import DBConnection, LanceDBConnection
|
||||||
|
from .remote.db import RemoteDBConnection
|
||||||
|
from .schema import vector # noqa: F401
|
||||||
|
from .utils import sentry_log # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
|
def connect(
|
||||||
|
uri: URI,
|
||||||
|
*,
|
||||||
|
api_key: Optional[str] = None,
|
||||||
|
region: str = "us-east-1",
|
||||||
|
host_override: Optional[str] = None,
|
||||||
|
read_consistency_interval: Optional[timedelta] = None,
|
||||||
|
) -> DBConnection:
|
||||||
|
"""Connect to a LanceDB database.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
uri: str or Path
|
||||||
|
The uri of the database.
|
||||||
|
api_key: str, optional
|
||||||
|
If presented, connect to LanceDB cloud.
|
||||||
|
Otherwise, connect to a database on file system or cloud storage.
|
||||||
|
Can be set via environment variable `LANCEDB_API_KEY`.
|
||||||
|
region: str, default "us-east-1"
|
||||||
|
The region to use for LanceDB Cloud.
|
||||||
|
host_override: str, optional
|
||||||
|
The override url for LanceDB Cloud.
|
||||||
|
read_consistency_interval: timedelta, default None
|
||||||
|
(For LanceDB OSS only)
|
||||||
|
The interval at which to check for updates to the table from other
|
||||||
|
processes. If None, then consistency is not checked. For performance
|
||||||
|
reasons, this is the default. For strong consistency, set this to
|
||||||
|
zero seconds. Then every read will check for updates from other
|
||||||
|
processes. As a compromise, you can set this to a non-zero timedelta
|
||||||
|
for eventual consistency. If more than that interval has passed since
|
||||||
|
the last check, then the table will be checked for updates. Note: this
|
||||||
|
consistency only applies to read operations. Write operations are
|
||||||
|
always consistent.
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
For a local directory, provide a path for the database:
|
||||||
|
|
||||||
|
>>> import lancedb
|
||||||
|
>>> db = lancedb.connect("~/.lancedb")
|
||||||
|
|
||||||
|
For object storage, use a URI prefix:
|
||||||
|
|
||||||
|
>>> db = lancedb.connect("s3://my-bucket/lancedb")
|
||||||
|
|
||||||
|
Connect to LancdDB cloud:
|
||||||
|
|
||||||
|
>>> db = lancedb.connect("db://my_database", api_key="ldb_...")
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
conn : DBConnection
|
||||||
|
A connection to a LanceDB database.
|
||||||
|
"""
|
||||||
|
if isinstance(uri, str) and uri.startswith("db://"):
|
||||||
|
if api_key is None:
|
||||||
|
api_key = os.environ.get("LANCEDB_API_KEY")
|
||||||
|
if api_key is None:
|
||||||
|
raise ValueError(f"api_key is required to connected LanceDB cloud: {uri}")
|
||||||
|
return RemoteDBConnection(uri, api_key, region, host_override)
|
||||||
|
return LanceDBConnection(uri, read_consistency_interval=read_consistency_interval)
|
||||||
@@ -34,7 +34,3 @@ class Credential(str):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "********"
|
return "********"
|
||||||
|
|
||||||
|
|
||||||
def sanitize_uri(uri: URI) -> str:
|
|
||||||
return str(uri)
|
|
||||||
@@ -28,7 +28,6 @@ from .util import fs_from_uri, get_uri_location, get_uri_scheme, join_uri
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from ._lancedb import Connection as LanceDbConnection
|
|
||||||
from .common import DATA, URI
|
from .common import DATA, URI
|
||||||
from .embeddings import EmbeddingFunctionConfig
|
from .embeddings import EmbeddingFunctionConfig
|
||||||
from .pydantic import LanceModel
|
from .pydantic import LanceModel
|
||||||
@@ -41,21 +40,14 @@ class DBConnection(EnforceOverrides):
|
|||||||
def table_names(
|
def table_names(
|
||||||
self, page_token: Optional[str] = None, limit: int = 10
|
self, page_token: Optional[str] = None, limit: int = 10
|
||||||
) -> Iterable[str]:
|
) -> Iterable[str]:
|
||||||
"""List all tables in this database, in sorted order
|
"""List all table in this database
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
page_token: str, optional
|
page_token: str, optional
|
||||||
The token to use for pagination. If not present, start from the beginning.
|
The token to use for pagination. If not present, start from the beginning.
|
||||||
Typically, this token is last table name from the previous page.
|
|
||||||
Only supported by LanceDb Cloud.
|
|
||||||
limit: int, default 10
|
limit: int, default 10
|
||||||
The size of the page to return.
|
The size of the page to return.
|
||||||
Only supported by LanceDb Cloud.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Iterable of str
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -420,254 +412,3 @@ class LanceDBConnection(DBConnection):
|
|||||||
def drop_database(self):
|
def drop_database(self):
|
||||||
filesystem, path = fs_from_uri(self.uri)
|
filesystem, path = fs_from_uri(self.uri)
|
||||||
filesystem.delete_dir(path)
|
filesystem.delete_dir(path)
|
||||||
|
|
||||||
|
|
||||||
class AsyncConnection(EnforceOverrides):
|
|
||||||
"""An active LanceDB connection interface."""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def table_names(
|
|
||||||
self, *, page_token: Optional[str] = None, limit: int = 10
|
|
||||||
) -> Iterable[str]:
|
|
||||||
"""List all tables in this database, in sorted order
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
page_token: str, optional
|
|
||||||
The token to use for pagination. If not present, start from the beginning.
|
|
||||||
Typically, this token is last table name from the previous page.
|
|
||||||
Only supported by LanceDb Cloud.
|
|
||||||
limit: int, default 10
|
|
||||||
The size of the page to return.
|
|
||||||
Only supported by LanceDb Cloud.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Iterable of str
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def create_table(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
data: Optional[DATA] = None,
|
|
||||||
schema: Optional[Union[pa.Schema, LanceModel]] = None,
|
|
||||||
mode: str = "create",
|
|
||||||
exist_ok: bool = False,
|
|
||||||
on_bad_vectors: str = "error",
|
|
||||||
fill_value: float = 0.0,
|
|
||||||
embedding_functions: Optional[List[EmbeddingFunctionConfig]] = None,
|
|
||||||
) -> Table:
|
|
||||||
"""Create a [Table][lancedb.table.Table] in the database.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
name: str
|
|
||||||
The name of the table.
|
|
||||||
data: The data to initialize the table, *optional*
|
|
||||||
User must provide at least one of `data` or `schema`.
|
|
||||||
Acceptable types are:
|
|
||||||
|
|
||||||
- dict or list-of-dict
|
|
||||||
|
|
||||||
- pandas.DataFrame
|
|
||||||
|
|
||||||
- pyarrow.Table or pyarrow.RecordBatch
|
|
||||||
schema: The schema of the table, *optional*
|
|
||||||
Acceptable types are:
|
|
||||||
|
|
||||||
- pyarrow.Schema
|
|
||||||
|
|
||||||
- [LanceModel][lancedb.pydantic.LanceModel]
|
|
||||||
mode: str; default "create"
|
|
||||||
The mode to use when creating the table.
|
|
||||||
Can be either "create" or "overwrite".
|
|
||||||
By default, if the table already exists, an exception is raised.
|
|
||||||
If you want to overwrite the table, use mode="overwrite".
|
|
||||||
exist_ok: bool, default False
|
|
||||||
If a table by the same name already exists, then raise an exception
|
|
||||||
if exist_ok=False. If exist_ok=True, then open the existing table;
|
|
||||||
it will not add the provided data but will validate against any
|
|
||||||
schema that's specified.
|
|
||||||
on_bad_vectors: str, default "error"
|
|
||||||
What to do if any of the vectors are not the same size or contains NaNs.
|
|
||||||
One of "error", "drop", "fill".
|
|
||||||
fill_value: float
|
|
||||||
The value to use when filling vectors. Only used if on_bad_vectors="fill".
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
LanceTable
|
|
||||||
A reference to the newly created table.
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
|
|
||||||
The vector index won't be created by default.
|
|
||||||
To create the index, call the `create_index` method on the table.
|
|
||||||
|
|
||||||
Examples
|
|
||||||
--------
|
|
||||||
|
|
||||||
Can create with list of tuples or dictionaries:
|
|
||||||
|
|
||||||
>>> import lancedb
|
|
||||||
>>> db = lancedb.connect("./.lancedb")
|
|
||||||
>>> data = [{"vector": [1.1, 1.2], "lat": 45.5, "long": -122.7},
|
|
||||||
... {"vector": [0.2, 1.8], "lat": 40.1, "long": -74.1}]
|
|
||||||
>>> db.create_table("my_table", data)
|
|
||||||
LanceTable(connection=..., name="my_table")
|
|
||||||
>>> db["my_table"].head()
|
|
||||||
pyarrow.Table
|
|
||||||
vector: fixed_size_list<item: float>[2]
|
|
||||||
child 0, item: float
|
|
||||||
lat: double
|
|
||||||
long: double
|
|
||||||
----
|
|
||||||
vector: [[[1.1,1.2],[0.2,1.8]]]
|
|
||||||
lat: [[45.5,40.1]]
|
|
||||||
long: [[-122.7,-74.1]]
|
|
||||||
|
|
||||||
You can also pass a pandas DataFrame:
|
|
||||||
|
|
||||||
>>> import pandas as pd
|
|
||||||
>>> data = pd.DataFrame({
|
|
||||||
... "vector": [[1.1, 1.2], [0.2, 1.8]],
|
|
||||||
... "lat": [45.5, 40.1],
|
|
||||||
... "long": [-122.7, -74.1]
|
|
||||||
... })
|
|
||||||
>>> db.create_table("table2", data)
|
|
||||||
LanceTable(connection=..., name="table2")
|
|
||||||
>>> db["table2"].head()
|
|
||||||
pyarrow.Table
|
|
||||||
vector: fixed_size_list<item: float>[2]
|
|
||||||
child 0, item: float
|
|
||||||
lat: double
|
|
||||||
long: double
|
|
||||||
----
|
|
||||||
vector: [[[1.1,1.2],[0.2,1.8]]]
|
|
||||||
lat: [[45.5,40.1]]
|
|
||||||
long: [[-122.7,-74.1]]
|
|
||||||
|
|
||||||
Data is converted to Arrow before being written to disk. For maximum
|
|
||||||
control over how data is saved, either provide the PyArrow schema to
|
|
||||||
convert to or else provide a [PyArrow Table](pyarrow.Table) directly.
|
|
||||||
|
|
||||||
>>> custom_schema = pa.schema([
|
|
||||||
... pa.field("vector", pa.list_(pa.float32(), 2)),
|
|
||||||
... pa.field("lat", pa.float32()),
|
|
||||||
... pa.field("long", pa.float32())
|
|
||||||
... ])
|
|
||||||
>>> db.create_table("table3", data, schema = custom_schema)
|
|
||||||
LanceTable(connection=..., name="table3")
|
|
||||||
>>> db["table3"].head()
|
|
||||||
pyarrow.Table
|
|
||||||
vector: fixed_size_list<item: float>[2]
|
|
||||||
child 0, item: float
|
|
||||||
lat: float
|
|
||||||
long: float
|
|
||||||
----
|
|
||||||
vector: [[[1.1,1.2],[0.2,1.8]]]
|
|
||||||
lat: [[45.5,40.1]]
|
|
||||||
long: [[-122.7,-74.1]]
|
|
||||||
|
|
||||||
|
|
||||||
It is also possible to create an table from `[Iterable[pa.RecordBatch]]`:
|
|
||||||
|
|
||||||
|
|
||||||
>>> import pyarrow as pa
|
|
||||||
>>> def make_batches():
|
|
||||||
... for i in range(5):
|
|
||||||
... yield pa.RecordBatch.from_arrays(
|
|
||||||
... [
|
|
||||||
... pa.array([[3.1, 4.1], [5.9, 26.5]],
|
|
||||||
... pa.list_(pa.float32(), 2)),
|
|
||||||
... pa.array(["foo", "bar"]),
|
|
||||||
... pa.array([10.0, 20.0]),
|
|
||||||
... ],
|
|
||||||
... ["vector", "item", "price"],
|
|
||||||
... )
|
|
||||||
>>> schema=pa.schema([
|
|
||||||
... pa.field("vector", pa.list_(pa.float32(), 2)),
|
|
||||||
... pa.field("item", pa.utf8()),
|
|
||||||
... pa.field("price", pa.float32()),
|
|
||||||
... ])
|
|
||||||
>>> db.create_table("table4", make_batches(), schema=schema)
|
|
||||||
LanceTable(connection=..., name="table4")
|
|
||||||
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
async def open_table(self, name: str) -> Table:
|
|
||||||
"""Open a Lance Table in the database.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
name: str
|
|
||||||
The name of the table.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
A LanceTable object representing the table.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
async def drop_table(self, name: str):
|
|
||||||
"""Drop a table from the database.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
name: str
|
|
||||||
The name of the table.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
async def drop_database(self):
|
|
||||||
"""
|
|
||||||
Drop database
|
|
||||||
This is the same thing as dropping all the tables
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncLanceDBConnection(AsyncConnection):
|
|
||||||
def __init__(self, connection: LanceDbConnection):
|
|
||||||
self._inner = connection
|
|
||||||
|
|
||||||
async def __repr__(self) -> str:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@override
|
|
||||||
async def table_names(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
page_token=None,
|
|
||||||
limit=None,
|
|
||||||
) -> Iterable[str]:
|
|
||||||
return await self._inner.table_names()
|
|
||||||
|
|
||||||
@override
|
|
||||||
async def create_table(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
data: Optional[DATA] = None,
|
|
||||||
schema: Optional[Union[pa.Schema, LanceModel]] = None,
|
|
||||||
mode: str = "create",
|
|
||||||
exist_ok: bool = False,
|
|
||||||
on_bad_vectors: str = "error",
|
|
||||||
fill_value: float = 0.0,
|
|
||||||
embedding_functions: Optional[List[EmbeddingFunctionConfig]] = None,
|
|
||||||
) -> LanceTable:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@override
|
|
||||||
async def open_table(self, name: str) -> LanceTable:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@override
|
|
||||||
async def drop_table(self, name: str, ignore_missing: bool = False):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@override
|
|
||||||
async def drop_database(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
@@ -103,9 +103,9 @@ class InstructorEmbeddingFunction(TextEmbeddingFunction):
|
|||||||
# convert_to_numpy: bool = True # Hardcoding this as numpy can be ingested directly
|
# convert_to_numpy: bool = True # Hardcoding this as numpy can be ingested directly
|
||||||
|
|
||||||
source_instruction: str = "represent the document for retrieval"
|
source_instruction: str = "represent the document for retrieval"
|
||||||
query_instruction: str = (
|
query_instruction: (
|
||||||
"represent the document for retrieving the most similar documents"
|
str
|
||||||
)
|
) = "represent the document for retrieving the most similar documents"
|
||||||
|
|
||||||
@weak_lru(maxsize=1)
|
@weak_lru(maxsize=1)
|
||||||
def ndims(self):
|
def ndims(self):
|
||||||
@@ -26,7 +26,7 @@ import pyarrow as pa
|
|||||||
from lance.vector import vec_to_table
|
from lance.vector import vec_to_table
|
||||||
from retry import retry
|
from retry import retry
|
||||||
|
|
||||||
from ..util import deprecated, safe_import_pandas
|
from ..util import safe_import_pandas
|
||||||
from ..utils.general import LOGGER
|
from ..utils.general import LOGGER
|
||||||
|
|
||||||
pd = safe_import_pandas()
|
pd = safe_import_pandas()
|
||||||
@@ -36,10 +36,8 @@ TEXT = Union[str, List[str], pa.Array, pa.ChunkedArray, np.ndarray]
|
|||||||
IMAGES = Union[
|
IMAGES = Union[
|
||||||
str, bytes, List[str], List[bytes], pa.Array, pa.ChunkedArray, np.ndarray
|
str, bytes, List[str], List[bytes], pa.Array, pa.ChunkedArray, np.ndarray
|
||||||
]
|
]
|
||||||
AUDIO = Union[str, bytes, List[str], List[bytes], pa.Array, pa.ChunkedArray, np.ndarray]
|
|
||||||
|
|
||||||
|
|
||||||
@deprecated
|
|
||||||
def with_embeddings(
|
def with_embeddings(
|
||||||
func: Callable,
|
func: Callable,
|
||||||
data: DATA,
|
data: DATA,
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""Full text search index using tantivy-py"""
|
"""Full text search index using tantivy-py"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, Type, Union
|
from typing import TYPE_CHECKING, List, Literal, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
import deprecation
|
import deprecation
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -93,7 +93,7 @@ class Query(pydantic.BaseModel):
|
|||||||
metric: str = "L2"
|
metric: str = "L2"
|
||||||
|
|
||||||
# which columns to return in the results
|
# which columns to return in the results
|
||||||
columns: Optional[Union[List[str], Dict[str, str]]] = None
|
columns: Optional[List[str]] = None
|
||||||
|
|
||||||
# optional query parameters for tuning the results,
|
# optional query parameters for tuning the results,
|
||||||
# e.g. `{"nprobes": "10", "refine_factor": "10"}`
|
# e.g. `{"nprobes": "10", "refine_factor": "10"}`
|
||||||
@@ -321,25 +321,20 @@ class LanceQueryBuilder(ABC):
|
|||||||
self._limit = limit
|
self._limit = limit
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def select(self, columns: Union[list[str], dict[str, str]]) -> LanceQueryBuilder:
|
def select(self, columns: list) -> LanceQueryBuilder:
|
||||||
"""Set the columns to return.
|
"""Set the columns to return.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
columns: list of str, or dict of str to str default None
|
columns: list
|
||||||
List of column names to be fetched.
|
The columns to return.
|
||||||
Or a dictionary of column names to SQL expressions.
|
|
||||||
All columns are fetched if None or unspecified.
|
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
LanceQueryBuilder
|
LanceQueryBuilder
|
||||||
The LanceQueryBuilder object.
|
The LanceQueryBuilder object.
|
||||||
"""
|
"""
|
||||||
if isinstance(columns, list) or isinstance(columns, dict):
|
self._columns = columns
|
||||||
self._columns = columns
|
|
||||||
else:
|
|
||||||
raise ValueError("columns must be a list or a dictionary")
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def where(self, where: str, prefilter: bool = False) -> LanceQueryBuilder:
|
def where(self, where: str, prefilter: bool = False) -> LanceQueryBuilder:
|
||||||
@@ -397,7 +392,7 @@ class LanceVectorQueryBuilder(LanceQueryBuilder):
|
|||||||
>>> (table.search([0.4, 0.4])
|
>>> (table.search([0.4, 0.4])
|
||||||
... .metric("cosine")
|
... .metric("cosine")
|
||||||
... .where("b < 10")
|
... .where("b < 10")
|
||||||
... .select(["b", "vector"])
|
... .select(["b"])
|
||||||
... .limit(2)
|
... .limit(2)
|
||||||
... .to_pandas())
|
... .to_pandas())
|
||||||
b vector _distance
|
b vector _distance
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
from typing import Iterable, List, Optional, Union
|
from typing import Iterable, List, Optional, Union
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ class RemoteDBConnection(DBConnection):
|
|||||||
api_key: str,
|
api_key: str,
|
||||||
region: str,
|
region: str,
|
||||||
host_override: Optional[str] = None,
|
host_override: Optional[str] = None,
|
||||||
request_thread_pool: Optional[ThreadPoolExecutor] = None,
|
|
||||||
):
|
):
|
||||||
"""Connect to a remote LanceDB database."""
|
"""Connect to a remote LanceDB database."""
|
||||||
parsed = urlparse(db_url)
|
parsed = urlparse(db_url)
|
||||||
@@ -51,7 +49,6 @@ class RemoteDBConnection(DBConnection):
|
|||||||
self._client = RestfulLanceDBClient(
|
self._client = RestfulLanceDBClient(
|
||||||
self.db_name, region, api_key, host_override
|
self.db_name, region, api_key, host_override
|
||||||
)
|
)
|
||||||
self._request_thread_pool = request_thread_pool
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"RemoteConnect(name={self.db_name})"
|
return f"RemoteConnect(name={self.db_name})"
|
||||||
@@ -13,9 +13,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from concurrent.futures import Future
|
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import Dict, Iterable, Optional, Union
|
from typing import Dict, Optional, Union
|
||||||
|
|
||||||
import pyarrow as pa
|
import pyarrow as pa
|
||||||
from lance import json_to_schema
|
from lance import json_to_schema
|
||||||
@@ -271,29 +270,15 @@ class RemoteTable(Table):
|
|||||||
and len(query.vector) > 0
|
and len(query.vector) > 0
|
||||||
and not isinstance(query.vector[0], float)
|
and not isinstance(query.vector[0], float)
|
||||||
):
|
):
|
||||||
if self._conn._request_thread_pool is None:
|
|
||||||
|
|
||||||
def submit(name, q):
|
|
||||||
f = Future()
|
|
||||||
f.set_result(self._conn._client.query(name, q))
|
|
||||||
return f
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
def submit(name, q):
|
|
||||||
return self._conn._request_thread_pool.submit(
|
|
||||||
self._conn._client.query, name, q
|
|
||||||
)
|
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for v in query.vector:
|
for v in query.vector:
|
||||||
v = list(v)
|
v = list(v)
|
||||||
q = query.copy()
|
q = query.copy()
|
||||||
q.vector = v
|
q.vector = v
|
||||||
results.append(submit(self._name, q))
|
results.append(self._conn._client.query(self._name, q))
|
||||||
|
|
||||||
return pa.concat_tables(
|
return pa.concat_tables(
|
||||||
[add_index(r.result().to_arrow(), i) for i, r in enumerate(results)]
|
[add_index(r.to_arrow(), i) for i, r in enumerate(results)]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
result = self._conn._client.query(self._name, query)
|
result = self._conn._client.query(self._name, query)
|
||||||
@@ -474,21 +459,6 @@ class RemoteTable(Table):
|
|||||||
"count_rows() is not yet supported on the LanceDB cloud"
|
"count_rows() is not yet supported on the LanceDB cloud"
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_columns(self, transforms: Dict[str, str]):
|
|
||||||
raise NotImplementedError(
|
|
||||||
"add_columns() is not yet supported on the LanceDB cloud"
|
|
||||||
)
|
|
||||||
|
|
||||||
def alter_columns(self, alterations: Iterable[Dict[str, str]]):
|
|
||||||
raise NotImplementedError(
|
|
||||||
"alter_columns() is not yet supported on the LanceDB cloud"
|
|
||||||
)
|
|
||||||
|
|
||||||
def drop_columns(self, columns: Iterable[str]):
|
|
||||||
raise NotImplementedError(
|
|
||||||
"drop_columns() is not yet supported on the LanceDB cloud"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def add_index(tbl: pa.Table, i: int) -> pa.Table:
|
def add_index(tbl: pa.Table, i: int) -> pa.Table:
|
||||||
return tbl.add_column(
|
return tbl.add_column(
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user