Skip to content

Commit

Permalink
gRPC client + project setup overhaul (#24)
Browse files Browse the repository at this point in the history
- Generated gRPC client based on plugins from @bufbuild
- REST client accepts maxConnections now using undici.js agent for fetch
- Updated OAS definitions and improved generated types
- Improved NPM dependency management in monorepo
- Improved linting and tooling setup
- Added CI check to avoid bumping a version of clients too early
  • Loading branch information
Rendez authored Jun 2, 2023
1 parent 5413e88 commit fb009e1
Show file tree
Hide file tree
Showing 137 changed files with 19,218 additions and 1,181 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-days-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@qdrant/js-client-grpc': patch
'@qdrant/js-client-rest': patch
'@qdrant/qdrant-js': patch
---

Added gRPC client
32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"root": true,
"env": {
"node": true
},
"ignorePatterns": ["**/node_modules/**", "scripts/*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.base.json"]
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/strict"
],
"rules": {
"object-shorthand": "warn",
"arrow-body-style": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "all",
"argsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
],
"@typescript-eslint/consistent-type-definitions": "off"
}
}
17 changes: 10 additions & 7 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- uses: pnpm/action-setup@v2
with:
Expand All @@ -36,18 +36,21 @@ jobs:
env:
CI: 1

- name: Open API schema changes
- name: Generated OpenAPI update check
run: |
pnpm --filter "@qdrant/js-client-rest" codegen:openapi-typescript
if ( git diff-index HEAD | grep -q README.md || exit ) then
echo "Generated schema changed. Please update with pnpm -r codegen:openapi-typescript.";
if ( git diff --name-only | grep -q packages/js-client-rest/src/openapi/ || exit ) then
echo "Generated schema changed. Please update with: 'pnpm -r codegen:openapi-typescript'.";
exit 1
fi
shell: bash

- name: Run checks
- name: Project checks
run: pnpm -r pre-check

- name: Open API integration tests
run: cd packages/js-client-rest && ./tests/integration-tests.sh
- name: Integration tests
run: packages/qdrant-js/scripts/integration-tests.sh
shell: bash
env:
QDRANT_URL: ${{ secrets.QDRANT_URL }}
QDRANT_API_KEY: ${{ secrets.QDRANT_API_KEY }}
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
**/node_modules/
**/dist/
**/src/openapi/
**/src/proto/
**/pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.workingDirectories": ["packages/js-client-rest", "packages/js-client-grpc"]
"eslint.workingDirectories": ["packages/qdrant-js", "packages/js-client-rest", "packages/js-client-grpc"]
}
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<p align="center">
<img height="100" src="https://github.com/qdrant/qdrant/raw/master/docs/logo.svg" alt="Qdrant">
&nbsp;
Expand All @@ -9,8 +8,7 @@
<b>JavaScript/TypeScript library for the <a href="https://github.com/qdrant/qdrant">Qdrant</a> vector search engine.</b>
</p>


<p align=center>
<p align="center">
<a href="https://www.npmjs.com/package/@qdrant/qdrant-js"><img src="https://badge.fury.io/js/@qdrant%2Fqdrant-js.svg" alt="npm version" height="18"></a>
<a href="https://qdrant.github.io/qdrant/redoc/index.html"><img src="https://img.shields.io/badge/Docs-OpenAPI%203.0-success" alt="OpenAPI Docs"></a>
<a href="https://github.com/qdrant/qdrant-client/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-success" alt="Apache 2.0 License"></a>
Expand All @@ -22,23 +20,22 @@

