#Assistant API vector search

1 messages · Page 1 of 1 (latest)

timber fulcrum
#

When trying to upload a file to vector store in assistant api getting this error
Error in setting up resources: TypeError: Cannot read properties of undefined (reading 'length')

 at FileBatches.uploadAndPoll (/home/user/projs/pet-mate-BE/functions/node_modules/openai/resources/beta/vector-stores/file-batches.js)
        // Create the Vector Store
        const vectorStore = await openai.beta.vectorStores.create({
            name: "Pet Mate Store"
        });

        // Upload files to the Vector Store
        const filePath = path.join(__dirname, 'productData.json');
        console.log("🚀 ~ exports.setupAssistantResources=functions.https.onCall ~ filePath:", filePath)
        const fileStreams = fs.createReadStream(filePath);
        await openai.beta.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, fileStreams);

        // Update the Assistant to use the Vector Store
        await openai.beta.assistants.update(assistant_id, {
            tool_resources: { file_search: { vector_store_ids: [vectorStore.id] } },
        });
wheat tokenBOT
#

Hi @timber fulcrum. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, it seems like there might be an issue with the way you're trying to upload files to the vector store. Instead of using fileBatches.uploadAndPoll, you might want to try using files.create and files.createAndPoll methods.

Here's how you can modify your code:

const assistant_id = "asst_huFiiG0viunNSGkcsyG8puWJ";
// Create the Vector Store
const vectorStore = await openai.beta.vectorStores.create({
    name: "Pet Mate Store"
});

// Upload files to the Vector Store
const filePath = path.join(__dirname, 'productData.json');
console.log("🚀 ~ exports.setupAssistantResources=functions.https.onCall ~ filePath:", filePath)

// Create fileData
const fileData = await openai.files.create({
    file: fs.createReadStream(filePath),
    purpose: "fine-tune",
});

// Use createAndPoll instead of uploadAndPoll
await openai.beta.vectorStores.files.createAndPoll(vectorStore.id, {
    file_id: fileData.id,
});

// Update the Assistant to use the Vector Store
await openai.beta.assistants.update(assistant_id, {
    tool_resources: { file_search: { vector_store_ids: [vectorStore.id] } },
});

This change was suggested by a user in a Github issue (https://github.com/openai/openai-node/issues/805) who faced a similar problem. They resolved their error by changing from fileBatches (call like it's shown in the official docs) to files call and passing the fileData.id.

Please note that this is a suggestion based on the information available in the knowledge sources and might not completely resolve your issue. If the problem persists, it would be best to reach out to OpenAI support or check the official OpenAI documentation for more information.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: