Diagram of an AI application connected to a relational database, a document store, a vector index, a cache, object storage and a data warehouse
Back to Work & InsightsComprehensive Guide

Data Storage for Enterprise AI: SQL, NoSQL, Vector, and Cache

An AI product stores more than embeddings: users and permissions, conversations, agent state, documents, traces, and cached answers. Each has a different shape and access pattern. Pick the store by the job, and add new databases only when the one you have can't do it.

TL;DR

  • There is no single “AI database”. A production AI system usually needs a system of record (SQL), fast temporary state (cache), file storage (object store), and some form of search (keyword, vector, or both).
  • Relational databases like PostgreSQL remain the backbone: users, permissions, billing, workflow state, and audit logs need transactions and joins. With pgvector and full-text search, Postgres can also cover search for small and medium corpora.
  • NoSQL earns its place for flexible or massive data: document stores for varied JSON records, key-value stores for huge request volumes, graph databases for relationships, and time-series or warehouses for analytics.
  • Cache sits in front of everything: sessions, rate limits, tool results, and semantic caches of model answers. Treat cached data with the same access rules as the source, and give every entry an expiry.
Storage architecture · Typical API wrapper

Put everything into one vector database and hope it scales

Storage architecture · FDE architecture

Postgres as the system of record, plus cache, object storage, and search added for specific jobs

01 · Definition

The main kinds of storage, and what each is for

Each type of store is built around one access pattern. Problems usually start when a store is used for a pattern it wasn't designed for.

Relational (SQL)
PostgreSQL · MySQL · SQL Server

Tables, joins, and transactions. The source of truth for users, roles, orders, workflow state, and audit logs, where data must be consistent and correct.

Document (NoSQL)
MongoDB · Firestore · Cosmos DB

JSON documents with flexible fields. Good for records whose shape varies, such as extracted form data or chat transcripts with mixed content.

Key-value / wide-column
DynamoDB · Cassandra · Bigtable

Lookups by key at very high volume with predictable latency. Good for per-user session history or event streams at scale. Weak at ad-hoc queries.

Vector index
pgvector · Pinecone · Qdrant · Weaviate

Finds items with similar meaning by comparing embeddings. Used for semantic search, recommendations, deduplication, and semantic caching.

Search engine
Elasticsearch · OpenSearch · Postgres FTS

Keyword search with ranking, filters, and facets. Still the best at exact terms, IDs, and product codes, which embeddings often miss.

Graph
Neo4j · Amazon Neptune

Entities and relationships, queried by following links. Good for knowledge graphs, org structures, and fraud or dependency analysis.

Cache (in-memory)
Redis · Valkey · Memcached

Very fast, temporary storage in memory. Sessions, rate limits, queues, recent tool results, and cached model answers, each with an expiry time.

Object storage & warehouse
S3 · GCS · Snowflake · BigQuery

Object storage holds files: PDFs, audio, images, model outputs. Warehouses hold large historical data for analytics, reporting, and building eval sets.

02 · Mapping

Which AI data belongs in which store

Users, roles, permissions
Relational. Every AI answer and tool call should be checked against this, so it must be correct and consistent.
Agent and workflow state
Relational, for long-running tasks that must survive restarts. A cache only for short-lived steps that can be safely lost.
Conversation history
Relational or document store for most products. Key-value store when you have millions of active users and only read by conversation ID.
Source documents & files
Object storage for the files themselves, with metadata (owner, version, permissions) in the relational database.
Embeddings
pgvector next to the metadata for most corpora. A dedicated vector database when you reach many millions of vectors or need very low latency.
Knowledge & relationships
Graph database, or relational tables with foreign keys, when questions follow links (who owns what, what depends on what).
Cached answers & tool results
Redis with a time-to-live, scoped by tenant and user. Never the only copy of anything important.
Traces, costs, feedback
Append-only logs into a warehouse or analytics store. This is the raw material for evals, dashboards, and fine-tuning.
03 · Worked example

An HR policy assistant, two ways

A 5,000-person company wants an assistant that answers HR questions, cites the policy, and can open a leave request on the employee's behalf.

“How many vacation days do I have left, and can you book Dec 22–26 off?”
One vector DB for everything
Policies, users, and history as embeddings
  1. 01Embed the question and fetch similar chunks
  2. 02Gets the general vacation policy, but not this employee's balance
  3. 03No transaction to book the leave; writes a note into the vector store
  4. 04Any employee's question can match another employee's stored chats
Right store per job
Each piece of data where it belongs
  1. 01Postgres: look up the employee, their country, and leave balance
  2. 02Search (keyword + vector) over policies for that country only
  3. 03Postgres transaction: create the leave request and log the action
  4. 04Redis: cache the policy answer for others in the same country, 24h

The vector index is still useful, but only for finding the right policy text. Facts about a person and actions that change data belong in the system of record.

async function handleQuestion(userId: string, question: string): Promise<Answer> {
  const user = await db.users.findById(userId)            // Postgres: identity, role, region
  if (!user) throw new Error("Unknown user")

  const cacheKey = `policy:${user.region}:${normalize(question)}`
  const cached = await redis.get(cacheKey)                // Redis: shared, non-personal answers
  if (cached) return JSON.parse(cached)

  const passages = await search.hybrid(question, {        // keyword + pgvector
    filter: { region: user.region, visibleTo: user.role },
    limit: 8,
  })
  const balance = await db.leave.balanceFor(user.id)      // personal facts from SQL
  const answer = await model.generate({ question, passages, balance })

  if (!answer.usesPersonalData) {
    await redis.set(cacheKey, JSON.stringify(answer), { EX: 86_400 })
  }
  await warehouse.log({ userId, question, cost: answer.cost }) // traces for evals
  return answer
}
One request touches several stores. Permissions come from the system of record, not the vector index.
04 · Failure modes

Common storage mistakes in AI systems

Vector DB as system of record

Customer records live only as embeddings plus metadata in the vector index.

Keep the source of truth in SQL or object storage. The index is a derived copy you can rebuild.

Permissions lost in the index

Documents are embedded into one shared index, and search returns chunks the user isn't allowed to see.

Store owner and access fields with every chunk, and filter by the user's permissions on every query.

Stale embeddings

A policy is updated, but its old chunks stay in the index and keep being cited.

Version documents, re-embed on change, and delete old chunks in the same job.

Cache as a database

Agent state lives only in Redis; a restart or memory eviction loses hours of work.

Use cache for speed only. Anything you can't afford to lose goes to a durable store.

Too many databases too early

A small team runs Postgres, MongoDB, Pinecone, Neo4j, and Elasticsearch for a pilot.

Start with Postgres (plus pgvector and full-text search), Redis, and S3. Add a store when you hit a measured limit.

Embedding model lock-in

The team switches embedding models and finds that every stored vector is now incompatible.

Record the model and version with each vector, keep the source text, and plan for full re-indexing.

05 · Decision

Do you need more than Postgres, Redis, and S3?

Your score: 0 / 6

Postgres, Redis, and S3 are enough

Use Postgres for records, state, pgvector, and full-text search; Redis for cache and sessions; S3 for files. One database to back up, secure, and monitor.

06 · Trade-off

What each choice costs

Every new store
Another system to secure, back up, monitor, and keep in sync, and another place where permissions can be wrong. The cost is ongoing, not one-time.
Managed vs. self-hosted
Managed services (RDS, Pinecone, ElastiCache) cost more per unit but save operations work. Self-hosting pays off only with a team that runs databases well.
Consistency
Copies in search indexes, vector stores, and caches always lag behind the source. Decide how stale each one can be, and design updates around that.
Data residency & compliance
Enterprise customers ask where their data, embeddings, and logs are stored and how they are deleted. Embeddings and caches count as customer data too.

Embeddings can leak information about the text they came from, so they need the same protection as the original documents. A right-to-delete request has to reach the database, the vector index, the cache, the object store, and the logs.

07 · Playbook

How to design the storage layer

  1. 01List every kind of data the AI system reads or writes: records, files, conversations, embeddings, state, logs.
  2. 02For each, write down how it's accessed: by ID, by query, by meaning, by relationship, or in bulk for analytics.
  3. 03Start with Postgres as the system of record, S3 for files, and Redis for cache and sessions.
  4. 04Add pgvector and full-text search in Postgres; measure search quality and latency on real questions.
  5. 05Attach permissions, version, and source ID to every derived copy (chunks, vectors, cache entries).
  6. 06Move a workload to a specialized store only when measurements show Postgres can't handle it.

Tooling options

Default system of record
PostgreSQL + pgvector

Relational data, JSON columns, full-text search, and vector search in one database. Supabase and Neon offer it managed.

Cache & sessions
Redis / Valkey

Caching, rate limits, queues, and vector similarity for semantic caches, all with expiry built in.

Dedicated vector DB
Pinecone / Qdrant / Weaviate

For very large vector collections, strict latency targets, or advanced filtering beyond what pgvector handles well.

NoSQL at scale
DynamoDB / MongoDB

DynamoDB for key-based access at massive scale; MongoDB for flexible document data with rich queries.

Keyword & hybrid search
Elasticsearch / OpenSearch

Mature full-text search with ranking and facets, plus vector fields for hybrid search.

Files & analytics
S3 + Snowflake / BigQuery

Durable file storage, and a warehouse for traces, usage, and building eval datasets.

More guides

Want this built into your workflow?

I help small and mid-size teams decide what to build, then build it, from the first eval set to production guardrails.

Talk through your use case