Zero Labs
Industry News / AI

The Database Layer Your Agent Stack Is Missing

Source · Towards AI By Towards AI Editorial Team

From the publisher’s feed, collected in the ZeroLabs newsroom.

State persistence, vector search, and fault tolerance are typically three separate systems. They don’t have to be.An Agent Engineering overview of the 2025 framework landscape highlighted a pattern: the agent frameworks gaining production traction are those with strong state persistence, observability, and fault tolerance, not those with the cleanest quick start.All three of those capabilities are database problems. State persistence is a write. Observability is a read. Fault tolerance is a recovery. And in most agent architectures today, those three operations hit three different systems: a primary database for operational state, a vector database for embeddings, and an analytics store for monitoring. The application is left stitching them together.MongoDB five years ago would not have been part of this conversation. It was a document store, popular with Node.js developers, flexible but narrow. That has changed. Atlas Vector Search now runs operational queries and similarity search in the same pipeline, which means one fewer system to sync, one fewer integration to maintain, and one fewer failure boundary in the stack.The question is no longer whether MongoDB can handle vector workloads. It is where it fits alongside Lakebase, Postgres with pgvector, and standalone vector databases. No single tool covers every workload. But the problem of keeping state, retrieval, and application data together without duct tape is one that most teams have not solved cleanly, and it is the right lens for evaluating any of these options.Understanding the Database LayerBefore talking about the databases, imagine a typical support agent.A user asks the agent why their invoice is wrong. The agent has to read the user’s account state, search the knowledge base for billing policies, call a billing API, remember the steps it has already taken, and write a checkpoint before moving to the next step. If the billing API times out halfway through, the agent should not start from the beginning.At that point, the agent is not only storing messages. It also keeps track of what happened, what needs to happen next, which tools returned what, and what data the user is allowed to access. If one of those tool calls fails midway, the database decides whether the agent can continue from the last checkpoint or has to start over.This becomes a very real problem once agents move into production. LangChain’s 2024 survey found that 51% of respondents already had agents in production, and performance quality was the top blocker. Once an agent starts working with real user data, reliability becomes much more important.As soon as a company has more than a few agents running, it must also answer some basic questions. Which tools did the agent call? Which user data did it read? Why did it take a certain step? Where did the workflow fail? That’s the kind of governance and monitoring problem Kore.ai is addressing with its 2026 Agent Management Platform.For that support agent, the database needs to support several things:Fast writes for checkpoints, tool results, and session updatesVector search for finding the right policy, document, or past caseFlexible schema for agent memory that keeps changing shapeEnough scale to handle many agent sessions running at onceLow-latency reads, so the agent is not waiting on the database before every stepEach of these can come from a different specialized database. A lot of teams build that way. The support agent could keep account state in Postgres, embeddings in Pinecone or Weaviate, locks in Redis, and traces in a warehouse. That setup can work, but now there are more things to keep in sync. Data can fall behind, permissions can get out of sync, and debugging can become harder than it needs to be.Database vendors are trying to reduce the distance between agent state, retrieval, and analytics, but they are doing it from different directions. Databricks launched Lakebase in June 2025, bringing a managed Postgres database closer to the lakehouse. Its documentation describes Lakebase as a backend for storing agent state and memory.That is useful when an application already lives close to Databricks. MongoDB is coming from the other side. It starts with operational application data, then adds vector search, change streams, time-series collections, and federated queries around that model. For application-heavy agent systems, the advantage is that agent state, metadata, embeddings, and events can remain within the same application-facing data model rather than being shaped around a lakehouse workflow first.Revisiting the Old MongoDB Mental ModelIf you formed an opinion about MongoDB between 2015 and 2018, you may still remember it as a flexible document database for Node.js apps. It had fewer joins than relational databases, and although the aggregation framework was useful, it felt unfamiliar to many developers.In hindsight, flexible documents were exactly what many web applications needed back then. Teams coming from relational databases were used to designing around normalized tables, foreign keys, joins, and migrations, so MongoDB required a different way of thinking about data modeling.MongoDB has changed quite a bit since then. In 2018, MongoDB 4.0 added multi-document ACID transactions. MongoDB 4.2 extended that to distributed transactions across sharded clusters the next year.Time-series collections arrived for IoT and metrics workloads. Atlas Data Federation made it possible to query across Atlas clusters and object storage without moving everything into one place first. And `$vectorSearch` became part of the aggregation pipeline.So why did so many people miss this? MongoDB never had a big “version 2.0 moment” that forced a re-evaluation. The evolution was incremental, which made it easy to ignore if you weren’t actively following the changelog.But the basic idea remained the same. Application data does not always fit cleanly into fixed tables. In 2010, that mostly meant flexible documents for web apps. In 2025, that same flexibility also matters for agent state, retrieval, and operational events.Vector Search as Part of the Platform ShiftVector search is where the old mental model starts to break down. Adding vectors to a database is one thing. Making vector search work with the rest of the application data is more complex.It is not rare for the vector store and the operational database to fall out of sync. A few seconds can look harmless until an agent retrieves a document the user has already deleted or misses a document that the user just added. These are the kinds of problems that often don’t show up in prototypes but ruin production experiences.MongoDB takes a different approach from the separate vector store setup mentioned earlier. Vector Search is an aggregation stage, not a separate vector database with a separate query API. It has to be the first stage in the pipeline where it appears, but it can apply metadata filters inside the vector search stage itself. After that, the same pipeline can join related data via `$lookup`, group, sort, and project results.In a multi-tenant support system, this means the search can stay inside the correct tenant boundary from the start. MongoDB can filter by `tenant_id` before running vector similarity, then pass the matched documents into the rest of the aggregation pipeline. From there, the query can attach feedback, ratings, or permission metadata without forcing the application to stitch results together from two different systems.Under the hood, ‘$vectorSearch’ uses approximate nearest-neighbor search with the HNSW algorithm. For tenant-aware retrieval, the important part is the index definition. MongoDB lets you define additional filter fields in the vector search index, which is what makes pre-filtering by fields like `tenant_id` possible.The comparison between MongoDB and pgvector is more nuanced. pgvector can store vectors in Postgres, and it supports both exact and approximate nearest neighbor search. If an application is already relational and the team is comfortable tuning Postgres, it may be the right choice.The main tradeoff between MongoDB and pgvector shows up with filtered ANN search. In pgvector, filters are applied after the approximate index scan by default. That does not make pgvector bad, but it does mean teams may need to tune `hnsw.ef_search`, enable iterative scans, or use partial indexes and partitioning for stricter multi-tenant retrieval. In MongoDB, the filter field is part of the `$vectorSearch` query shape once it is defined in the vector search index.There can still be a short delay before a new document update appears in vector search results. The integration is at the query and operational level, not because the vector index lives inside the same collection storage. MongoDB describes Atlas Vector Search indexes as eventually consistent because `mongot` watches change streams and updates its indexed copy of the data.In practice, Atlas manages this async indexing path and exposes it through the aggregation pipeline. Teams are not building and operating a separate sync job to an external vector database themselves. For heavier workloads, dedicated Search Nodes can keep search indexes and search queries on separate nodes from the database nodes.Storing Agent State and CheckpointsIn agent systems, this failure mode is common. The agent starts a workflow, calls a tool or two, and then something fails. Maybe an API times out. Maybe the model returns an unexpected response. Maybe the user does something that changes the state halfway through. At that point, the question is whether the system can pick up from the last useful step or has to start over.In practice, agent state can include a few different kinds of data:Checkpoint documents with tool inputs, outputs, and intermediate stepsConversation history that does not always follow a fixed structureTool results that should expire after a whileHandoff status, locks, or coordination data between agentsA relational database can absolutely be the source of truth here, especially if the application is already relational. Teams may keep session, user, and workflow records in standard tables, then store tool-specific payloads or changing memory structures in JSON columns. That works, but JSON columns do not remove the modeling work. Teams still have to decide which fields deserve first-class columns, which fields can stay buried in JSON, which JSON paths need indexing, and which relationships the database can no longer enforce cleanly.A vector database solves a different problem. It is good at retrieval, but it is usually not the right source of truth for checkpoint updates or tool state. That data needs transactional updates, retries, permissions, and auditability. A vector database may store metadata, but that is not the same thing as being the operational record of what happened.This is where MongoDB’s document model starts to make sense. A checkpoint can look close to the thing the agent actually produced. It may include a tool input, a tool response, some metadata, timestamps, and maybe a list of events. The data still needs thoughtful modeling, and frequently queried fields still need indexes. The difference is that the changing parts of the checkpoint do not immediately force a redesign of the table set every time a tool starts returning one extra nested object.Consider a research agent that calls three tools one after another. One tool returns a neat JSON object. Another returns a long markdown summary. The third one returns an array of image URLs with captions. That kind of output is not impossible to store in a relational database, but it does make you pause to consider the storage schema before you can move on.With MongoDB, the checkpoint can stay as a document. If one of the tools starts returning an extra nested object later on, the code that reads that field can change without first forcing a full rethink of the storage model.Atlas adds operational features on top of that document model. Auto-scaling for handling traffic spikes. Read replicas for distributing query load. Global clusters for placing data close to users. You may not need all of this from the get-go, but it is good to know the database has room to grow once the agent starts getting real traffic.This matters even more in small teams. In larger teams, there may be separate people for the agent framework, the vector database, and another for the operational database. In startups, one person may own all three. When production incidents happen, having fewer moving parts can make a real difference.Choosing Between MongoDB, Lakebase, and pgvectorMongoDB is clearly not the only solution for every AI application. Lakebase and pgvector both make sense. The harder part is knowing when each one makes sense.Figure: Diagram comparing when to choose Lakebase, Postgres with pgvector, or MongoDB based on whether the AI application is lakehouse-first, relational-first, or application-data-firstIf an AI application already lives close to Databricks, Lakebase is a very reasonable choice. Databricks describes Lakebase as a managed Postgres backend for agent state and memory, and that fits naturally with lakehouse governance and analytics workflows. If most of the data, pipelines, models, and permissions already live in Databricks, moving away from it just because MongoDB also supports vector search would not make much sense.The same applies to pgvector. If the application already runs on Postgres and the team is comfortable with SQL, indexes, query plans, and Postgres operations, pgvector may be enough. It preserves joins, constraints, transactions, and the ecosystem that the team already knows. That existing ecosystem matters.MongoDB becomes more interesting when the application data itself refuses to stay in a neat relational shape. Agent checkpoints, tool outputs, conversation memory, tenant metadata, embeddings, and execution events can all change as the agent changes. Teams can model that in Postgres. Some of it can live in JSON columns. Some of it can move into separate services. None of those choices are wrong. But after a while, the application may be doing too much translation work just to keep its own state usable.This is also why MongoDB can be a strong default for fast-changing new projects. In founder-led projects, the product can change shape very quickly. A workflow that looked simple in the first week may need more metadata, more events, or a different state model a few weeks later. MongoDB’s old philosophy of flexible documents, combined with the newer features discussed in this article, fits that kind of work very well.This is not an argument against PostgreSQL. PostgreSQL is still a strong database, and if the project is already relational, it deserves serious consideration. For fast-changing agent workflows, MongoDB can still be the easier starting point.MongoDB’s advantage is not only its vector search. The useful part is that those capabilities work against the state, metadata, tool outputs, and application records already being stored.The point is not that one database is universally better than the others. That framing would be too simplistic. Lakebase brings operational Postgres closer to the lakehouse. MongoDB brings retrieval and events closer to operational application data. Both are useful. They just start from different places.This is why the old mental model is so limiting. If MongoDB is still being evaluated as “just a document store,” then the comparison is not really against today’s MongoDB. It is against a version of the product that no longer exists.ConclusionMongoDB did not become relevant to AI applications by becoming a completely different database. It kept the same basic idea and kept adding the pieces modern applications needed around it: transactions, vector search, time-series collections, change streams, and data federation.The feature list matters less than where those features sit. For document-shaped agent state and operational records, having vector search, change streams, and aggregation close to the document model can simplify the system.For teams that have not looked at MongoDB in years, the Atlas Vector Search documentation and the aggregation pipeline reference are useful starting points. For teams maintaining separate databases for operational state and vector search, the question is not only whether the architecture works. It is how much sync, consistency, and debugging overhead the architecture creates.MongoDB isn’t the right choice for every workload. No database is. But if an opinion was formed years ago and has not been revisited, it may be dismissing a tool that solves problems teams are currently working around.Written by Farhan Hasin ChowdhuryThe Database Layer Your Agent Stack Is Missing was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.