Assistance Needed for Error with Pinecone Upsert: PineconeError: PineconeClient: Error calling upsertRaw: FetchError

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:

  1. Checked API key and configurations in the Pinecone client.
  2. Verified that embeddings are correctly formatted (fixed dimensions).
  3. Increased the timeout setting to see if it might be due to a network delay.
  4. 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:

  1. Has anyone encountered this specific error, and what was the root cause?
  2. Could this error be related to network issues, rate limits, or Pinecone’s internal request handling?
  3. 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 });
}
}

Looks like youve been fairly proactive in eliminating some potential causes already. I’ll put some additional suggestions (hopefully avoiding redundance)

Im guessing that you already checked your rate limtis and quotas, along with your network configs to prevent possible interference and conflicts

Along with network configuration, did you also check batch size? Although you mentioned using small batches (50-100 vectors), try reducing the batch size further to see if it improves the success rate of the upsert operations.