From b0022507f842b85da8f31cdce45672333c247422 Mon Sep 17 00:00:00 2001 From: qzhu Date: Mon, 20 Jan 2025 13:31:18 -0800 Subject: [PATCH] fix issues for cloud js example --- examples/js-transformers/lancedb_cloud/index.js | 9 ++++----- examples/js-transformers/walkthrough.md | 9 +++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/js-transformers/lancedb_cloud/index.js b/examples/js-transformers/lancedb_cloud/index.js index 7a63661..f7474a2 100644 --- a/examples/js-transformers/lancedb_cloud/index.js +++ b/examples/js-transformers/lancedb_cloud/index.js @@ -14,11 +14,10 @@ 'use strict' +import * as lancedb from "@lancedb/lancedb" async function example() { - - const lancedb = require('vectordb') - + // Import transformers and the all-MiniLM-L6-v2 model (https://huggingface.co/Xenova/all-MiniLM-L6-v2) const { pipeline } = await import('@xenova/transformers') const pipe = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2'); @@ -64,9 +63,9 @@ async function example() { let query = (await embed_fun.embed(['a sweet fruit to eat']))[0] const results = await table .search(query) - .metricType("cosine") + .distanceType("cosine") .limit(2) - .execute() + .toArray() console.log(results.map(r => r.text)) } diff --git a/examples/js-transformers/walkthrough.md b/examples/js-transformers/walkthrough.md index a36fd11..97504fb 100644 --- a/examples/js-transformers/walkthrough.md +++ b/examples/js-transformers/walkthrough.md @@ -8,7 +8,7 @@ This example shows how to use the [transformers.js](https://github.com/xenova/tr ### Setting up First, install the dependencies: ```bash -npm install vectordb +npm install @lancedb/lancedb npm i @xenova/transformers ``` @@ -17,7 +17,8 @@ We will also be using the [all-MiniLM-L6-v2](https://huggingface.co/Xenova/all-M Within our `index.js` file we will import the necessary libraries and define our model and database: ```javascript -const lancedb = require('vectordb') +import * as lancedb from "@lancedb/lancedb" + const { pipeline } = await import('@xenova/transformers') const pipe = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2'); ``` @@ -75,9 +76,9 @@ Now, we can perform the search using the `search` function. LanceDB automaticall // Query the table const results = await table .search("a sweet fruit to eat") - .metricType("cosine") + .distanceType("cosine") .limit(2) - .execute() + .toArray() console.log(results.map(r => r.text)) ``` ```bash