Qdrant JavaScript/TypeScript SDK

repository·master·Indexed 19 days ago

https://github.com/qdrant/qdrant-js

A JavaScript/TypeScript SDK for the Qdrant vector search engine. It provides clients for both REST and gRPC protocols via the @qdrant/qdrant-js, @qdrant/js-client-rest, and @qdrant/js-client-grpc packages. The SDK supports Node.js (>= 18.0.0), Deno, Browser (via fetch API), and Cloudflare Workers.

Tokens
38.3K
Snippets
111
Records
209
Agent score
65%

What's inside qdrant-js

  1. Choosing between REST and gRPC clients

    master

    REST Client

    • Best for: Initial development, debugging, and small-size requests.
    • Characteristics: Based on OpenAPI; easier to inspect and debug.

    gRPC Client

    • Best for: High-performance production environments and large data chunks.
    • Characteristics: More efficient 'on the wire' for big data, though it incurs a small conversion cost. For very small requests, REST may perform similarly or better than gRPC.
  2. Configure npm Trusted Publishing

    master

    The SDK uses GitHub Actions with trusted publishing to publish to npm without needing an NPM_TOKEN.

    In the npmjs.com settings for @qdrant/js-client-rest, @qdrant/js-client-grpc, and @qdrant/qdrant-js, configure the following under Settings → Trusted publishing → GitHub Actions:

    FieldValue
    Organization or userqdrant
    Repositoryqdrant-js
    Workflow filenamerelease.yaml
    Environment name(empty)
    Allowed actionsnpm publish

    Workflow Requirements:

    • The release job must have permissions: id-token: write.
    • Use pnpm >= 11.1.x (earlier versions had OIDC exchange bugs).
    • Ensure pnpm/action-setup is >= v6.0.6.
    • Do not include _authToken in .npmrc or set registry-url in actions/setup-node.
    • The repository.url in each package.json must match the actual repository URL.
  3. Generate the REST client

    master

    To update the REST client, navigate to the REST client directory and run the OpenAPI codegen script.

    By default, the OpenAPI schema is pulled from the dev branch of the Qdrant repository. You can modify the source URL in packages/js-client-rest/package.json under config.openapi_schema_remote if you need to target a different branch (e.g., master).

    Generated files include:

    • src/openapi/generated_schema.ts
    • src/openapi/generated_client_type.ts
    • src/openapi/genetated_api_client.ts
    cd packages/js-client-rest
    pnpm codegen:openapi-typescript
  4. Install the Qdrant JS SDK

    master

    You can install the lightweight REST client for Qdrant using your preferred package manager. The main package is @qdrant/js-client-rest.

    pnpm i @qdrant/js-client-rest
    # or
    npm install @qdrant/js-client-rest
    # or
    yarn add @qdrant/js-client-rest
  5. Update version numbers in the monorepo

    master

    When releasing, you must update the version string across all relevant files (package.json, client-version.ts, CHANGELOG.md, etc.).

    To find all files containing a specific version (e.g., 1.15.0), use:

    grep -rn --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=.git '1\.15\.0'

    To quickly edit all identified files using vi:

    for i in $(grep -rn --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=.git '1\.15\.0' | cut -d ':'  -f1 | uniq); do vi $i;done

    Important files to update:

    • package.json (version and workspace dependencies)
    • src/client-version.ts (PACKAGE_VERSION)
    • CHANGELOG.md (New entries)
    • scripts/integration-tests.sh (QDRANT_LATEST)
    • examples/**/package.json (SDK version constraint)
  6. Connect to Qdrant Cloud

    master

    To connect to a managed Qdrant Cloud instance, initialize the QdrantClient with your specific Cloud url and your apiKey. You can obtain your API key from the Qdrant Cloud console.

    import {QdrantClient} from '@qdrant/js-client-rest';
    
    const client = new QdrantClient({
        url: 'https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.us-east-0-1.aws.cloud.qdrant.io',
        apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    });
  7. Release a new version of Qdrant JS SDK

    master

    Releasing a new version of the Qdrant JS SDK involves generating new clients from the Qdrant server schemas (gRPC and REST), updating the SDK code to match the new API, updating version numbers across the monorepo, and publishing via GitHub Actions using trusted publishing.

    Pre-requisites

    • Node.js 18 or higher
    • pnpm 10

    Install dependencies:

    pnpm install
  8. Import the REST or gRPC client

    master

    The SDK provides two types of clients. The REST client is the default entry point and is recommended for initial development due to ease of debugging. The gRPC client is available via a subpath and is optimized for high-performance scenarios involving large data chunks.

    import {QdrantClient} from '@qdrant/qdrant-js'; // REST client
    
    import {QdrantClient} from '@qdrant/qdrant-js/grpc'; // gRPC client