CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
README.md103 linesDownload Raw Back to js-client-rest
1# JavaScript Qdrant REST Client2 3This repository contains the REST client for the [Qdrant](https://github.com/qdrant/qdrant) vector search engine.4 5## Installation6 7```shell8npm install @qdrant/js-client-rest9# or10yarn add @qdrant/js-client-rest11# or12pnpm i @qdrant/js-client-rest13```14 15## Usage16 17Run the Qdrant Docker container:18 19```shell20docker run -p 6333:6333 qdrant/qdrant21```22 23### Instantiate a client24 25```ts26import {QdrantClient} from '@qdrant/js-client-rest';27 28const client = new QdrantClient({host: '127.0.0.1', port: 6333});29// or30const client = new QdrantClient({url: 'http://127.0.0.1:6333'});31```32 33### Make requests34 35Using one of the available facade methods:36 37```ts38try {39    const result = await client.getCollections();40    console.log('List of collections:', result.collections);41} catch (err) {42    console.error('Could not get collections:', err);43}44```45 46Or directly using an endpoint from the API:47 48```ts49await client.api('collections').getCollections();50```51 52### Typed Error Handling53 54A non-ok fetch response throws a generic `ApiError`55 56But an Openapi document can declare a different response type for each status code, or a default error response type.57 58These can be accessed via a discriminated union on status, as in code snippet below:59 60```ts61const findPetsByStatus = fetcher.path('/pet/findByStatus').method('get').create();62const addPet = fetcher.path('/pet').method('post').create();63 64try {65    const collection = await client.getCollection('bom-ada-002');66    // ...67} catch (e) {68    // check which operation threw the exception69    if (e instanceof client.getCollection.Error) {70        // get discriminated union error { status, data }71        const error = e.getActualType();72        // sort case's logic73        if (error.status === 400) {74            error.data.status.error; // only available for a 4xx responses75        } else if (error.status === 500) {76            error.data.status.error; // only available for a 500 response77        } else {78            error.data.result;79            // ...80        }81    }82}83```84 85## Support86 87The REST implementation relies on the native [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), which is available in Deno and Node.js (starting on v18.0.0 without experimental flag). The Deno implementation [supports HTTP/2](https://deno.com/blog/every-web-api-in-deno#fetch-request-response-and-headers) whereas Node.js is still lagging on the spec and provide only HTTP 1.1 support (this is due to the fact that under the hood Node.js still relies on [undici](https://github.com/nodejs/undici)).88 89## Releases90 91Major 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.92 93## Contributing94 95These are the most relevant scripts for development:96 97-   `pnpm build`: builds and bundles from TypeScript sources98-   `pnpm pre-check`: type-checks sources99-   `pnpm pre-commit`: same as pre-check, but for git hooks (husky)100-   `pnpm test`: run unit tests101-   `pnpm test:integration`: runs integration tests against a locally running Qdrant docker container102-   `pnpm codegen:openapi-typescript`: updates generated TS schema from the latest openapi.json remote103