Skip to content

Instantly share code, notes, and snippets.

@gsilvestrin
Created June 2, 2023 16:46
Show Gist options
  • Save gsilvestrin/b04d5a4688af5197652ea4fd0bfe8465 to your computer and use it in GitHub Desktop.
Save gsilvestrin/b04d5a4688af5197652ea4fd0bfe8465 to your computer and use it in GitHub Desktop.
// Copyright 2023 Lance Developers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as vectordb from 'vectordb';
type Data = {vector: number[], id: string, content: string, longId: string }
async function example () {
const db = await vectordb.connect('data/sample-lancedb')
let data: Data[] = [
{ vector: Array(1536).fill(1.2), id: '1', content: "", longId: "1" },
]
const table = await db.createTable('vectors', data)
for (let i = 0; i < 10; i++) {
console.log(`Batch ${i}`)
let data: Data[] = []
for (let j = 0; j < 100_000; j++) {
data.push({vector: Array(1536).fill(i * j), id: `${j}`, content: "", longId: `${j}`},)
}
await table.add(data)
}
const results = await table
.search(Array(1536).fill(1.2))
.limit(20)
.execute()
console.log(results)
}
example().then(_ => { console.log ("All done!") })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment