How to create memory for AI

Hello! My name is Ildar, and I'm developing an AI assistant for programmers in the BayLang AI project. Today I want to tell you how I came to the memory architecture for AI agents.

When I started developing an AI agent, I first stored memory in files. It seemed logical: there is memory.md, there is user_data.md, everything is simple.

But that's not the case.

  • Files were constantly overwritten — the agent updated the memory and lost important context.
  • There were no versions — it was impossible to restore the previous state.
  • AI lost important information — everything was mixed into one pile.
  • Not all files were needed in the context — the agent received unnecessary data.

I came to the conclusion that a database is needed with a separation of memory types and a mechanism for protecting important data.

I realized that the memory of an AI agent should work like a human: there is something that is always "at hand" (contextual memory), and there is something that is stored "in the desk drawer" (notebook).

Context Memory

This is data that is loaded into the context with every request to the AI.

How it works:
- When a user sends a message, the system automatically loads the context memory.
- The AI sees this data "always" — it's like having a note with important reminders always in front of your eyes.
- The volume is limited — you can't load everything at once.

What to store:
- System settings (language, communication style).
- Agent behavior rules.
- Information about the user (name, preferences).
- Current session context.

But if you load ALL of the agent's knowledge into the context, the context will overflow (LLM has a token limit) and the AI will receive too much unnecessary information.

Therefore, another type of memory was invented — the notebook.

Notebook

This is memory with semantic search. The AI does not see this data "always," but can find it by meaning.

How it works:
- Data is stored in a database with vector embeddings.
- When the AI receives a question, the system searches for relevant notes by meaning (not by keywords!).
- Found notes are added to the context for a specific request.

What to store:
- Project knowledge base.
- Interaction history.
- Notes, instructions, documentation.
- Goals, plans, tasks.

Example: The AI asks "Tell me about BayLang." The system searches the notebook and finds notes with the baylang tag, returns relevant data.

Categories and Tags: Knowledge Organization

In the notebook, there are categories and tags for better data organization.

Categories define access level and data type:

CategoryTypeDescriptionExample
public_dataPublicGeneral data that can be shown to everyoneProject information, agent styles
public_docsPublicDocumentation, instructionsGuides, API documentation
public_goalsPublicGoals and plansDevelopment plan, roadmap
public_wikiPublicKnowledge baseTechnical articles, FAQ
user_dataPrivatePersonal information about the userPreferences, communication history
android_maintainSystemAgent's technical dataError logs, debugging
android_preferencesSystemAgent settingsStyles, configuration

Why:
- Security: private user data will not be available to other users or AI assistants.
- Performance: searching only in the desired category is faster.
- Organization: it is easier to find the necessary information.

Tags

Tags are labels for quick search and grouping of notes by topic.

Examples of tags:
- ai-agent — everything about AI agents.
- baylang — materials on the BayLang project.
- communication — communication, interfaces.
- important — important notes (do not delete!).
- task — tasks and todos.
- personal — personal notes.

Why:
- Quick search: "show all tasks" → filter by task tag.
- Grouping: all notes on BayLang → baylang tag.
- Prioritization: important notes → important tag.

Discovery

When a user asks a question, a Discovery occurs — a query to memory.

How it works:

  1. User writes: "Tell me about the BayLang plans"
  2. System sends an API request to Discovery
  3. Loads context memory (system_settings, user_data, rules)
  4. Collects the initial context for the AI
  5. AI responds taking into account all data

Resume

File memory for AI is a dead end. A database is needed with a separation of contextual memory (always in context) and a notebook (semantic search). Categories and tags help organize knowledge, and Discovery collects everything into the initial context for the AI. This works.

Important conclusions:

  1. Files ≠ memory. For production AI agents, you need a structured database.
  2. Context is a resource. Don't load everything into the prompt.
  3. Semantic search > full-text search. AI thinks in vectors, not keywords.
  4. Prioritization saves data. Important notes should not be overwritten.

If you are developing an AI agent — start with the memory architecture. This is the foundation on which everything else depends.

What's next?

Next, I plan to develop the system and add more features.

Publish date: 19 Apr 2026