Build or buy an AI memory layer
The first version of an AI memory is small: a table, a call to an embedding model and a similarity query. Many teams build it and it works. The rest of the work comes later and is prompted by other things, such as a support ticket, a customer’s questionnaire or a memory that has grown for a year. The pieces below are the ones we ended up building for CrystalBrain, each with what it involves. After them we say when we think building them yourself makes sense. We sell a memory layer, so read that second part with that in mind.
Storage, embeddings and search bounded per user
The core needs a database with vector search, an embedding model and one query. CrystalBrain uses Postgres with pgvector and embeddings from Voyage AI. Two details take more thought than the rest.
The first is the boundary between users. The filter on the user has to be part of the vector search itself. If you search first and filter afterwards, a user with few memories gets empty results because the nearest vectors all belonged to someone else, and a mistake in the filter returns another person’s memories. In CrystalBrain every search function takes the workspace and the user as arguments.
The second is that the embedding model is a commitment. The size of the vectors is fixed in the database column, and vectors from two models cannot be compared, so changing model means computing every embedding again.
Duplicate handling
A model that saves what it learns will save the same thing many times. The cheapest moment to stop a duplicate is the save: compare the new text with what the topic already holds and refuse it above a similarity threshold. CrystalBrain refuses a save at 0.92 or more within the same brain. This is one query and one threshold, and choosing the threshold takes some testing on your own data.
An admin tool to open and fix one user’s memory
You need this tool from the first support ticket that says “your assistant told me something odd”. Someone has to find the user, read what the AI holds about them, find the entry behind the answer and correct it. Without a tool that person is a developer with database access, and the correction is a SQL statement.
A usable tool needs a search of users by name, ID or email, a list of one user’s memories, an edit screen, an archive action that can be reversed, and the earlier versions of an edited memory. It also needs sign-in and roles, because the people who fix memories are not all people who should change settings. This is ordinary application work, and there is a lot of it.
Contradiction checks
Finding two memories that disagree cannot be done with similarity alone, because a contradiction and a repetition look alike to an embedding. It takes a pipeline: select candidate pairs by similarity, have a language model read each pair, store the verdicts, and show the contradictions to a person who decides. Around it you need a schedule, a limit on what the model calls may cost, and a way to undo what the check did, since the model will sometimes be wrong. We describe ours in how an AI memory ends up contradicting itself.
Activity logging
To explain an answer you need to know what the AI searched for and what it received. That means a log of every search with its question, the memories returned, their scores, the tokens sent and the app that asked, and a record on each memory of who wrote it and how often it was read. The same data feeds the figures that tell you whether the memory is used, which we cover in measuring an AI memory. A log is quick to add. The screens that make it readable by someone other than its author are the larger part.
Clean-up of stale memories
A memory that only grows fills with entries that the AI no longer reads. Cleaning it needs a definition of stale (in CrystalBrain, neither read by the AI nor kept by a reviewer for a number of days that you set), a job that finds those memories, and a decision on whether a person reviews them or they are archived automatically. Either way the clean-up should archive and not delete, so that a memory that turns out to matter can come back.
Deletion
Users can ask for their data to be erased, and customers will ask how you do it. Deleting a user from a memory touches more than the memories table: earlier versions, files and their passages, search logs, and anything else keyed on the user. It also needs protection against deleting the wrong person. We go through the list in deleting a user from an AI memory.
API and MCP
Finally the memory has to be reachable by everything that uses it. For your own code that is an API with keys that can be revoked, a rate limit, stable error codes and a reference. For Claude and other MCP apps it is an MCP server with a sign-in flow. If only one app of yours uses the memory, a few internal functions are enough and this piece can wait.
When building makes sense
We see four situations where building your own is the better choice.
- Memory is the core of your product. If how you store and retrieve what users said is what makes the product different, you need to control every part of it, and a general layer will get in your way.
- The data cannot leave your infrastructure. CrystalBrain is a hosted service. Its database is in Paris, and text is processed by providers in the United States, as our privacy policy lists. If your contracts rule that out, a hosted layer is not an option.
- You have one AI feature and a small number of users. A table and a query are enough, and most of the pieces above can wait until something asks for them.
- You already have the surrounding tools. A team with an internal admin console, a logging pipeline and a data deletion process can add memory to them at a lower cost than a team starting from nothing.
When buying makes sense
The case for buying is strongest when several AI features should share what they know about a user, when people outside engineering need to read and fix memories, and when customers have started to ask what is stored and how it is deleted. In those cases the core is a small share of the work, and the pieces around it are the ones that a team would prefer not to maintain. Our demo of per-customer memory for an AI ad generator follows a SaaS that made this choice.
If you want to judge by trying, the Free plan covers up to 25 tracked users a month, and every memory can be exported as CSV, so you can take what you stored with you.