fix example code

This commit is contained in:
qzhu
2024-01-03 15:59:30 -08:00
parent f2d90331a4
commit 88f6ae7cd1
3 changed files with 22 additions and 12 deletions

View File

@@ -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

View File

@@ -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()
```

View File

@@ -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