Access array of FilesID attached to an Assistant

Hello y’all

I’m trying to access from the API the file IDs of the files attached to an assistant. In the API documentation there is not a reference to this particular task.

I feel like the ‘Assistant Object’ when retrieved should have an array of file IDs and vector spaces IDs, but there is none.

Not correct. When you retrieve the Assistant using this:

GET https://api.openai.com/v1/assistants

You will get the Assistant Object. In this returned object you’ll have Tool Resource. If you’ve attached Vector Store to you assistant, this will come under this Tool Resource. Check this screenshot:

image
Let me know if this answered your question.

Hi, how do i access the vector_store_ids? Currently, how can i access an assistant which has files stored in playground? How can i connect such an assistant to my chatbot?

This is how:

This is very wide question, for this you’ll need to follow all steps, like upload file, add files to vector store, create assistan, create thread, create message, run thread and then retrieve the messages again(or streaming). If you have any specific question on how to implement the assistant as chatbot, do let us know here.

So my question is, currently my chatbot is unable to access the file store and provide a response from it. Do we need add the file store id while creating thread/message?

try {
    const response = await axios.get(`https://api.openai.com/v1/assistants/${assistantId}`, {
      headers: {
        'Authorization': `Bearer ${OPENAI_API_KEY}`,
        'Content-Type': 'application/json'
      }
    });

  await openai.beta.threads.create(
        messages=[ { "role": "user", "content": lastUserMessage} ],
        tool_resources={
          "file_search": {
            "vector_store_ids": "id"
          }
        }
      )

      let formattedMessages = await retrieveAndSendMessages(thread.id, res);

This is the code I’m using, passing in the assistant key and then creating a thread, but I am unable to receive response from the file store.

You can add your vector store to both Thread and Assistant. It depends on your use case.

My use case is, I have a chatbot in react. I want to connect that to the assistant and receive responses based on the file store. But currently I get response saying it does not have any file.

files are not talked about like “do you have the file” when you have a vector store.

Instead what you must have enabled in the assistant is file_search tool, and if the files are part of the permanent purpose of the assistant, then the vector store should be attached to the assistant id with create or modify assistant.

Then the tool name that is actually presented to the AI is myfiles_browser. It has a search method. It is best if your assistant instructions tell the AI what it doesn’t know and therefore must perform a search on, and also what information is actually behind the file search as part of its operations. You must counter some stupid instructions accompanying the tool that there are “user uploaded” files with your own instructions.

The search return is chunks of documents by similarity to the search results. You therefore cannot ask questions like “summarize the entire dog grooming article”.

There are methods to investigate the files previously added to a store:

GET https://api.openai.com/v1/assistants/{assistant_id}

Return assistant object. Must have both tools: type->file_search, and tool_resources->file_search->vector_store_ids from which you can obtain connected vector stores.

List vector store files

get https://api.openai.com/v1/vector_stores/{vector_store_id}/files?limit=100

Complete listing. You must use more query terms besides limit if you get 100 file results indicating there may be more, then needing pagination through multiple calls.

GET https://api.openai.com/v1/vector_stores/{vector_store_id}/associations?limit=10

Undocumented, returns objects that have the store connected, with thread objects or assistant objects. (might be session key only, since you can reverse to thread ids)

GET https://api.openai.com/v1/assistants_models

Like the models endpoint, but returns whether retrieval (nee file_search) can be used with each model. So you can block yourself from using the wrong model.

2 Likes

Screenshot 2024-05-18 at 8.23.52 PM

When I call GET https://api.openai.com/v1/assistants/{assistant_id}, I receive these options in my response object. There’s no files_search or tool sources to retrieve the vectore_store_ids. I also see file_search given as retrieval in tools, confirmed by toggling it off in playground. I am trying to retrieve the vector ids by passing the id in playground but facing an issue. Thank you for your detailed response, I appreciate it.

That indicates that you are not passing a v2 header, perhaps using an openai library that is too old.

1 Like

I think you’re using OpenAI Assistant V1. You can migrate your Assistant from V1 to V2, check this migration Guide. If you need a video tutorial, check this video also on OpenAI Assistant V2.

Once you successfully implement V2 and if you run the GET CURL you mentioned above, you’ll see the below response:

{
  "id": "asst_abc123",
  "object": "assistant",
  "created_at": 1699009709,
  "name": "HR Helper",
  "description": null,
  "model": "gpt-4-turbo",
  "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.",
  "tools": [
    {
      "type": "file_search"
    }
  ],
  "metadata": {},
  "top_p": 1.0,
  "temperature": 1.0,
  "response_format": "auto"
}

That was it, works now and receiving the required response from the file_search but soon after a couple of tries I get this error now - [You exceeded your current quota error]

Although there is enough balance on my account. Any idea? Also thank you so much, appreciate your help.

That was it, i have updated my library and now it works. After two tries though i get this error - rate limit exceeded? Even though my limit is way more on account. Thanks!

Can you show the screenshot of the credits you are left with?

Hi I have one other question, How do i append or add the next message to my current thread? Because currently the assistant response back with the initial response even though i have changed the question

You likely need to purchase credits for the above error. You probably figured that out.

A thread is a record of a chat session. You create a thread. Get its id number. Add a user message to the thread. Run. Get the assistant response added to the thread.

You are then ready to repeat the process by adding a new user message to the thread id. Then the conversation continues.