Skip to content

About

Official TypeScript client for Weaviate, the open-source vector database. Use @weaviate/node for Node.js and @weaviate/web for browsers and edge runtimes. Manage collections and run vector, keyword and hybrid search.

Topics

Resources

Code of conduct

Stars

102 stars

Watchers

11 watching

Forks

Latest commit

 

History

888 Commits

Folders and files

Repository files navigation

Weaviate TypeScript client Weaviate logo

The official JavaScript and TypeScript client for Weaviate, the open-source vector database.

npm Build Status License

Packages

Package Use it for Runtime
@weaviate/node Server-side apps, scripts and data ingestion. Talks to Weaviate over REST and gRPC. Node.js
@weaviate/web Apps that run in a browser or an edge runtime. Talks to Weaviate over REST and gRPC-Web. Browsers and edge runtimes
@weaviate/core Shared code used by both clients. It is installed for you, so do not install it directly. Node.js, browsers and edge runtimes

For Weaviate Agents such as the Query Agent, use the companion package @weaviate/agents.

Install

npm install @weaviate/node
# or: pnpm add @weaviate/node, yarn add @weaviate/node, bun add @weaviate/node

For browsers and edge runtimes, install @weaviate/web instead.

@weaviate/node needs Node.js 22 or later. It supports both ES modules (import) and CommonJS (require).

Quickstart

This example needs a local Weaviate with no vectorizer module. See Run Weaviate with Docker. The example brings its own vectors and searches with nearVector.

import weaviate from '@weaviate/node';

const client = await weaviate.connectToLocal();

if (await client.collections.exists('Article')) {
  await client.collections.delete('Article');
}

const articles = await client.collections.create({
  name: 'Article',
  properties: [{ name: 'title', dataType: weaviate.configure.dataType.TEXT }],
  vectorizers: weaviate.configure.vectors.selfProvided(),
});

await articles.data.insertMany([
  { properties: { title: 'Intro to vector search' }, vectors: [0.1, 0.9, 0.2] },
  { properties: { title: 'Tuning HNSW indexes' }, vectors: [0.8, 0.1, 0.3] },
]);

const result = await articles.query.nearVector([0.2, 0.8, 0.1], {
  limit: 1,
  returnMetadata: ['distance'],
});

for (const obj of result.objects) {
  console.log(obj.properties.title, obj.metadata?.distance);
}

await client.close();

The example uses top-level await, so run it as an ES module. For example, save it as quickstart.mts and run npx tsx quickstart.mts.

With CommonJS, load the client with require and wrap the code in an async function:

const weaviate = require('@weaviate/node').default;

async function main() {
  const client = await weaviate.connectToLocal();
  // The rest of the quickstart goes here.
  await client.close();
}

main();

To connect to Weaviate Cloud, replace the connectToLocal() call. Set WEAVIATE_URL and WEAVIATE_API_KEY in your environment first.

const client = await weaviate.connectToWeaviateCloud(process.env.WEAVIATE_URL!, {
  authCredentials: new weaviate.ApiKey(process.env.WEAVIATE_API_KEY!),
});

Use in the browser and edge runtimes

@weaviate/web is generally available. Use it in browsers and in edge runtimes such as Cloudflare Workers and Vercel. Its API is mostly the same as @weaviate/node, with the differences below. For details, see the web client docs.

import weaviate from '@weaviate/web';

const client = await weaviate.connectToLocal();

Keep these points in mind:

  • gRPC requests use gRPC-Web on the HTTP host and port, at the /v1/grpc-web path. You do not configure a separate gRPC port.
  • The gRPC connection options grpcHost, grpcPort and grpcSecure do not apply.
  • Server-side batching is not available. client.batch.stream() and collection.data.ingest() throw. Use collection.data.insertMany() instead.
  • Anyone who loads your page can read the keys in your bundle. Never ship an admin key to a browser. Use a read-only API key that has only the RBAC permissions your app needs.
  • Browser requests are subject to CORS, so the Weaviate server must allow your page's origin. On Weaviate Cloud, turn on the Allow all CORS origins setting for the database. See default settings. Server-side code, such as edge functions or Node.js, does not need this.

Compatibility

To check which Weaviate versions a client release supports, see the version table in the docs.

Migrating from an older package

@weaviate/node is the new name of the weaviate-client package. The API is the same. Swap the dependency and update your imports.

npm uninstall weaviate-client
npm install @weaviate/node
// Before
import weaviate from 'weaviate-client';
// After
import weaviate from '@weaviate/node';

If you are moving from the v2 client (weaviate-ts-client), follow the v2 to v3 migration guide.

Documentation

Support

Contributing

Read the contributing guide before you open a pull request.

The repository is a pnpm workspace. To build the packages and run the tests:

pnpm install
pnpm build

# Start the Weaviate test stack in Docker, run the tests, then stop the stack.
# <version> is a Weaviate release without the leading "v".
# Starts several Weaviate containers on ports 8078-8091, 9999-10001 and 50049-50062
ci/run_dependencies.sh <version>
WEAVIATE_VERSION=<version> pnpm test
ci/stop_dependencies.sh <version>

License

BSD-3-Clause. See LICENSE.

About

Official TypeScript client for Weaviate, the open-source vector database. Use @weaviate/node for Node.js and @weaviate/web for browsers and edge runtimes. Manage collections and run vector, keyword and hybrid search.

Topics

Resources

Code of conduct

Stars

102 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages