Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues for cloud js example #291

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions examples/js-transformers/lancedb_cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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))
}

Expand Down
9 changes: 5 additions & 4 deletions examples/js-transformers/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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');
```
Expand Down Expand Up @@ -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
Expand Down
Loading