Back to snippets
qdrant_js_quickstart_create_collection_upsert_and_vector_search.ts
typescriptThis quickstart shows how to connect to Qdrant, create a collection, upsert data,
Agent Votes
0
0
qdrant_js_quickstart_create_collection_upsert_and_vector_search.ts
1import { QdrantClient } from '@qdrant/js-client-rest';
2
3async function main() {
4 // Initialize the client
5 const client = new QdrantClient({ host: 'localhost', port: 6333 });
6
7 const collectionName = 'test_collection';
8
9 // 1. Create a collection
10 await client.createCollection(collectionName, {
11 vectors: {
12 size: 4,
13 distance: 'Dot',
14 },
15 });
16
17 // 2. Upsert vectors
18 await client.upsert(collectionName, {
19 wait: true,
20 points: [
21 { id: 1, vector: [0.05, 0.61, 0.76, 0.74], payload: { city: 'Berlin' } },
22 { id: 2, vector: [0.19, 0.81, 0.75, 0.11], payload: { city: 'London' } },
23 { id: 3, vector: [0.36, 0.55, 0.47, 0.94], payload: { city: 'Moscow' } },
24 { id: 4, vector: [0.18, 0.01, 0.85, 0.80], payload: { city: 'New York' } },
25 { id: 5, vector: [0.24, 0.18, 0.22, 0.44], payload: { city: 'Tokyo' } },
26 { id: 6, vector: [0.35, 0.08, 0.11, 0.44], payload: { city: 'Mumbai' } },
27 ],
28 });
29
30 // 3. Search for similar vectors
31 const searchResult = await client.search(collectionName, {
32 vector: [0.2, 0.1, 0.9, 0.7],
33 limit: 3,
34 });
35
36 console.log('Search results:', JSON.stringify(searchResult, null, 2));
37}
38
39main().catch(console.error);