1 | import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.1.1/mod.ts"; |
2 | import { PineconeClient } from "npm:@pinecone-database/pinecone"; |
3 |
|
4 |
|
5 | * @param name The name of the index to be created. The maximum length is 45 characters. |
6 | * |
7 | * @param dimension The dimensions of the vectors to be inserted in the index. |
8 | * |
9 | * @param metric _(Optional)_ The distance metric to be used for similarity search. |
10 | * |
11 | * @param pods _(Optional)_ The number of pods for the index to use, including replicas. |
12 | * |
13 | * @param replicas _(Optional)_ The number of replicas. |
14 | * |
15 | * @param pod_type _(Optional)_ The pod type for the index. |
16 | * `s1`: Best storage capacity. |
17 | * `p1`: Faster queries. |
18 | * `p2`: Lowest latency and highest throughput. |
19 | * |
20 | * @param pod_size _(Optional)_ The size of the pod. You can increase (but not decrease) the pod size on running indexes. |
21 | * If `pod_type` is not set, this will be ignored. |
22 | * |
23 | * @param metadata_config _(Optional)_ Configuration for the behavior of Pinecone's internal metadata index. |
24 | * By default, all metadata is indexed; when `metadata_config` is present, only specified metadata fields are indexed. |
25 | * |
26 | * @param source_collection _(Optional)_ The name of the collection to create an index from. |
27 | */ |
28 | type Pinecone = { |
29 | apiKey: string; |
30 | environment: string; |
31 | }; |
32 | export async function main( |
33 | auth: Pinecone, |
34 | name: string, |
35 | dimension: number, |
36 | metric?: "" | "euclidean" | "cosine" | "dotproduct", |
37 | pods?: number, |
38 | replicas?: number, |
39 | pod_type?: "" | "s1" | "p1" | "p2", |
40 | pod_size?: "" | "x1" | "x2" | "x4" | "x8", |
41 | metadata_config?: Record<string, string>, |
42 | source_collection?: number, |
43 | ) { |
44 | const client = new PineconeClient(); |
45 | await client.init(auth); |
46 |
|
47 | const createRequest = removeObjectEmptyFields({ |
48 | name, |
49 | dimension, |
50 | metric, |
51 | pods, |
52 | replicas, |
53 | pod_type: pod_type ? `${pod_type}.${pod_size || "x1"}` : undefined, |
54 | metadata_config, |
55 | source_collection, |
56 | }); |
57 | return await client.createIndex({ createRequest }); |
58 | } |
59 |
|