Skip to content

Commit

Permalink
Implement BigInt support for REST client (#62)
Browse files Browse the repository at this point in the history
* Implement BigInt support for REST client

* Return to Node.js 18 compatibility and skip BigInt support and test until Node 21

* Update expected number of points in retrieve all points test

---------

Co-authored-by: kartik-gupta-ij <[email protected]>
  • Loading branch information
Rendez and kartik-gupta-ij authored Mar 1, 2024
1 parent 48db336 commit 44bac2a
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]
node-version: [18, 20, 21]
os:
- ubuntu-latest
- windows-latest
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"node": ">=18.0.0",
"pnpm": ">=8"
},
"packageManager": "pnpm@8.3.0",
"packageManager": "pnpm@8.15.3",
"scripts": {
"prepare": "node scripts/prepare.cjs && pnpm -r build",
"ci:version": "pnpm changeset version && pnpm install --no-frozen-lockfile && git add .",
Expand Down
31 changes: 29 additions & 2 deletions packages/js-client-grpc/tests/integration/qdrant-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('QdrantClient', () => {
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const client = new QdrantClient();
const collectionName = 'test_collection';
const bigInt = BigInt(String(Number.MAX_SAFE_INTEGER + 2));

test('signal abort: timeout', async () => {
const client = new QdrantClient({timeout: 0});
Expand Down Expand Up @@ -217,6 +218,14 @@ describe('QdrantClient', () => {
},
},
},
{
id: {
pointIdOptions: {case: 'num', value: bigInt},
},
vectors: {
vectorsOptions: {case: 'vector', value: {data: [0.18, 0.01, 0.85, 0.8]}},
},
},
{
id: {
pointIdOptions: {case: 'uuid', value: '98a9a4b1-4ef2-46fb-8315-a97d874fe1d7'},
Expand Down Expand Up @@ -315,6 +324,24 @@ describe('QdrantClient', () => {
});
});

test('retrieve point by uint64 id (BigInt)', async () => {
const points = (
await client.api('points').get({
collectionName,
ids: [
{
pointIdOptions: {case: 'num', value: bigInt},
},
],
})
).result;
expect(points[0].toJson()).toMatchObject({
id: {
num: bigInt.toString(),
},
});
});

test('retrieve points', async () => {
const points = (
await client.api('points').get({
Expand All @@ -334,8 +361,8 @@ describe('QdrantClient', () => {

test('retrieve all points', async () => {
const result = (await client.api('collections').get({collectionName})).result!;
expect(result.toJson(), 'check failed - 6 points expected').toMatchObject({
vectorsCount: '6',
expect(result.toJson(), 'check failed - 7 points expected').toMatchObject({
vectorsCount: '7',
});
});

Expand Down
10 changes: 6 additions & 4 deletions packages/js-client-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@
"openapi_schema_remote": "https://raw.githubusercontent.com/qdrant/qdrant/master/docs/redoc/master/openapi.json"
},
"dependencies": {
"@sevinf/maybe": "^0.5.0",
"@qdrant/openapi-typescript-fetch": "^1.2.1",
"undici": "^5.26.2"
"@qdrant/openapi-typescript-fetch": "1.2.5",
"@sevinf/maybe": "0.5.0",
"undici": "5.28.3"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-replace": "^5.0.2",
"@total-typescript/ts-reset": "^0.4.2",
"@types/semver": "7.5.7",
"openapi-typescript": "^6.2.6",
"semver": "7.6.0",
"ts-prune": "^0.10.3",
"vitest": "^0.31.4"
},
"peerDependencies": {
"typescript": ">=4.1"
"typescript": ">=4.7"
}
}
18 changes: 16 additions & 2 deletions packages/js-client-rest/tests/integration/qdrant-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {test, describe, expect} from 'vitest';
import semver from 'semver';
import {QdrantClient} from '../../src/qdrant-client.js';

describe('QdrantClient', () => {
Expand All @@ -7,6 +8,9 @@ describe('QdrantClient', () => {
const DIM = 100;
const client = new QdrantClient();
const collectionName = 'test_collection';
const bigInt = BigInt(String(Number.MAX_SAFE_INTEGER + 2)) as unknown as number;
const maxSafeInteger = Number.MAX_SAFE_INTEGER;
const supportsJSONBigInt = semver.satisfies(process.versions.node, '>=21');

test('Qdrant service check', async () => {
const {data} = await client.api('service').telemetry({});
Expand Down Expand Up @@ -93,9 +97,10 @@ describe('QdrantClient', () => {
{id: 2, vector: [0.19, 0.81, 0.75, 0.11], payload: {city: ['Berlin', 'London']}},
{id: 3, vector: [0.36, 0.55, 0.47, 0.94], payload: {city: ['Berlin', 'Moscow']}},
{id: 4, vector: [0.18, 0.01, 0.85, 0.8], payload: {city: ['London', 'Moscow']}},
{id: maxSafeInteger, vector: [0.19, 0.81, 0.75, 0.11]},
{id: '98a9a4b1-4ef2-46fb-8315-a97d874fe1d7', vector: [0.24, 0.18, 0.22, 0.44], payload: {count: [0]}},
{id: 'f0e09527-b096-42a8-94e9-ea94d342b925', vector: [0.35, 0.08, 0.11, 0.44]},
],
].concat(supportsJSONBigInt ? [{id: bigInt, vector: [0.19, 0.81, 0.75, 0.11]}] : []),
});
expect(result).toMatchObject<typeof result>({operation_id: expect.any(Number) as number, status: 'completed'});
});
Expand All @@ -109,6 +114,15 @@ describe('QdrantClient', () => {
});
});

test.skipIf(!supportsJSONBigInt)('retrieve point by uint64 id (BigInt)', async () => {
const result = (await client.api('points').getPoint({collection_name: collectionName, id: bigInt})).data
.result!;
expect(result).toMatchObject<typeof result>({
id: bigInt,
vector: [0.19, 0.81, 0.75, 0.11],
});
});

test('retrieve points', async () => {
const result = await client.retrieve(collectionName, {ids: [1, 2]});
expect(result).toHaveLength(2);
Expand All @@ -117,7 +131,7 @@ describe('QdrantClient', () => {
test('retrieve all points', async () => {
const result = await client.getCollection(collectionName);
expect(result, 'check failed - 6 points expected').toMatchObject<Pick<typeof result, 'vectors_count'>>({
vectors_count: 6,
vectors_count: 7 + (supportsJSONBigInt ? 1 : 0),
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/js-client-rest/tests/unit/api-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('apiClient', () => {
ok: true,
status,
json: () => new Promise((resolve) => resolve({error_message: 'response error'})),
text: () => new Promise((resolve) => resolve(JSON.stringify({error_message: 'response error'}))),
});
let originalFetch: typeof global.fetch;

Expand Down
48 changes: 35 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44bac2a

Please sign in to comment.