Files
lancedb/docs
Nishil Rathod 84fc48198b docs: add guide for using LanceDB in VS Code extensions
Closes #1849

This was lancedb/docs#371. After lancedb/docs#355 moved the open-source pages, their navigation and the snippet tests into this repository's `docs/web` and `docs/web-tests`, that PR could no longer merge there, so I've moved the same change here.

## Why

#1849 asks for an example of LanceDB in a VS Code extension, because people kept running into problems there (#927, #1713). An earlier attempt, #3682, added a README link. @prrao87 asked for something else instead: a quick guide on the docs site, under **Integrations › AI Platforms & Frameworks**, showing how to use LanceDB in an extension and what results look like. The author of #3682 agreed and closed it. This PR is that guide.

## What it adds

- **`docs/web/integrations/ai/vscode.mdx`**: a new page, also added to `docs/web/docs.json`. It builds a small extension with two commands. One indexes the workspace's Markdown into a LanceDB table using the built-in `huggingface` embedding function, so no API key is needed. The other searches it by meaning. The page covers the parts that are specific to VS Code:
  - storing the table under `context.storageUri` instead of a relative path, which is the cause of #927;
  - `@types/node` ≥ 22 and `skipLibCheck`, which covers #1713 and the DOM-type errors from `apache-arrow`/onnxruntime typings;
  - pinning `apache-arrow` inside LanceDB's peer range;
  - marking `@lancedb/lancedb` and `@huggingface/transformers` as esbuild externals, and removing `node_modules/**` from the template's `.vscodeignore`;
  - storing each file's URI so a hit opens in the right folder of a multi-root workspace;
  - building one VSIX per platform with `vsce package --target`, with a table mapping each target to LanceDB's native package, and a note that the sample's local model (via `onnxruntime-node`) doesn't run on Alpine;
  - keeping the Transformers.js model cache in `globalStorageUri`, which only works if it's loaded with `import()`;
  - a troubleshooting table listing each error message with its cause and fix.
- **`docs/web-tests/ts/vscode_search.ts`** and **`vscode_search.test.ts`**: the LanceDB code the page shows (connect, chunk, index, search), plus jest tests for it.
- **`docs/web-tests/ts/vscode_extension.ts`**: the extension's `src/extension.ts`. Jest can't run it because it needs the VS Code extension host, so it was tested in a real extension instead (see below). This follows the precedent of `integrations.ts`.
- **`docs/web/snippets/vscode_search.mdx`** and **`vscode_extension.mdx`**: generated with the command in CONTRIBUTING.md.

## Changes from lancedb/docs#371

- **New paths only.** The page, tests and snippets are the same content, at their paths in this repository.
- **One link.** `/tables/update` doesn't exist under `docs/web`, so the `mergeInsert` link now points to `/ingestion/merge-insert`.
- **Heading anchors.** Every heading now has an explicit `{#anchor}`, as CONTRIBUTING.md asks.

## How I tested it