This repository contains packages of the JS SDK for the [Qdrant](https://github.com/qdrant/qdrant) vector search engine.

There are 3 packages:

* [`@qdrant/qdrant-js`](./packages/qdrant-js) - the main package with the SDK itself.
* [`@qdrant/js-client-rest`](./packages/js-client-rest) - leightweight REST client for Qdrant.
* [`@qdrant/js-client-grpc`](./packages/js-client-grpc) - WIP gRPC client for Qdrant.
There are published 3 packages:

- [`@qdrant/qdrant-js`](./packages/qdrant-js) - the main package with the SDK itself.
- [`@qdrant/js-client-rest`](./packages/js-client-rest) - lightweight REST client for Qdrant.
- [`@qdrant/js-client-grpc`](./packages/js-client-grpc) - gRPC client for Qdrant.

## JS/TS Examples

### Installation

```shell
pnpm i @qdrant/js-client-rest
# or
npm install @qdrant/js-client-rest
# or
yarn add @qdrant/js-client-rest
# or
pnpm i @qdrant/js-client-rest
```

### Usage
Expand Down Expand Up @@ -75,19 +72,24 @@ console.log('List of collections:', result.collections);

More examples can be found in the [`examples`](./examples) folder.

## Support

TypeScript types are provided alongside JavaScript sources to be used in:

- Node.js (ESM and CJS) - `>= 18.0.0`
- Deno
- Browser (fetch API)
- Cloudflare Workers (OpenAPI only)

## Releases

Major and minor versions align with Qdrant's engine releases, whilst patch are reserved for fixes regarding the current minor release. Check out [RELEASE.md](./RELEASE.md) for more info on release guidelines.

For release automation we use [`changesets`](https://github.com/changesets/changesets) both for pull requests and pushes to the master branch, and their [Github Action](https://github.com/changesets/action) to automate changeset steps.

## Contributions

In order to contribute there are a couple of things you may need to do.
## Contributing

We make use of [`pnpm`](https://pnpm.io/) instead of `npm` or `yarn` to manage and install packages in this monorepo, make sure it's installed on your local environment.
In order to [contribute](./CONTRIBUTING.md) there are a couple of things you may need to setup. We make use of [`pnpm`](https://pnpm.io/) instead of `npm` or `yarn` to manage and install packages in this monorepo, make sure it's installed on your local environment.

After checking out the repository and desired branch, run `pnpm install` to install all package's dependencies and run the compilation steps. This will work for the monorepo.

Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ New releases are made from the `master` branch following semver. Major and minor

2. (**AC**) Then open a pull request.

3. (**RC**) verifies the **semver** version commitment and turns it into a bump wtih `pnpm run version` on the root directory. This updates the versions on package.json files and updates the CHANGELOG.md files.
3. (**RC**) verifies the **semver** version commitment and turns it into a bump with `pnpm ci:version` on the root directory. This updates the versions on package.json files and updates the CHANGELOG.md files.

> This last step if skipped could result in an outdated pnpm lock file, and if so, update it manually with: `pnpm install --lockfile-only`.
Expand Down
10 changes: 4 additions & 6 deletions examples/node-js-basic/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {QdrantClient} from '@qdrant/js-client-rest';
import {QdrantClient} from '@qdrant/qdrant-js';

async function main() {
const collectionName = 'test_collection';
Expand Down Expand Up @@ -69,8 +69,8 @@ async function main() {
});

const collectionInfo = await client.getCollection(collectionName);
console.log(collectionInfo.points_count);
// prints: 6
console.log('number of points:', collectionInfo.points_count);
// prints: number of points: 6

const points = await client.retrieve(collectionName, {
ids: [1, 2],
Expand Down Expand Up @@ -230,9 +230,7 @@ async function main() {

main()
.then((code) => {
if (code !== 0) {
process.exit(code);
}
process.exit(code);
})
.catch((err) => {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion examples/node-js-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"author": "Qdrant Team",
"license": "Apache-2.0",
"dependencies": {
"@qdrant/js-client-rest": "^1.1.3"
"@qdrant/qdrant-js": "^1.2.0"
}
}
35 changes: 26 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@
},
"packageManager": "[email protected]",
"scripts": {
"prepare": "node ./prepare.cjs && pnpm -r build",
"prepare": "node scripts/prepare.cjs && pnpm -r build",
"ci:version": "pnpm changeset version && pnpm install --no-frozen-lockfile && git add .",
"ci:release": "pnpm changeset publish"
"ci:release": "node scripts/prepublish.mjs && pnpm changeset publish"
},
"lint-staged": {
"*.ts": [
"prettier --list-different",
"eslint"
],
"*.{md,yaml}": "prettier --list-different"
},
"devDependencies": {
"@changesets/changelog-github": "0.4.8",
"@changesets/cli": "2.26.1",
"husky": "8.0.3",
"is-ci": "3.0.1",
"prettier": "2.8.7",
"typescript": "5.0.4"
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-terser": "^0.4.1",
"@types/node": "^20.1.3",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"eslint": "^8.41.0",
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"rollup": "^3.21.6",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"pnpm": {
"overrides": {
"[email protected] || 2.x": "^2.2.2"
"@bufbuild/protobuf@^1.2.0": "file:./packages/js-client-grpc/includes/bufbuild-protobuf-1.2.1.tgz"
}
}
}
6 changes: 6 additions & 0 deletions packages/js-client-grpc/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignorePatterns": ["dist/*", "src/proto/*", "scripts/post-build.js"],
"parserOptions": {
"project": ["./tsconfig.json"]
}
}
3 changes: 3 additions & 0 deletions packages/js-client-grpc/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules/
**/dist/
**/src/proto/
63 changes: 63 additions & 0 deletions packages/js-client-grpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# JavaScript Qdrant gRPC Client

This repository contains the gRPC client for the [Qdrant](https://github.com/qdrant/qdrant) vector search engine.

## Installation

```shell
npm install @qdrant/js-client-grpc
# or
yarn add @qdrant/js-client-grpc
# or
pnpm i @qdrant/js-client-grpc
```

## Usage

Run the Qdrant Docker container:

```shell
docker run -p 6334:6334 qdrant/qdrant
```

## Instantiate a client

```ts
import {QdrantClient} from '@qdrant/js-client-grpc';

const client = new QdrantClient({host: '127.0.0.1', port: 6334});
// or
const client = new QdrantClient({url: 'http://127.0.0.1:6334'});
```

## Make requests

Use an endpoint from `collections` API:

```ts
try {
const result = await client.api('collections').list({});
console.log('List of collections:', result.collections);
} catch (err) {
console.error('Could not get collections:', err);
}
```

## Support

The gRPC implementation relies on the native node module `node:https`. For the time being, no JavaScript runtime other than Node / Deno are supported (though support for web may be added). Both Deno and Node support full-duplex, HTTP trailers and all the necessary bits for gRPC. Under the hood, the client uses [`connect-es`](https://github.com/bufbuild/connect-es/) to communicate with the server.

## Releases

Major and minor versions align with Qdrant's engine releases, whilst patch are reserved for fixes regarding the current minor release. Check out [RELEASE.md](../../RELEASE.md) for more info on release guidelines.

## Contributing

These are the most relevant scripts for development:

- `pnpm build`: builds and bundles from TypeScript sources
- `pnpm pre-check`: type-checks sources
- `pnpm pre-commit`: same as pre-check, but for git hooks (husky)
- `pnpm test`: run unit tests
- `pnpm test:integration`: runs integration tests against a locally running Qdrant docker container
- `pnpm codegen:openapi-typescript`: updates generated TS schema from the latest openapi.json remote
12 changes: 0 additions & 12 deletions packages/js-client-grpc/buf.gen.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions packages/js-client-grpc/examples/README.md

This file was deleted.

Loading

0 comments on commit fb009e1

Please sign in to comment.