This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from athrael-soju/18-update-pinecone-to-v101-1
18-update-pinecone-to-v101-1
- Loading branch information
Showing
10 changed files
with
698 additions
and
664 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { getPineconeClient } from "@/utils/pinecone"; | ||
|
||
export async function POST(req: Request) { | ||
const pinecone = await getPineconeClient() | ||
const index = pinecone.Index(process.env.PINECONE_INDEX!) | ||
await index.delete1({ | ||
deleteAll: true | ||
}); | ||
import { NextResponse } from 'next/server'; | ||
import { Pinecone } from '@pinecone-database/pinecone'; | ||
|
||
export async function POST() { | ||
// Instantiate a new Pinecone client | ||
const pinecone = new Pinecone(); | ||
// Select the desired index | ||
const index = pinecone.Index(process.env.PINECONE_INDEX!); | ||
|
||
// Use the custom namespace, if provided, otherwise use the default | ||
const namespaceName = process.env.PINECONE_NAMESPACE ?? ''; | ||
const namespace = index.namespace(namespaceName); | ||
|
||
// Delete everything within the namespace | ||
await namespace.deleteAll(); | ||
|
||
return NextResponse.json({ | ||
success: true | ||
}) | ||
} | ||
success: true, | ||
}); | ||
} |
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
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
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,34 @@ | ||
import type { Index, PineconeRecord } from '@pinecone-database/pinecone'; | ||
|
||
const sliceIntoChunks = <T>(arr: T[], chunkSize: number) => { | ||
return Array.from({ length: Math.ceil(arr.length / chunkSize) }, (_, i) => | ||
arr.slice(i * chunkSize, (i + 1) * chunkSize) | ||
); | ||
}; | ||
|
||
export const chunkedUpsert = async ( | ||
index: Index, | ||
vectors: Array<PineconeRecord>, | ||
namespace: string, | ||
chunkSize = 10 | ||
) => { | ||
// Split the vectors into chunks | ||
const chunks = sliceIntoChunks<PineconeRecord>(vectors, chunkSize); | ||
|
||
try { | ||
// Upsert each chunk of vectors into the index | ||
await Promise.allSettled( | ||
chunks.map(async (chunk) => { | ||
try { | ||
await index.namespace(namespace).upsert(vectors); | ||
} catch (e) { | ||
console.log('Error upserting chunk', e); | ||
} | ||
}) | ||
); | ||
|
||
return true; | ||
} catch (e) { | ||
throw new Error(`Error upserting vectors into index: ${e}`); | ||
} | ||
}; |
Oops, something went wrong.