- **Snippet tests.** In this repository at `c2c8269f`, `vscode_search.test.ts` passes (2 tests) with the pinned `@lancedb/lancedb` 0.31.0. On Windows the `npm test` script fails before it starts, because it runs `node` on the `.bin/jest` shell shim. I ran `node --experimental-vm-modules node_modules/jest/bin/jest.js --testEnvironment jest-environment-node-single-context vscode_search` instead.
- **Lint.** `biome ci` is clean for the three new files, and they carry the SPDX header that `license-header-check.yml` looks for.
- **Snippets.** I regenerated them with CONTRIBUTING.md's command, `mdx_snippets_gen.py -s docs/web-tests/py -s docs/web-tests/ts -s docs/web-tests/rs -o docs/web/snippets`, run with `python` since I don't have `uv`. It reproduces the two new snippet files exactly, once the Windows CRLF endings are normalised. As CONTRIBUTING.md warns, it also rewrites `build_with_ai_agents.mdx`, `integrations.mdx`, `search.mdx` and `storage.mdx`. I left those out.
- **Links.** `mint broken-links` from `docs/web` reports no entries on the new page, and its three internal links (`/embedding/quickstart`, `/ingestion/merge-insert`, `/search/full-text-search`) resolve to pages here.
- **Real extension.** I built a sample extension from exactly the code on the page, scaffolded with `yo code` (TypeScript + esbuild) and using `@lancedb/lancedb` 0.39.0. I ran it with `@vscode/test-cli` in VS Code 1.140 on Windows x64. The integration test runs both commands against a six-file workspace and checks the top hits. The "Sample results" block on the page is copied from that run, and after the review fixes below it reproduces line for line in VS Code 1.141.
- **Multi-root workspace.** A second test configuration opens two folders that both contain `docs/auth.md`. It types a query and picks the top hit through the real picker, then checks that the right folder's file opens at the right line. It fails on the code before the review fix and passes after it.
- **Packaged VSIX.** I packaged `vsce package --target win32-x64` (200 MB, or 148 MB with the onnxruntime trimming in the Tip). Then I unpacked it outside the project and ran the same tests against the unpacked copy, so they couldn't pick up the project's `node_modules`. They pass.
- **Negative checks behind the troubleshooting rows:**
  - With `node_modules/**` left in `.vscodeignore`, activation fails with `Cannot find module '@lancedb/lancedb'` and the commands report `command '…' not found`.
  - Without the externals, esbuild fails with `No loader is configured for ".node" files`.
  - Installing LanceDB into a project that already has `apache-arrow` 21 fails with `ERESOLVE`.
  - `require("@huggingface/transformers")` returns a different `env` object from `import()`.
- **Rendering.** For lancedb/docs#371, `mint dev` rendered the page, its 14 code blocks and the sidebar entry. I haven't re-rendered it from `docs/web`; only the paths, one link and the heading anchors changed.

**Not tested:**
- macOS. I couldn't reproduce the read-only working directory from #927; the page's fix (an absolute storage path) doesn't depend on the OS.
- Linux and macOS VSIX builds.

## Notes for reviewers

- I added `_distance` to `.select(...)`, because LanceDB warns that it will stop adding the column automatically.

## AI disclosure

I used Claude Code to research the issue and its history, write the sample extension, the tests and this page, move the change here, and draft this description. I ran every check listed above myself, and the outputs quoted on the page come from those runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-10-29 05:25:00 +08:00
..

LanceDB Documentation

For website guides in docs/web, start with Documentation in CONTRIBUTING.md. That covers editing pages, generated examples, previews, availability and drafts.

This page covers the SDK reference in docs/src, built with MkDocs. Its GitHub Actions workflow builds and deploys on pushes to main, so it can include unreleased APIs. That is separate from the release editions of the Mintlify website.

Building the docs

Setup

  1. Install LanceDB Python. See setup in Python contributing guide. Run make develop to install the Python package.
  2. Install documentation dependencies. From LanceDB repo root: pip install -r docs/requirements.txt

Preview the docs

Run these commands from the LanceDB repository root. The subshell changes into docs to load mkdocs.yml, while leaving your shell in the repository root.

(cd docs && PYTHONPATH=. mkdocs serve)

If you want to just generate the HTML files:

(cd docs && PYTHONPATH=. mkdocs build)

If successful, you should see a docs/site directory in the repository root that you can verify locally.

Adding examples

To make sure examples are correct, we put examples in test files so they can be run as part of our test suites.

You can see the tests are at:

  • Python: python/python/tests/docs
  • Typescript: nodejs/examples/

Checking python examples

cd python
pytest -vv python/tests/docs

Checking typescript examples

The examples depend on @lancedb/lancedb at file:../dist, so the package must be built before running the tests. This uses pnpm; see the Typescript contributing guide for the toolchain setup.

pushd nodejs
pnpm install
pnpm build
popd

Then you can run the examples by going to the nodejs/examples directory, which is a separate pnpm package with its own lockfile:

pushd nodejs/examples
pnpm install
pnpm test
popd

API documentation

Python

The Python API documentation is organized based on the file docs/src/python/python.md. We manually add entries there so we can control the organization of the reference page. However, this means any new types must be manually added to the file. No additional steps are needed to generate the API documentation.

Typescript

The typescript API documentation is generated from the typescript source code using typedoc.

When new APIs are added, you must manually re-run the typedoc command to update the API documentation. The new files should be checked into the repository.

pushd nodejs
# `pnpm docs` would invoke pnpm's built-in `docs` command, not the script.
pnpm run docs
popd