Compare commits

...

2 Commits

Author SHA1 Message Date
qzhu
9a066f9330 fix a bug 2024-01-04 13:47:07 -08:00
qzhu
88f6ae7cd1 fix example code 2024-01-03 15:59:30 -08:00
3 changed files with 24 additions and 13 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,21 @@ 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
console.log(devApiKey)
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 +60,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
@@ -70,11 +76,11 @@ const newData = [
{ id: 3, vector: [10.3, 1.9], item: "test1", price: 30.0 },
{ id: 4, vector: [6.2, 9.2], item: "test2", price: 40.0 }
]
table.add(newData)
await 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