Compare commits

..

9 Commits

Author SHA1 Message Date
Lance Release
1cbfc1bbf4 [python] Bump version: 0.1.13 → 0.1.14 2023-07-20 20:06:15 +00:00
gsilvestrin
a2bb497135 feat(node) Move native packages to @lancedb NPM org (#341)
- Move native packages to @lancedb org
- Move package-lock.json update to a reusable action and created a target to run it manually.
2023-07-20 12:54:39 -07:00
Will Jones
0cf40c8da3 fix: only use util function to build filesystem (#339) 2023-07-20 10:41:50 -07:00
Rob Meng
8233c689c3 fix remote SDK (#342) 2023-07-20 02:01:13 -04:00
gsilvestrin
6e24e731b8 Updating package-lock.json (#338) 2023-07-18 21:10:18 -07:00
Lance Release
f4ce86e12c [python] Bump version: 0.1.12 → 0.1.13 2023-07-19 03:09:50 +00:00
Lance Release
0664eaec82 Bump version: 0.1.14 → 0.1.15 2023-07-19 02:54:10 +00:00
Lei Xu
63acdc2069 [Python] Support pydantic v1 as well (#337)
Support both Pydantic v1 and v2 (breaking changes)
2023-07-18 19:53:09 -07:00
Rob Meng
a636bb1075 add support for host override (#335) 2023-07-18 21:21:39 -04:00
24 changed files with 244 additions and 201 deletions

View File

@@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.1.14 current_version = 0.1.15
commit = True commit = True
message = Bump version: {current_version} → {new_version} message = Bump version: {current_version} → {new_version}
tag = True tag = True

View File

@@ -25,38 +25,25 @@ jobs:
bump-version: bump-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out main - name: Check out main
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: main ref: main
persist-credentials: false fetch-depth: 0
fetch-depth: 0 lfs: true
lfs: true - name: Set git configs for bumpversion
- name: Set git configs for bumpversion shell: bash
shell: bash run: |
run: | git config user.name 'Lance Release'
git config user.name 'Lance Release' git config user.email 'lance-dev@lancedb.com'
git config user.email 'lance-dev@lancedb.com' - name: Set up Python 3.10
- name: Set up Python 3.10 uses: actions/setup-python@v4
uses: actions/setup-python@v4 with:
with: python-version: "3.10"
python-version: "3.10" - name: Bump version, create tag and commit
- name: Bump version, create tag and commit run: |
run: | pip install bump2version
pip install bump2version bumpversion --verbose ${{ inputs.part }}
bumpversion --verbose ${{ inputs.part }} git push
- name: Update package-lock.json file - uses: ./.github/workflows/update_package_lock
run: |
npm install
git add package-lock.json
# Add this change to the commit created by bumpversion
git commit --amend --no-edit
working-directory: node
- name: Push new version and tag
if: ${{ inputs.dry_run }} == "false"
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.LANCEDB_RELEASE_TOKEN }}
branch: main
tags: true

View File

@@ -70,7 +70,7 @@ jobs:
npm run tsc npm run tsc
npm run build npm run build
npm run pack-build npm run pack-build
npm install --no-save ./dist/vectordb-*.tgz npm install --no-save ./dist/lancedb-vectordb-*.tgz
# Remove index.node to test with dependency installed # Remove index.node to test with dependency installed
rm index.node rm index.node
- name: Test - name: Test
@@ -101,7 +101,7 @@ jobs:
npm run tsc npm run tsc
npm run build npm run build
npm run pack-build npm run pack-build
npm install --no-save ./dist/vectordb-*.tgz npm install --no-save ./dist/lancedb-vectordb-*.tgz
# Remove index.node to test with dependency installed # Remove index.node to test with dependency installed
rm index.node rm index.node
- name: Test - name: Test

View File

@@ -35,7 +35,7 @@ jobs:
with: with:
name: node-package name: node-package
path: | path: |
node/vectordb-*.tgz node/lancedb-vectordb-*.tgz
node-macos: node-macos:
runs-on: macos-12 runs-on: macos-12
@@ -46,25 +46,25 @@ jobs:
matrix: matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin] target: [x86_64-apple-darwin, aarch64-apple-darwin]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install system dependencies - name: Install system dependencies
run: brew install protobuf run: brew install protobuf
- name: Install npm dependencies - name: Install npm dependencies
run: | run: |
cd node cd node
npm ci npm ci
- name: Install rustup target - name: Install rustup target
if: ${{ matrix.target == 'aarch64-apple-darwin' }} if: ${{ matrix.target == 'aarch64-apple-darwin' }}
run: rustup target add aarch64-apple-darwin run: rustup target add aarch64-apple-darwin
- name: Build MacOS native node modules - name: Build MacOS native node modules
run: bash ci/build_macos_artifacts.sh ${{ matrix.target }} run: bash ci/build_macos_artifacts.sh ${{ matrix.target }}
- name: Upload Darwin Artifacts - name: Upload Darwin Artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: darwin-native name: native-darwin
path: | path: |
node/dist/vectordb-darwin*.tgz node/dist/lancedb-vectordb-darwin*.tgz
node-linux: node-linux:
name: node-linux (${{ matrix.arch}}-unknown-linux-${{ matrix.libc }}) name: node-linux (${{ matrix.arch}}-unknown-linux-${{ matrix.libc }})
@@ -84,37 +84,37 @@ jobs:
# Building on aarch64 is too slow for now # Building on aarch64 is too slow for now
# - aarch64 # - aarch64
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Change owner to root (for npm) - name: Change owner to root (for npm)
# The docker container is run as root, so we need the files to be owned by root # The docker container is run as root, so we need the files to be owned by root
# Otherwise npm is a nightmare: https://github.com/npm/cli/issues/3773 # Otherwise npm is a nightmare: https://github.com/npm/cli/issues/3773
run: sudo chown -R root:root . run: sudo chown -R root:root .
- name: Set up QEMU - name: Set up QEMU
if: ${{ matrix.arch == 'aarch64' }} if: ${{ matrix.arch == 'aarch64' }}
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
with: with:
platforms: arm64 platforms: arm64
- name: Build Linux GNU native node modules - name: Build Linux GNU native node modules
if: ${{ matrix.libc == 'gnu' }} if: ${{ matrix.libc == 'gnu' }}
run: | run: |
docker run \ docker run \
-v $(pwd):/io -w /io \ -v $(pwd):/io -w /io \
rust:1.70-bookworm \ rust:1.70-bookworm \
bash ci/build_linux_artifacts.sh ${{ matrix.arch }}-unknown-linux-gnu bash ci/build_linux_artifacts.sh ${{ matrix.arch }}-unknown-linux-gnu
- name: Build musl Linux native node modules - name: Build musl Linux native node modules
if: ${{ matrix.libc == 'musl' }} if: ${{ matrix.libc == 'musl' }}
run: | run: |
docker run --platform linux/arm64/v8 \ docker run --platform linux/arm64/v8 \
-v $(pwd):/io -w /io \ -v $(pwd):/io -w /io \
quay.io/pypa/musllinux_1_1_${{ matrix.arch }} \ quay.io/pypa/musllinux_1_1_${{ matrix.arch }} \
bash ci/build_linux_artifacts.sh ${{ matrix.arch }}-unknown-linux-musl bash ci/build_linux_artifacts.sh ${{ matrix.arch }}-unknown-linux-musl
- name: Upload Linux Artifacts - name: Upload Linux Artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: linux-native name: native-linux
path: | path: |
node/dist/vectordb-linux*.tgz node/dist/lancedb-vectordb-linux*.tgz
node-windows: node-windows:
runs-on: windows-2022 runs-on: windows-2022
@@ -145,12 +145,12 @@ jobs:
- name: Upload Windows Artifacts - name: Upload Windows Artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: windows-native name: native-windows
path: | path: |
node/dist/vectordb-win32*.tgz node/dist/lancedb-vectordb-win32*.tgz
release: release:
needs: [node, node-macos, node-linux] needs: [node, node-macos, node-linux, node-windows]
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Only runs on tags that matches the make-release action # Only runs on tags that matches the make-release action
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/v')
@@ -170,3 +170,11 @@ jobs:
for filename in *.tgz; do for filename in *.tgz; do
npm publish $filename npm publish $filename
done done
update-package-lock:
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/workflows/update_package_lock

View File

@@ -0,0 +1,22 @@
name: update_package_lock
description: "Update node's package.lock"
runs:
using: "composite"
steps:
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Set git configs
shell: bash
run: |
git config user.name 'Lance Release'
git config user.email 'lance-dev@lancedb.com'
- name: Update package-lock.json file
working-directory: ./node
run: |
npm install
git add package-lock.json
git commit -m "Updating package-lock.json"
git push
shell: bash

View File

@@ -0,0 +1,12 @@
name: Update package-lock.json
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/workflows/update_package_lock

View File

@@ -11,6 +11,6 @@ arrow-array = "42.0"
arrow-data = "42.0" arrow-data = "42.0"
arrow-schema = "42.0" arrow-schema = "42.0"
arrow-ipc = "42.0" arrow-ipc = "42.0"
half = { "version" = "2.2.1", default-features = false } half = { "version" = "=2.2.1", default-features = false }
object_store = "0.6.1" object_store = "0.6.1"

View File

@@ -17,7 +17,7 @@ const { currentTarget } = require('@neon-rs/load');
let nativeLib; let nativeLib;
try { try {
nativeLib = require(`vectordb-${currentTarget()}`); nativeLib = require(`@lancedb/vectordb-${currentTarget()}`);
} catch (e) { } catch (e) {
try { try {
// Might be developing locally, so try that. But don't expose that error // Might be developing locally, so try that. But don't expose that error
@@ -25,12 +25,12 @@ try {
nativeLib = require("./index.node"); nativeLib = require("./index.node");
} catch { } catch {
throw new Error(`vectordb: failed to load native library. throw new Error(`vectordb: failed to load native library.
You may need to run \`npm install vectordb-${currentTarget()}\`. You may need to run \`npm install @lancedb/vectordb-${currentTarget()}\`.
If that does not work, please file a bug report at https://github.com/lancedb/lancedb/issues If that does not work, please file a bug report at https://github.com/lancedb/lancedb/issues
Source error: ${e}`); Source error: ${e}`);
} }
} }
// Dynamic require for runtime. // Dynamic require for runtime.

68
node/package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "vectordb", "name": "vectordb",
"version": "0.1.14", "version": "0.1.15",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "vectordb", "name": "vectordb",
"version": "0.1.14", "version": "0.1.15",
"cpu": [ "cpu": [
"x64", "x64",
"arm64" "arm64"
@@ -51,11 +51,11 @@
"typescript": "*" "typescript": "*"
}, },
"optionalDependencies": { "optionalDependencies": {
"vectordb-darwin-arm64": "0.1.14", "@lancedb/vectordb-darwin-arm64": "0.1.15",
"vectordb-darwin-x64": "0.1.14", "@lancedb/vectordb-darwin-x64": "0.1.15",
"vectordb-linux-arm64-gnu": "0.1.14", "@lancedb/vectordb-linux-arm64-gnu": "0.1.15",
"vectordb-linux-x64-gnu": "0.1.14", "@lancedb/vectordb-linux-x64-gnu": "0.1.15",
"vectordb-win32-x64-msvc": "0.1.14" "@lancedb/vectordb-win32-x64-msvc": "0.1.15"
} }
}, },
"node_modules/@apache-arrow/ts": { "node_modules/@apache-arrow/ts": {
@@ -4297,42 +4297,6 @@
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
"dev": true "dev": true
}, },
"node_modules/vectordb-darwin-arm64": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.1.14.tgz",
"integrity": "sha512-5doSFMUR4scxseo73thCxScmO3Wpb+cqPsIa7+2uneTEtBSViMbkw/1mGTC+rV4NTCnxhoiqHk9pJzZVeDMkPg==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"darwin"
]
},
"node_modules/vectordb-darwin-x64": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/vectordb-darwin-x64/-/vectordb-darwin-x64-0.1.14.tgz",
"integrity": "sha512-x+qVaKNhAG65HdENL6GRJjxl1hZ7erRm3a2rhplyYoQyzuRPPBILeWzxkE01G1fb0+47dehe7Q4f/8BDaghcCQ==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"darwin"
]
},
"node_modules/vectordb-linux-x64-gnu": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.1.14.tgz",
"integrity": "sha512-hvA2YYwTZK92k6nPH99Jn5N0CwagDOdnwMmjtCpzFOEYK7dY/2kcTOoQNlBwwNP9MYvgN6jdFD/Cwkih1X/qjA==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
]
},
"node_modules/vscode-oniguruma": { "node_modules/vscode-oniguruma": {
"version": "1.7.0", "version": "1.7.0",
"resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz", "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz",
@@ -7638,24 +7602,6 @@
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
"dev": true "dev": true
}, },
"vectordb-darwin-arm64": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.1.14.tgz",
"integrity": "sha512-5doSFMUR4scxseo73thCxScmO3Wpb+cqPsIa7+2uneTEtBSViMbkw/1mGTC+rV4NTCnxhoiqHk9pJzZVeDMkPg==",
"optional": true
},
"vectordb-darwin-x64": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/vectordb-darwin-x64/-/vectordb-darwin-x64-0.1.14.tgz",
"integrity": "sha512-x+qVaKNhAG65HdENL6GRJjxl1hZ7erRm3a2rhplyYoQyzuRPPBILeWzxkE01G1fb0+47dehe7Q4f/8BDaghcCQ==",
"optional": true
},
"vectordb-linux-x64-gnu": {
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.1.14.tgz",
"integrity": "sha512-hvA2YYwTZK92k6nPH99Jn5N0CwagDOdnwMmjtCpzFOEYK7dY/2kcTOoQNlBwwNP9MYvgN6jdFD/Cwkih1X/qjA==",
"optional": true
},
"vscode-oniguruma": { "vscode-oniguruma": {
"version": "1.7.0", "version": "1.7.0",
"resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz", "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz",

View File

@@ -1,6 +1,6 @@
{ {
"name": "vectordb", "name": "vectordb",
"version": "0.1.14", "version": "0.1.15",
"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",
@@ -70,18 +70,18 @@
], ],
"neon": { "neon": {
"targets": { "targets": {
"x86_64-apple-darwin": "vectordb-darwin-x64", "x86_64-apple-darwin": "@lancedb/vectordb-darwin-x64",
"aarch64-apple-darwin": "vectordb-darwin-arm64", "aarch64-apple-darwin": "@lancedb/vectordb-darwin-arm64",
"x86_64-unknown-linux-gnu": "vectordb-linux-x64-gnu", "x86_64-unknown-linux-gnu": "@lancedb/vectordb-linux-x64-gnu",
"aarch64-unknown-linux-gnu": "vectordb-linux-arm64-gnu", "aarch64-unknown-linux-gnu": "@lancedb/vectordb-linux-arm64-gnu",
"x86_64-pc-windows-msvc": "vectordb-win32-x64-msvc" "x86_64-pc-windows-msvc": "@lancedb/vectordb-win32-x64-msvc"
} }
}, },
"optionalDependencies": { "optionalDependencies": {
"vectordb-darwin-arm64": "0.1.14", "@lancedb/vectordb-darwin-arm64": "0.1.15",
"vectordb-darwin-x64": "0.1.14", "@lancedb/vectordb-darwin-x64": "0.1.15",
"vectordb-linux-arm64-gnu": "0.1.14", "@lancedb/vectordb-linux-arm64-gnu": "0.1.15",
"vectordb-linux-x64-gnu": "0.1.14", "@lancedb/vectordb-linux-x64-gnu": "0.1.15",
"vectordb-win32-x64-msvc": "0.1.14" "@lancedb/vectordb-win32-x64-msvc": "0.1.15"
} }
} }

View File

@@ -44,6 +44,9 @@ export interface ConnectionOptions {
apiKey?: string apiKey?: string
// Region to connect // Region to connect
region?: string region?: string
// override the host for the remote connections
hostOverride?: string
} }
/** /**

View File

@@ -19,7 +19,11 @@ import { tableFromIPC, type Table as ArrowTable } from 'apache-arrow'
export class HttpLancedbClient { export class HttpLancedbClient {
private readonly _url: string private readonly _url: string
public constructor (url: string, private readonly _apiKey: string) { public constructor (
url: string,
private readonly _apiKey: string,
private readonly _dbName?: string
) {
this._url = url this._url = url
} }
@@ -37,7 +41,7 @@ export class HttpLancedbClient {
filter?: string filter?: string
): Promise<ArrowTable<any>> { ): Promise<ArrowTable<any>> {
const response = await axios.post( const response = await axios.post(
`${this._url}/v1/table/${tableName}`, `${this._url}/v1/table/${tableName}/query/`,
{ {
vector, vector,
k, k,
@@ -49,7 +53,8 @@ export class HttpLancedbClient {
{ {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'x-api-key': this._apiKey 'x-api-key': this._apiKey,
...(this._dbName !== undefined ? { 'x-lancedb-database': this._dbName } : {})
}, },
responseType: 'arraybuffer', responseType: 'arraybuffer',
timeout: 10000 timeout: 10000

View File

@@ -37,8 +37,13 @@ export class RemoteConnection implements Connection {
} }
this._dbName = opts.uri.slice('db://'.length) this._dbName = opts.uri.slice('db://'.length)
const server = `https://${this._dbName}.${opts.region}.api.lancedb.com` let server: string
this._client = new HttpLancedbClient(server, opts.apiKey) if (opts.hostOverride === undefined) {
server = `https://${this._dbName}.${opts.region}.api.lancedb.com`
} else {
server = opts.hostOverride
}
this._client = new HttpLancedbClient(server, opts.apiKey, opts.hostOverride === undefined ? undefined : this._dbName)
} }
get uri (): string { get uri (): string {

View File

@@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.1.12 current_version = 0.1.14
commit = True commit = True
message = [python] Bump version: {current_version} → {new_version} message = [python] Bump version: {current_version} → {new_version}
tag = True tag = True

View File

@@ -327,6 +327,6 @@ class LanceDBConnection(DBConnection):
name: str name: str
The name of the table. The name of the table.
""" """
filesystem, path = pa.fs.FileSystem.from_uri(self.uri) filesystem, path = fs_from_uri(self.uri)
table_path = os.path.join(path, name + ".lance") table_path = os.path.join(path, name + ".lance")
filesystem.delete_dir(table_path) filesystem.delete_dir(table_path)

View File

@@ -11,7 +11,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.
"""Pydantic adapter for LanceDB""" """Pydantic (v1 / v2) adapter for LanceDB"""
from __future__ import annotations from __future__ import annotations
@@ -19,11 +19,19 @@ import inspect
import sys import sys
import types import types
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Any, List, Type, Union, _GenericAlias from typing import Any, Callable, Dict, Generator, List, Type, Union, _GenericAlias
import numpy as np
import pyarrow as pa import pyarrow as pa
import pydantic import pydantic
from pydantic_core import CoreSchema, core_schema import semver
PYDANTIC_VERSION = semver.Version.parse(pydantic.__version__)
try:
from pydantic_core import CoreSchema, core_schema
except ImportError:
if PYDANTIC_VERSION >= (2,):
raise
class FixedSizeListMixin(ABC): class FixedSizeListMixin(ABC):
@@ -73,6 +81,9 @@ def vector(
# TODO: make a public parameterized type. # TODO: make a public parameterized type.
class FixedSizeList(list, FixedSizeListMixin): class FixedSizeList(list, FixedSizeListMixin):
def __repr__(self):
return f"FixedSizeList(dim={dim})"
@staticmethod @staticmethod
def dim() -> int: def dim() -> int:
return dim return dim
@@ -94,6 +105,25 @@ def vector(
), ),
) )
@classmethod
def __get_validators__(cls) -> Generator[Callable, None, None]:
yield cls.validate
# For pydantic v1
@classmethod
def validate(cls, v):
if not isinstance(v, (list, range, np.ndarray)) or len(v) != dim:
raise TypeError("A list of numbers or numpy.ndarray is needed")
return v
if PYDANTIC_VERSION < (2, 0):
@classmethod
def __modify_schema__(cls, field_schema: Dict[str, Any]):
field_schema["items"] = {"type": "number"}
field_schema["maxItems"] = dim
field_schema["minItems"] = dim
return FixedSizeList return FixedSizeList
@@ -120,11 +150,20 @@ def _py_type_to_arrow_type(py_type: Type[Any]) -> pa.DataType:
) )
def _pydantic_model_to_fields(model: pydantic.BaseModel) -> List[pa.Field]: if PYDANTIC_VERSION.major < 2:
fields = []
for name, field in model.model_fields.items(): def _pydantic_model_to_fields(model: pydantic.BaseModel) -> List[pa.Field]:
fields.append(_pydantic_to_field(name, field)) return [
return fields _pydantic_to_field(name, field) for name, field in model.__fields__.items()
]
else:
def _pydantic_model_to_fields(model: pydantic.BaseModel) -> List[pa.Field]:
return [
_pydantic_to_field(name, field)
for name, field in model.model_fields.items()
]
def _pydantic_to_arrow_type(field: pydantic.fields.FieldInfo) -> pa.DataType: def _pydantic_to_arrow_type(field: pydantic.fields.FieldInfo) -> pa.DataType:

View File

@@ -141,5 +141,7 @@ class RestfulLanceDBClient:
@_check_not_closed @_check_not_closed
async def query(self, table_name: str, query: VectorQuery) -> VectorQueryResult: async def query(self, table_name: str, query: VectorQuery) -> VectorQueryResult:
"""Query a table.""" """Query a table."""
tbl = await self.post(f"/v1/table/{table_name}/", query, deserialize=_read_ipc) tbl = await self.post(
f"/v1/table/{table_name}/query/", query, deserialize=_read_ipc
)
return VectorQueryResult(tbl) return VectorQueryResult(tbl)

View File

@@ -33,13 +33,13 @@ class RemoteTable(Table):
self._name = name self._name = name
def __repr__(self) -> str: def __repr__(self) -> str:
return f"RemoteTable({self._conn.db_name}.{self.name})" return f"RemoteTable({self._conn.db_name}.{self._name})"
@cached_property @cached_property
def schema(self) -> pa.Schema: def schema(self) -> pa.Schema:
"""Return the schema of the table.""" """Return the schema of the table."""
resp = self._conn._loop.run_until_complete( resp = self._conn._loop.run_until_complete(
self._conn._client.get(f"/v1/table/{self._name}/describe") self._conn._client.post(f"/v1/table/{self._name}/describe/")
) )
schema = json_to_schema(resp["schema"]) schema = json_to_schema(resp["schema"])
return schema return schema
@@ -73,7 +73,7 @@ class RemoteTable(Table):
self._conn._loop.run_until_complete( self._conn._loop.run_until_complete(
self._conn._client.post( self._conn._client.post(
f"/v1/table/{self._name}/insert", f"/v1/table/{self._name}/insert/",
data=payload, data=payload,
params={"request_id": request_id, "mode": mode}, params={"request_id": request_id, "mode": mode},
content_type=ARROW_STREAM_CONTENT_TYPE, content_type=ARROW_STREAM_CONTENT_TYPE,

View File

@@ -23,12 +23,12 @@ import numpy as np
import pandas as pd import pandas as pd
import pyarrow as pa import pyarrow as pa
import pyarrow.compute as pc import pyarrow.compute as pc
import pyarrow.fs
from lance import LanceDataset from lance import LanceDataset
from lance.vector import vec_to_table from lance.vector import vec_to_table
from .common import DATA, VEC, VECTOR_COLUMN_NAME from .common import DATA, VEC, VECTOR_COLUMN_NAME
from .query import LanceFtsQueryBuilder, LanceQueryBuilder, Query from .query import LanceFtsQueryBuilder, LanceQueryBuilder, Query
from .util import fs_from_uri
def _sanitize_data(data, schema, on_bad_vectors, fill_value): def _sanitize_data(data, schema, on_bad_vectors, fill_value):
@@ -527,7 +527,7 @@ class LanceTable(Table):
@classmethod @classmethod
def open(cls, db, name): def open(cls, db, name):
tbl = cls(db, name) tbl = cls(db, name)
fs, path = pa.fs.FileSystem.from_uri(tbl._dataset_uri) fs, path = fs_from_uri(tbl._dataset_uri)
file_info = fs.get_file_info(path) file_info = fs.get_file_info(path)
if file_info.type != pa.fs.FileType.Directory: if file_info.type != pa.fs.FileType.Directory:
raise FileNotFoundError( raise FileNotFoundError(

View File

@@ -71,7 +71,8 @@ def fs_from_uri(uri: str) -> Tuple[pa_fs.FileSystem, str]:
Get a PyArrow FileSystem from a URI, handling extra environment variables. Get a PyArrow FileSystem from a URI, handling extra environment variables.
""" """
if get_uri_scheme(uri) == "s3": if get_uri_scheme(uri) == "s3":
if os.environ["AWS_ENDPOINT"]: fs = pa_fs.S3FileSystem(endpoint_override=os.environ.get("AWS_ENDPOINT"))
uri += "?endpoint_override=" + os.environ["AWS_ENDPOINT"] path = get_uri_location(uri)
return fs, path
return pa_fs.FileSystem.from_uri(uri) return pa_fs.FileSystem.from_uri(uri)

View File

@@ -1,7 +1,7 @@
[project] [project]
name = "lancedb" name = "lancedb"
version = "0.1.12" version = "0.1.14"
dependencies = ["pylance~=0.5.8", "ratelimiter", "retry", "tqdm", "aiohttp", "pydantic>=2", "attr"] dependencies = ["pylance~=0.5.8", "ratelimiter", "retry", "tqdm", "aiohttp", "pydantic", "attr", "semver"]
description = "lancedb" description = "lancedb"
authors = [ authors = [
{ name = "LanceDB Devs", email = "dev@lancedb.com" }, { name = "LanceDB Devs", email = "dev@lancedb.com" },
@@ -52,3 +52,6 @@ requires = [
"wheel", "wheel",
] ]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[tool.isort]
profile = "black"

View File

@@ -20,7 +20,7 @@ import pyarrow as pa
import pydantic import pydantic
import pytest import pytest
from lancedb.pydantic import pydantic_to_schema, vector from lancedb.pydantic import PYDANTIC_VERSION, pydantic_to_schema, vector
@pytest.mark.skipif( @pytest.mark.skipif(
@@ -111,10 +111,16 @@ def test_fixed_size_list_field():
li: List[int] li: List[int]
data = TestModel(vec=list(range(16)), li=[1, 2, 3]) data = TestModel(vec=list(range(16)), li=[1, 2, 3])
assert json.loads(data.model_dump_json()) == { if PYDANTIC_VERSION >= (2,):
"vec": list(range(16)), assert json.loads(data.model_dump_json()) == {
"li": [1, 2, 3], "vec": list(range(16)),
} "li": [1, 2, 3],
}
else:
assert data.dict() == {
"vec": list(range(16)),
"li": [1, 2, 3],
}
schema = pydantic_to_schema(TestModel) schema = pydantic_to_schema(TestModel)
assert schema == pa.schema( assert schema == pa.schema(
@@ -124,7 +130,11 @@ def test_fixed_size_list_field():
] ]
) )
json_schema = TestModel.model_json_schema() if PYDANTIC_VERSION >= (2,):
json_schema = TestModel.model_json_schema()
else:
json_schema = TestModel.schema()
assert json_schema == { assert json_schema == {
"properties": { "properties": {
"vec": { "vec": {

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "vectordb-node" name = "vectordb-node"
version = "0.1.14" version = "0.1.15"
description = "Serverless, low-latency vector database for AI applications" description = "Serverless, low-latency vector database for AI applications"
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "vectordb" name = "vectordb"
version = "0.1.14" version = "0.1.15"
edition = "2021" edition = "2021"
description = "Serverless, low-latency vector database for AI applications" description = "Serverless, low-latency vector database for AI applications"
license = "Apache-2.0" license = "Apache-2.0"