From 88f6ae7cd1e1ae391452fd7a9fceaca87d3648c4 Mon Sep 17 00:00:00 2001 From: qzhu Date: Wed, 3 Jan 2024 15:59:30 -0800 Subject: [PATCH] fix example code --- .github/workflows/docs_test.yml | 3 +++ docs/src/ann_indexes.md | 2 ++ docs/src/javascript/saas-modules.md | 29 +++++++++++++++++------------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docs_test.yml b/.github/workflows/docs_test.yml index 084d563b..661e954f 100644 --- a/.github/workflows/docs_test.yml +++ b/.github/workflows/docs_test.yml @@ -88,6 +88,9 @@ jobs: cd docs/test node md_testing.js - name: Test + env: + LANCEDB_URI: ${{ secrets.LANCEDB_URI }} + LANCEDB_DEV_API_KEY: ${{ secrets.LANCEDB_DEV_API_KEY }} run: | cd docs/test/node for d in *; do cd "$d"; echo "$d".js; node "$d".js; cd ..; done diff --git a/docs/src/ann_indexes.md b/docs/src/ann_indexes.md index 6e9b7ac3..13b59d40 100644 --- a/docs/src/ann_indexes.md +++ b/docs/src/ann_indexes.md @@ -164,6 +164,7 @@ You can further filter the elements returned by a search using a where clause. const results_2 = await table .search(Array(1536).fill(1.2)) .where("id != '1141'") + .limit(2) .execute() ``` @@ -187,6 +188,7 @@ You can select the columns returned by the query using a select clause. const results_3 = await table .search(Array(1536).fill(1.2)) .select(["id"]) + .limit(2) .execute() ``` diff --git a/docs/src/javascript/saas-modules.md b/docs/src/javascript/saas-modules.md index 08318e7b..22253972 100644 --- a/docs/src/javascript/saas-modules.md +++ b/docs/src/javascript/saas-modules.md @@ -37,15 +37,20 @@ yet support Windows or musl-based Linux (such as Alpine Linux). ## Example code ```javascript -// connect to a remote DB + const lancedb = require('vectordb'); +const { Schema, Field, Int32, Float32, Utf8, FixedSizeList } = require ("apache-arrow/Arrow.node") + +// connect to a remote DB +const devApiKey = process.env.LANCEDB_DEV_API_KEY +const dbURI = process.env.LANCEDB_URI const db = await lancedb.connect({ - uri: "db://your-project-name", - apiKey: "sk_...", - region: "us-east-1" + uri: dbURI, // replace dbURI with your project, e.g. "db://your-project-name" + apiKey: devApiKey, // replace dbURI with your api key + region: "us-east-1-dev" }); // create a new table -const tableName = "my_table" +const tableName = "my_table_000" const data = [ { id: 1, vector: [0.1, 1.0], item: "foo", price: 10.0 }, { id: 2, vector: [3.9, 0.5], item: "bar", price: 20.0 } @@ -54,15 +59,15 @@ const schema = new Schema( [ new Field('id', new Int32()), new Field('vector', new FixedSizeList(2, new Field('float32', new Float32()))), - new Field('item', new String()), + new Field('item', new Utf8()), new Field('price', new Float32()) ] ) -const table = await db.createTable( - tableName, +const table = await db.createTable({ + name: tableName, schema, - data -) +}, data) + // list the table const tableNames_1 = await db.tableNames('') // add some data and search should be okay @@ -73,8 +78,8 @@ const newData = [ table.add(newData) // create the index for the table await table.createIndex({ - metric_type: 'L2', - column: 'vector' + metric_type: "L2", + column: "vector" }) let result = await table.search([2.8, 4.3]).select(["vector", "price"]).limit(1).execute() // update the data