I ran into issues with adding files to a vector store as well.
After trying many different strategies, I gave up on it working the first time. After the file uploads and vector store creation were completed, I run this.
export const fixAnyUploadIssues = async (vectorStoreId: string) => {
const filesPage = await openai.beta.vectorStores.files.list(vectorStoreId);
const files = filesPage.data;
const failedFiles = files.filter(file => file.status === "failed");
console.log("Initial failed files", failedFiles);
for (const failedFile of failedFiles) {
let attempt = 0;
let success = false;
while (attempt < 5 && !success) {
attempt++;
console.log(`Attempt: ${attempt} for file ${failedFile.id}`);
try {
await openai.beta.vectorStores.files.create(vectorStoreId, {
file_id: failedFile.id
});
const updatedFilesPage = await openai.beta.vectorStores.files.list(vectorStoreId);
const updatedFiles = updatedFilesPage.data;
const updatedFailedFiles = updatedFiles.filter(file => file.status === "failed");
if (!updatedFailedFiles.some(file => file.id === failedFile.id)) {
success = true;
}
} catch (error) {
console.error(`Failed to upload file to vector store: ${failedFile.id}, attempt ${attempt}`, error);
}
}
}
};