How should file attachments be handled in Azure AI Foundry? Delete after upload or persist for annotations?

Meenakshi Kathiresan 0 Reputation points
2025-12-03T21:52:46.1066667+00:00

Current setup

I am using Azure AI Foundry agents with persistent threads/messages.

A user uploads a file. I call:

await _persistentAgentsClient.Files.UploadFileAsync(
    streamData,
    PersistentAgentFilePurpose.Agents,
    filename,
    cancellationToken);

I attach the uploaded file to the user message (via MessageAttachment).

Immediately after sending the message, the file is deleted from our database and from Azure AI Foundry storage.

This pattern was already part of the project. The original idea seems to be:

  • files are only needed for the run
  • once the run starts, the system ingests/chunks the file
  • therefore the file can be deleted to save space / for security

The Problem

The agent produces annotations (MessageTextFileCitationAnnotation) that reference the file ID. Later, when I fetch past messages from the thread, these annotations still exist, but the underlying file no longer exists. So, I can’t resolve citations. Because the file was deleted as soon as it was attached.


My Questions

1. Should I persist files instead of deleting them?

If the model produces citations tied to file IDs, does Azure AI Foundry expect the developer to persist files long-term?

Or is the intended usage to treat uploaded files as ephemeral?

2. Should I maintain a vector store per thread?

If files are meant to be long-lived context, does best practice involve storing them in a vector store per conversation and referencing those instead of raw attachments? Or is it an overkill to have one vector store per conversation. Do the files get chunked/embedded when sent as attachments?

3. What are the trade-offs between keeping files vs storing in vector store?

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SRILAKSHMI C 10,805 Reputation points Microsoft External Staff Moderator
    2025-12-04T11:17:20.9233333+00:00

    Hello Meenakshi Kathiresan,

    Welcome to Microsoft Q&A and Thank you for reaching out.

    This is the correct direction, and your assumptions are valid. Let me clarify how the Azure AI Foundry Agents system handles files today, and what the expected pattern is when using persistent threads + annotations.

    1. Should files be persisted instead of deleted?

    Yes, if you need citations later

    Agents do not copy file contents into the thread. They only keep a file ID reference, and annotations/citations point back to that file ID.

    If the file is deleted:

    • the thread history still shows citations

    but the underlying file is gone

    therefore citations can’t be resolved

    So if your product allows users to reopen older messages or view citations, the file must remain available.

    If you want annotations to work later → don’t delete files immediately. Keep them for as long as the conversation history needs to remain valid.

    2. Do files get chunked/embedded automatically? Do I need a vector store per thread?

    When you attach a file to a message, the agent chunks and processes the file for that run only.

    That embedding is not stored anywhere permanently.

    Each new run processes the file again.

    You only need a vector store if:

    the same documents must be reused across many conversations,

    you want global semantic search,

    or this is acting like a knowledge base.

    You do not need a vector store per thread unless conversations are extremely long and reuse large numbers of documents. For typical file uploads inside a single thread, a vector store is unnecessary.

    3. Files vs Vector Store — What’s the trade-off?

    Keeping files (recommended for your scenario):

    Pros

    Required for citations to work

    Simple, native agent workflow

    No extra infra

    Cons

    You pay for storage

    You must clean up old files

    Vector Store:

    Pros

    Helps when many threads or users need to reuse the same documents

    Faster retrieval for large corpora

    Good for building a knowledge base

    Cons

    • More architecture and cost
    • Does not eliminate the need to keep original files if you rely on citations (citations always reference the file ID, not the vector entry)

    Do not delete the uploaded files immediately. Keep them for as long as users need to view past messages or citations.

    Use a retention policy. Example: keep files for 30 days or until the thread is archived, then delete safely.

    Only introduce a vector store if you need cross-conversation retrieval or a shared knowledge base. It is not required for normal citation-based workflows.

    This approach preserves citation integrity while keeping your storage footprint predictable. your storage footprint predictable.

    I Hope this helps. Do let me know if you have any further queries.


    If this answers your query, please do click Accept Answer and Yes for was this answer helpful.

    Thank you!


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.