0
Upsert Vectors
One script reply has been approved by the moderators Verified
Created by adam186 384 days ago Viewed 5815 times
0
Submitted by adam186 Deno
Verified 384 days ago
1
import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.1.1/mod.ts";
2
import { PineconeClient } from "npm:@pinecone-database/pinecone";
3
import { UpsertOperationRequest } from "npm:@pinecone-database/pinecone/0.0.12/dist/pinecone-generated-ts-fetch/index.js";
4

5
type Pinecone = {
6
  apiKey: string;
7
  environment: string;
8
};
9
export async function main(
10
  auth: Pinecone,
11
  index_name: string,
12
  vectors: { id: string; values: number[]; metadata?: Record<string, any> }[],
13
  namespace?: string,
14
  raw?: boolean,
15
) {
16
  const client = new PineconeClient();
17
  await client.init(auth);
18
  const index = client.Index(index_name);
19

20
  const upsertRequest: UpsertOperationRequest = removeObjectEmptyFields({
21
    vectors,
22
    namespace,
23
  });
24
  return await index[raw ? "upsertRaw" : "upsert"]({ upsertRequest });
25
}
26