PineconeError: PineconeClient: Error calling upsert: PineconeError: PineconeClient: Error calling upsertRaw: FetchError: The request failed and the interceptors did not return an alternative response
Context:
I’m working on a project that uses Pinecone to store embeddings. Each time I try to upsert a batch of embeddings, I receive this error. This issue seems to occur sporadically and disrupts the flow of data into Pinecone.
Steps I’ve Taken:
- Checked API key and configurations in the Pinecone client.
- Verified that embeddings are correctly formatted (fixed dimensions).
- Increased the timeout setting to see if it might be due to a network delay.
- Examined network settings and ensured there are no restrictions that might block the request.
Environment Details:
- Language/Library: Node.js with
@pinecone-database/pinecone
client - Deployment: Using in a backend API service with batches of embeddings.
- Database Size and Batch Size: Small initial dataset, around 50–100 vectors per batch.
Questions:
- Has anyone encountered this specific error, and what was the root cause?
- Could this error be related to network issues, rate limits, or Pinecone’s internal request handling?
- Are there specific retry strategies or configurations that could help prevent this error?
Any insights or recommendations for debugging steps would be appreciated!
Thank you!
this is the main code i have
export async function POST(request: any, userId: string): Promise {
try {
const formData = await request.formData();
const file = formData.get(“file”);
if (!file) {
return NextResponse.json({ error: “File is required.” }, { status: 400 });
}
const buffer = Buffer.from(await file.arrayBuffer());
const fileName = await uploadFileToS3(buffer, file.name);
const uploadedFile = await db.file.create({
data: {
key: fileName,
name: file.name,
userId: "kp_37e2a1af91f44861946a081d10112f5c",
url: `https://${process.env.NEXT_PUBLIC_AWS_S3_BUCKET_NAME}.s3.${process.env.NEXT_PUBLIC_AWS_S3_REGION}.amazonaws.com/${file.name}`,
uploadStatus: "PROCESSING",
},
});
const response = await fetch(
`https://${process.env.NEXT_PUBLIC_AWS_S3_BUCKET_NAME}.s3.${process.env.NEXT_PUBLIC.AWS_S3_REGION}.amazonaws.com/${file.name}`
);
const blob = await response.blob();
const loader = new PDFLoader(blob);
const pageLevelDocs = await loader.load();
// Extract the text content from the pageLevelDocs
const texts = pageLevelDocs.map(doc => doc.pageContent);
const geminiEmbeddings = new GeminiEmbeddings(
process.env.GEMINI_API_KEY!,
"text-embedding-004"
);
const pinecone = await getPineconeClient();
const pineconeIndex = pinecone.Index("docdecodegemini");
console.log("Generating embeddings...");
const vectors = await geminiEmbeddings.embedDocuments(texts);
// Convert the `vectors` into a format Pinecone expects (id and values)
const upsertData = vectors.map((vector, index) => ({
id: `${uploadedFile.id}-${index}`, // Unique ID for each vector
values: vector, // The vector values generated by Gemini
}));
console.log("Chunking embeddings for upsert...");
const chunks = chunkArray(upsertData, CHUNK_SIZE);
for (const chunk of chunks) {
try {
await pineconeIndex.upsert({ upsertRequest: { vectors: chunk } });
console.log(`Successfully upserted a batch of ${chunk.length} embeddings.`);
} catch (error) {
console.error("Error upserting chunk:", error);
await db.file.update({
data: { uploadStatus: "FAILED" },
where: { id: uploadedFile.id },
});
throw error;
}
}
await db.file.update({
data: { uploadStatus: "SUCCESS" },
where: { id: uploadedFile.id },
});
return NextResponse.json({ success: true, key: fileName, uploadedFile });
} catch (error) {
console.error(“An error occurred during processing:”, error);
return NextResponse.json({ error: error.message });
}
}