| 1 | # LanceDB JavaScript SDK |
| 2 | |
| 3 | A JavaScript library for [LanceDB](https://github.com/lancedb/lancedb). |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | npm install @lancedb/lancedb |
| 9 | ``` |
| 10 | |
| 11 | This will download the appropriate native library for your platform. We currently |
| 12 | support: |
| 13 | |
| 14 | - Linux (x86_64 and aarch64) |
| 15 | - MacOS (Intel and ARM/M1/M2) |
| 16 | - Windows (x86_64 only) |
| 17 | |
| 18 | We do not yet support musl-based Linux (such as Alpine Linux) or aarch64 Windows. |
| 19 | |
| 20 | ## Usage |
| 21 | |
| 22 | ### Basic Example |
| 23 | |
| 24 | ```javascript |
| 25 | import * as lancedb from "@lancedb/lancedb"; |
| 26 | const db = await lancedb.connect("data/sample-lancedb"); |
| 27 | const table = await db.createTable("my_table", [ |
| 28 | { id: 1, vector: [0.1, 1.0], item: "foo", price: 10.0 }, |
| 29 | { id: 2, vector: [3.9, 0.5], item: "bar", price: 20.0 }, |
| 30 | ]); |
| 31 | const results = await table.vectorSearch([0.1, 0.3]).limit(20).toArray(); |
| 32 | console.log(results); |
| 33 | ``` |
| 34 | |
| 35 | The [quickstart](../basic.md) contains a more complete example. |
| 36 | |
| 37 | ## Development |
| 38 | |
| 39 | ```sh |
| 40 | npm run build |
| 41 | npm run test |
| 42 | ``` |
| 43 | |
| 44 | ### Running lint / format |
| 45 | |
| 46 | LanceDb uses [biome](https://biomejs.dev/) for linting and formatting. if you are using VSCode you will need to install the official [Biome](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) extension. |
| 47 | To manually lint your code you can run: |
| 48 | |
| 49 | ```sh |
| 50 | npm run lint |
| 51 | ``` |
| 52 | |
| 53 | to automatically fix all fixable issues: |
| 54 | |
| 55 | ```sh |
| 56 | npm run lint-fix |
| 57 | ``` |
| 58 | |
| 59 | If you do not have your workspace root set to the `nodejs` directory, unfortunately the extension will not work. You can still run the linting and formatting commands manually. |
| 60 | |
| 61 | ### Generating docs |
| 62 | |
| 63 | ```sh |
| 64 | npm run docs |
| 65 | |
| 66 | cd ../docs |
| 67 | # Asssume the virtual environment was created |
| 68 | # python3 -m venv venv |
| 69 | # pip install -r requirements.txt |
| 70 | . ./venv/bin/activate |
| 71 | mkdocs build |
| 72 | ``` |