Course contentsShow
← AI Engineering
Lesson 945 of 1,88623. LLM Application Architecture PatternsFree lesson

Document Storage for User Data and Context

Explore document databases and object storage solutions for managing user-uploaded files and unstructured data.

Document Storage for User Data and Context

What you'll learn: How to store and manage user-uploaded files and unstructured data like documents, images, and conversation histories in LLM applications.

The Core Challenge

When users upload PDFs, images, or other files to your LLM application—or when you need to preserve rich conversation context beyond simple session data—traditional relational databases become awkward. You need storage that handles variable-sized, unstructured content efficiently without forcing everything into rigid tables.

Two Main Solutions

Document Databases like MongoDB store data as flexible JSON-like documents. Think of them as filing cabinets where each folder can have a different structure. Perfect for:

  • Conversation histories with metadata (timestamps, user ratings, model versions)
  • User profiles with varying attributes
  • Parsed document chunks with embeddings and source references

Object Storage (AWS S3, Google Cloud Storage, Azure Blob) treats files as immutable objects identified by keys—like a massive warehouse with numbered bins. Ideal for:

  • Original uploaded files (PDFs, images, audio)
  • Large text documents before chunking
  • Generated outputs (reports, images)
  • Model artifacts and prompts versioned over time

When to Use Which

Use document databases when you need to query or update structured metadata frequently (e.g., "find all conversations where user gave thumbs-down"). Use object storage for raw files where you mostly just write-once and read-by-key.

Many systems use both: store the actual file in S3, store metadata and processing status in MongoDB, linking them with a reference key.

Key Takeaway: Document databases and object storage complement each other—use document databases for queryable, semi-structured data and object storage for large, immutable files, often combining both in production LLM applications.