Files
lancedb/docs/src/javascript/saas-modules.md
2024-01-12 09:45:36 +01:00

2.7 KiB

Table of contents

Installation

npm install vectordb

This will download the appropriate native library for your platform. We currently support x86_64 Linux, aarch64 Linux, Intel MacOS, and ARM (M1/M2) MacOS. We do not yet support Windows or musl-based Linux (such as Alpine Linux).

Classes

Methods

Example code


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: 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_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 }
]
const schema = new Schema(
    [
        new Field('id', new Int32()), 
        new Field('vector', new FixedSizeList(2, new Field('float32', new Float32()))),
        new Field('item', new Utf8()),
        new Field('price', new Float32())
    ]
)
const table = await db.createTable({
    name: tableName,
    schema,
}, data)

// list the table
const tableNames_1 = await db.tableNames('')
// add some data and search should be okay
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)
// create the index for the table
await table.createIndex({
      metric_type: "L2", 
      column: "vector"
})
let result = await table.search([2.8, 4.3]).select(["vector", "price"]).limit(1).execute()
// update the data
await table.update({ 
      where: "id == 1", 
      values: { item: "foo1" } 
})
//drop the table
await db.dropTable(tableName)