Skip to main content
HowOpenClawv2026.3.24

Build a Knowledge Base

Set up a persistent memory system so your agent builds knowledge over time.

By the end of this page, your agent will remember what it researched last week, what you found useful, and what you want to go deeper on — and use that context in future conversations.

Time: ~20 minutes


The problem with stateless research

Without memory, every research session starts from zero. You ask about a topic, get a summary, and it's gone. The next time you ask, your agent doesn't know you already looked at this, what you concluded, or what you still want to know.

Memory fixes this.


How OpenClaw memory works

OpenClaw has a file-based memory system:

  • MEMORY.md in your workspace — a growing text file of facts, notes, and context
  • Your agent reads it at the start of each session
  • You can instruct your agent to write to it during or after a session
  • You can read and edit it directly at any time — it's just a text file

Think of it as a shared notepad between you and your agent.


Step 1 — Enable memory writes in SOUL.md

Open ~/.openclaw/SOUL.md and add a section:

## Memory and research
After any research session:
- Write key findings to MEMORY.md under a dated entry
- Note: topic, sources used, key conclusions, and what's still unknown
- If I express an opinion or preference, note it
- If I say "save this" or "remember this", write it immediately

Format:
## [Date] — [Topic]
[2-4 bullet points of key facts or conclusions]
Sources: [brief list]

Step 2 — Build a research knowledge base

Tell your agent explicitly to build a knowledge base. Example conversation:

"I want to build a knowledge base about [topic]. Start by researching the fundamentals — key concepts, main approaches, and key players. Save everything important to MEMORY.md under a 'Knowledge Base: [topic]' section."

Your agent will research, synthesize, and write structured notes to MEMORY.md.


Step 3 — Query your knowledge base

Once you've built up notes over several sessions, query them:

"What do we have in MEMORY.md about [topic]? Are there any gaps I should fill in?"

Your agent will read the file and give you a summary of what's there and what's missing.


What a good knowledge base looks like

After a few weeks of research sessions, your MEMORY.md might look like:

## 2026-03-15 — RAG Architecture
- Chunk size matters more than model choice for retrieval quality
- Hybrid search (dense + sparse) consistently outperforms pure vector search
- Re-ranking is worth the extra latency for high-stakes retrieval
Sources: papers from Weaviate blog, LlamaIndex docs, Anthropic cookbook
To explore: late chunking, contextual retrieval

## 2026-03-20 — Vector Databases
- Pgvector is good enough for <1M vectors with Postgres
- Qdrant preferred for high-write workloads
- Pinecone only worth it at enterprise scale
Still unclear: cost comparison at 100M+ vectors

## 2026-03-22 — Preferences noted
- Prefer code examples over prose explanations
- Interested in production patterns, not toy examples
- Working in Python, not TypeScript

This compounds. After 30 sessions, you have a personalized reference.


Search your knowledge base

For large MEMORY.md files, add the read tool so your agent can search efficiently:

{
  "tools": {
    "read": { "enabled": true }
  }
}

Then ask:

"Search MEMORY.md for everything about [topic] and give me a summary."


Session memory hooks

For more automatic memory, you can use session hooks. These run after every conversation and let the agent write a summary:

{
  "hooks": {
    "session_end": "Summarize this conversation. If anything new was learned, save it to MEMORY.md with today's date and topic."
  }
}

With this configured, your agent automatically writes session notes without you having to ask.


Goal complete

Your research assistant now:

  • Searches the web and fetches sources on demand
  • Builds structured knowledge over time in MEMORY.md
  • Reads its own notes to give you context-aware answers
  • Gets smarter the more you use it

Where to go next