Creating thread somehow creating a new untitled Vector Store...?

Overview
I am developing a chatbot using Google App Script and LINE chat.

I attached 2 pieces from my entire code in this post, where are responsible for

  1. creating a new thread.
  2. Send initial message to the AI in the thread just created.

After these 2 processes, there are code for run and get response from the AI.

Question
When the program runs “STEP02: CREATE MESSAGE”, it also auto generate untitled vector store which I can find it at openAI dashbord > storage > Vector Store.

I don’t mind the program to create a new vector store responsible for storing file needed for generating response in the conversation done in the thread.

But the problem is, I have no idea how to retrieve this newly created vector store ID, therefore I cannot delete it when I am done with conversation and delete the thread.

Does anyone know how to access vector store ID?
Perhaps find out vector store ID when it is generated?

Thank you for any thoughts and advices!

//[STEP01: CREATE THREAD] 
function createNewThread() {

  var options = {
    'method': 'post',
    'headers': {
      'contentType': 'application/json',
      'Authorization': 'Bearer ' + OpenAI_key,
      'OpenAI-Beta': 'assistants=v2'
    },
    'muteHttpExceptions': true // HTTP例外をミュートにする
  };

  try {
    let response = UrlFetchApp.fetch(OPENAI_ASSISTANT_END_POINT, options);
    let responseCode = response.getResponseCode();
    let content = response.getContentText();
    
    if (responseCode == 200) {
      Logger.log('Success: ' + content);

      //[#TEST]FOR TEST PURPOSE, DELETE AFTER TEST
      pc_threadId.setValue(JSON.parse(content)["id"]);
      
      return JSON.parse(content)["id"];
    } else {
      Logger.log('Error: ' + responseCode + '\n' + content);
    }
  } catch (e) {
    Logger.log('Exception: ' + e.toString());
  }
}

//[STEP02: CREATE MESSAGE] 
function createMessage(threadId,userMessage){
  var data = {
    "role":"user",
    "content":userMessage,
    "attachments": [
      {
        "file_id": fileId_01,
        "tools" : [
          {
            "type": "file_search"
          }
        ]
      }
    ],
    //"file_ids": [fileId_01],
  };

  var options = {
    'method': 'post',
    'headers': {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + OpenAI_key,
      'OpenAI-Beta': 'assistants=v2'
    },
    'payload': JSON.stringify(data)
  };

  try {
    var response = UrlFetchApp.fetch(OPENAI_ASSISTANT_END_POINT + "/" + threadId  + "/messages", options);
    var responseCode = response.getResponseCode();
    var content = response.getContentText();
    var result = JSON.parse(response.getContentText());
    Logger.log(result.id); // 応答をログに記録します
    if (responseCode == 200) {
      Logger.log('Success: ' + content);
    }else{
      Logger.log('Error: ' + responseCode + '\n' + content);
    }
    return result;
  } catch (e) {
    Logger.log(e.toString());
  }
}

When using the Assistant API to create a bot for conversations on LINE, it looks like file objects are being generated.

Given that the file ID is specified as fileId_01, you can delete the file when it’s no longer needed by ensuring you retain the value of fileId_01. You can do this with the following code:

async function main() {
  const file = await openai.files.del(fileId_01);
  console.log(file);
}

main();

If your goal is to store past conversation history, there are simpler methods to manage this without relying on the Assistant API, which you might find worth exploring.

I hope this helps in some way🙂

1 Like

Thank you very much for your reply!

I have one question about your approach!

When I run this async function you mentioned, does it only deletes the file I upload on the opneAI platform or it deletes file in the Vector Store and also the auto generated Vector Store?

I don’t want the file to be deleted from the platform since I always want to attach this file whenever new thread is created.

For your Information, this is what is going on every single time I make a new thread and created a new message. I want to delete this vector stores when I am done with the Assistant AI.

Thank you!

As far as I understand and based on my experience, deleting vector data stored in a vector store does not delete the original files.

A vector store can consolidate vector data created from multiple files into one, but deleting that data does not affect the original files.

Also, even if you run it asynchronously, the only difference would be the timing of the execution, and it shouldn’t affect the results.

In your screenshot, the vector data is named “Untitled store” but to avoid confusion, it might be better to name the vector data before saving it.

Thank you for you reply!
I think I made you confused about my intention with this post, so let me clarify it again.

You are totally right about deleting Vector Store does not delete the Original file.

But my main focus in this post is to delete this auto-generated Vector Stores as you saw in the screenshot.
(Due to this auto-gen triggered every single time I initiated the conversation with AI Assistant, my Storage in the OpenAI platform looks super messy…)

So I don’t want to delete the original files from the OpenAI platform. (Which I defined it as “fileId_01” in my script).

I need it to remain uploaded on the OpenAI platform for the future conversation with my AI Assistant.

So my question to your suggested code is, if it deletes the auto-generated Vector Stores only and the original file remains in the Files in the platform.

If it doesn’t, I am seeking the way to do that…

Thank you for sharing your knowledge and experiences!

It seems I misunderstood the intention earlier. This command is indeed for deleting a file.

To delete vector data, you need to know the ID of the vector data you want to remove.
You can retrieve the list of objects stored in the vector store using:

openai.beta.vectorStores.list();

But, you will need to specify which of these to delete.

Below is an example structure of a retrieved vector object as shown in the API documentation:

{
  "object": "list",
  "data": [
    {
      "id": "vs_abc123",
      "object": "vector_store",
      "created_at": 1699061776,
      "name": "Support FAQ",
      "bytes": 139920,
      "file_counts": {
        "in_progress": 0,
        "completed": 3,
        "failed": 0,
        "cancelled": 0,
        "total": 3
      }
    },

Looking at the screenshot you provided earlier, it seems like you want to delete the ones labeled as “Untitled store.”

In that case, you should select the vector object where the value corresponding to the “name” key is blank and delete it using the following:

openai.beta.vectorStores.del(Vector.ID)

Here, “Vector.ID” should refer to the ID of the vector object where the value corresponding to the “name” key is blank or None.

{
    "data": [
        {
            "id": "vs_******************",
            "created_at": 1723785730,
            "file_counts": {
                "cancelled": 0,
                "completed": 0,
                "failed": 0,
                "in_progress": 0,
                "total": 0
            },
            "last_active_at": 1723785730,
            "metadata": {},
            **"name": null,**
            "object": "vector_store",
            "status": "completed",
            "usage_bytes": 0,
            "expires_after": null,
            "expires_at": null
        },

This operation deletes objects in the vector store and does not affect the original files.

Semantics is up to you. :computer:

1 Like

Thank you very much for your reply!

Your reply inspired me for a new approach to solve my problem!

I was trying to retrieve Vector Id somehow by calling API; “api.openai/v1/threads”.

But as it is impossible, I decided to write and run a new program which monitors the whether the auto-generated Vector Store is expired or not.

If it is expired I run a code to delete.

This doesn’t trigger the deletion upon the end of conversation with AI assistant, but at least it deletes when it expires by run the script like every week or so.

Anyways, thank you so much for being attentive for this matter!
It was a big support to progress my project!

2 Likes