-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move examples into another folder and expanded documentation. - Fixes issue on Webpack and potentially other bundles to target ESM files when bundling. - Fixes default parameter host=localhost resolving to ipv6 ::1 since Node 17 by using 127.0.0.1 instead.
- Loading branch information
Showing
21 changed files
with
480 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@qdrant/js-client-rest': patch | ||
--- | ||
|
||
Move examples into another folder and expanded documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@qdrant/js-client-rest': patch | ||
'@qdrant/qdrant-js': patch | ||
--- | ||
|
||
Fixes issue on Webpack and potentially other bundles to target ESM files when bundling. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@qdrant/js-client-rest': patch | ||
--- | ||
|
||
Fixes default parameter host=localhost resolving to ipv6 ::1 since Node 17 by using 127.0.0.1 instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
packages/**/package-lock.json | ||
**/yarn.lock | ||
**/package-lock.json | ||
**/node_modules/ | ||
**/.pnpm-store/ | ||
**/*.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Node.js Example | ||
|
||
Access Qdrant API from Node.js | ||
|
||
## How to | ||
|
||
Install dependencies | ||
|
||
```bash | ||
npm install --save @qdrant/js-client-rest | ||
``` | ||
|
||
Import client | ||
|
||
```js | ||
import {QdrantClient} from '@qdrant/js-client-rest'; | ||
``` | ||
|
||
Initialize client | ||
|
||
```js | ||
const client = new QdrantClient({url: 'http://127.0.0.1:6333'}); | ||
``` | ||
|
||
## Run example | ||
|
||
```bash | ||
node ./index.js | ||
``` | ||
|
||
## Connect to Qdrant Cloud | ||
|
||
```js | ||
const client = new QdrantClient({ | ||
url: 'https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.us-east-0-1.aws.cloud.qdrant.io', | ||
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
}); | ||
``` | ||
|
||
Obtain API key from [Qdrant Cloud](https://cloud.qdrant.io/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
import {QdrantClient} from '@qdrant/js-client-rest'; | ||
|
||
async function main() { | ||
const collectionName = 'test_collection'; | ||
|
||
const client = new QdrantClient({url: 'http://127.0.0.1:6333'}); | ||
|
||
const response = await client.getCollections(); | ||
|
||
const collectionNames = response.collections.map((collection) => collection.name); | ||
|
||
if (collectionNames.includes(collectionName)) { | ||
await client.deleteCollection(collectionName); | ||
} | ||
|
||
await client.createCollection(collectionName, { | ||
vectors: { | ||
size: 4, | ||
distance: 'Cosine', | ||
}, | ||
optimizers_config: { | ||
default_segment_number: 2, | ||
}, | ||
replication_factor: 2, | ||
}); | ||
|
||
// -------- Create payload indexes ------------- | ||
|
||
await client.createPayloadIndex(collectionName, { | ||
field_name: 'city', | ||
field_schema: 'keyword', | ||
wait: true, | ||
}); | ||
|
||
await client.createPayloadIndex(collectionName, { | ||
field_name: 'count', | ||
field_schema: 'integer', | ||
wait: true, | ||
}); | ||
|
||
await client.createPayloadIndex(collectionName, { | ||
field_name: 'coords', | ||
field_schema: 'geo', | ||
wait: true, | ||
}); | ||
|
||
// -------- Add points ------------- | ||
|
||
await client.upsert(collectionName, { | ||
wait: true, | ||
points: [ | ||
{ | ||
id: 1, | ||
vector: [0.05, 0.61, 0.76, 0.74], | ||
payload: { | ||
city: 'Berlin', | ||
country: 'Germany', | ||
count: 1000000, | ||
square: 12.5, | ||
coords: {lat: 1.0, lon: 2.0}, | ||
}, | ||
}, | ||
{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: '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]}, | ||
], | ||
}); | ||
|
||
const collectionInfo = await client.getCollection(collectionName); | ||
console.log(collectionInfo.points_count); | ||
// prints: 6 | ||
|
||
const points = await client.retrieve(collectionName, { | ||
ids: [1, 2], | ||
}); | ||
|
||
console.log('points: ', points); | ||
// prints: | ||
// points: [ | ||
// { | ||
// id: 1, | ||
// payload: { | ||
// city: 'Berlin', | ||
// coords: [Object], | ||
// count: 1000000, | ||
// country: 'Germany', | ||
// square: 12.5 | ||
// }, | ||
// vector: null | ||
// }, | ||
// { id: 2, payload: { city: [Array] }, vector: null } | ||
// ] | ||
|
||
// -------- Search ---------------- | ||
const queryVector = [0.2, 0.1, 0.9, 0.7]; | ||
|
||
const res1 = await client.search(collectionName, { | ||
vector: queryVector, | ||
limit: 3, | ||
}); | ||
|
||
console.log('search result: ', res1); | ||
// prints: | ||
// search result: [ | ||
// { | ||
// id: 4, | ||
// version: 3, | ||
// score: 0.99248314, | ||
// payload: { city: [Array] }, | ||
// vector: null | ||
// }, | ||
// { | ||
// id: 1, | ||
// version: 3, | ||
// score: 0.89463294, | ||
// payload: { | ||
// city: 'Berlin', | ||
// coords: [Object], | ||
// count: 1000000, | ||
// country: 'Germany', | ||
// square: 12.5 | ||
// }, | ||
// vector: null | ||
// }, | ||
// { | ||
// id: '98a9a4b1-4ef2-46fb-8315-a97d874fe1d7', | ||
// version: 3, | ||
// score: 0.8543979, | ||
// payload: { count: [Array] }, | ||
// vector: null | ||
// } | ||
// ] | ||
|
||
const resBatch = await client.searchBatch(collectionName, { | ||
searches: [ | ||
{ | ||
vector: queryVector, | ||
limit: 1, | ||
}, | ||
{ | ||
vector: queryVector, | ||
limit: 2, | ||
}, | ||
], | ||
}); | ||
|
||
console.log('search batch result: ', resBatch); | ||
// prints: | ||
// search batch result: [ | ||
// [ | ||
// { | ||
// id: 4, | ||
// version: 3, | ||
// score: 0.99248314, | ||
// payload: null, | ||
// vector: null | ||
// } | ||
// ], | ||
// [ | ||
// { | ||
// id: 4, | ||
// version: 3, | ||
// score: 0.99248314, | ||
// payload: null, | ||
// vector: null | ||
// }, | ||
// { | ||
// id: 1, | ||
// version: 3, | ||
// score: 0.89463294, | ||
// payload: null, | ||
// vector: null | ||
// } | ||
// ] | ||
// ] | ||
|
||
// -------- Search filters ---------------- | ||
|
||
const res2 = await client.search(collectionName, { | ||
vector: queryVector, | ||
limit: 3, | ||
filter: { | ||
must: [ | ||
{ | ||
key: 'city', | ||
match: { | ||
value: 'Berlin', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
console.log('search result with filter: ', res2); | ||
// prints: | ||
// search result with filter: [ | ||
// { | ||
// id: 1, | ||
// version: 3, | ||
// score: 0.89463294, | ||
// payload: { | ||
// city: 'Berlin', | ||
// coords: [Object], | ||
// count: 1000000, | ||
// country: 'Germany', | ||
// square: 12.5 | ||
// }, | ||
// vector: null | ||
// }, | ||
// { | ||
// id: 3, | ||
// version: 3, | ||
// score: 0.83872515, | ||
// payload: { city: [Array] }, | ||
// vector: null | ||
// }, | ||
// { | ||
// id: 2, | ||
// version: 3, | ||
// score: 0.66603535, | ||
// payload: { city: [Array] }, | ||
// vector: null | ||
// } | ||
// ] | ||
|
||
return 0; | ||
} | ||
|
||
main() | ||
.then((code) => { | ||
if (code !== 0) { | ||
process.exit(code); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.