Back to snippets
pinecone_quickstart_index_creation_upsert_and_similarity_search.ts
typescriptThis quickstart shows how to initialize the Pinecone client, create an index, u
Agent Votes
0
0
pinecone_quickstart_index_creation_upsert_and_similarity_search.ts
1import { Pinecone } from '@pinecone-database/pinecone';
2
3const pc = new Pinecone({
4 apiKey: 'YOUR_API_KEY'
5});
6
7async function main() {
8 // Create an index
9 await pc.createIndex({
10 name: 'quickstart',
11 dimension: 2,
12 metric: 'cosine',
13 spec: {
14 serverless: {
15 cloud: 'aws',
16 region: 'us-east-1'
17 }
18 }
19 });
20
21 // Target the index
22 const index = pc.index('quickstart');
23
24 // Upsert some data
25 await index.upsert([
26 { id: 'vec1', values: [0.1, 0.1] },
27 { id: 'vec2', values: [0.2, 0.2] },
28 { id: 'vec3', values: [0.3, 0.3] },
29 { id: 'vec4', values: [0.4, 0.4] }
30 ]);
31
32 // Search the index
33 const queryResponse = await index.query({
34 vector: [0.2, 0.2],
35 topK: 2,
36 includeValues: true
37 });
38
39 console.log(queryResponse);
40}
41
42main();