In OpenClaw, what do the memory_search and memory_get tools each do, and why does an agent usually call them in that order?
answer
- find first, then read
- vectors plus keywords
- path, start line, line count
- transcript hits are not files
- the group:memory tool group
basics
~20 smemory_search ranks indexed memory chunks by meaning and exact terms and returns snippets with their paths; memory_get reads a named memory file or line range. The agent searches to locate a note, then reads only the lines it needs.
solid answer
~40 sBoth tools come from the active memory plugin, `memory-core` by default, and make up the `group:memory` tool group. `memory_search` takes a `query` (optionally `maxResults`, `minScore` and `corpus`) and searches `MEMORY.md`, `USER.md`, Markdown files under `memory/` and any `memory.search.extraPaths`. With an embedding provider it runs vector and BM25 keyword search in parallel, merges them, applies recency decay to dated notes and an MMR diversity pass. `memory_get` takes a `path` with optional `from` and `lines` and returns that excerpt. Searching first finds where something was written; reading second pulls in a bounded slice instead of whole files. When session transcripts are among its sources, search can also return `sessions/...jsonl` hits, which `memory_get` cannot open; those go through `sessions_search` and `sessions_history`.
go deeper
Remember the split: memory_search finds where something is written, memory_get reads a specific file or line range.
Explain the inputs and the ranking: query with maxResults and minScore, path with from and lines, hybrid vector and keyword retrieval, and the 30-day half-life on dated notes.
Show you can tell a tool-policy gap, a provider failure and a ranking miss apart, and that transcript hits need sessions_search and sessions_history rather than memory_get.
Judge which agents should hold group:memory at all, since search covers the agent's indexed notes, not just those written in the conversation asking.
## Why two tools instead of one OpenClaw keeps only the curated `MEMORY.md` in the prompt of a private session; the detailed daily notes in `memory/YYYY-MM-DD.md` stay on disk. To use them, the agent needs a way to **find** the relevant note and a way to **read** it. OpenClaw splits those into two tools, both provided by the active memory plugin (`memory-core` unless another plugin fills the memory slot) and grouped in tool policy as `group:memory`. ## `memory_search`: locate - **Input**: a required `query`, plus optional `maxResults`, `minScore` and `corpus` (`memory`, `wiki`, `all` or `sessions`). - **What it searches**: `MEMORY.md`, `USER.md`, Markdown files anywhere under `memory/`, and any directories listed in `memory.search.extraPaths`. - **Hybrid retrieval**: when an embedding provider is configured, a vector search (meaning) and a BM25 keyword search (exact IDs, error strings, config keys) run in parallel and are merged. Filenames are indexed separately so an exact path or date ranks well. - **Ranking**: the builtin engine multiplies hybrid relevance by a recency decay and an importance multiplier. Dated daily notes decay with a **30-day half-life**; `MEMORY.md`, `USER.md` and undated files under `memory/` are evergreen. An MMR pass then reorders results to avoid near-duplicate snippets. - **Output**: snippets with their source paths and line positions, which is exactly what `memory_get` needs. The tool's own description tells the model it is a mandatory recall step before answering questions about prior work, decisions, dates, people, preferences or todos. ## `memory_get`: read - **Input**: a required `path`, optional `from` (first line) and `lines` (how many), and an optional `corpus`. - **Output**: that excerpt, with a status of `ok`, `not_found` or `error`. An unsupported path is reported as a read error, not as memory being switched off. | | `memory_search` | `memory_get` | |---|---|---| | Question it answers | where is this written? | what exactly does it say? | | Required argument | `query` | `path` | | Bounding arguments | `maxResults`, `minScore` | `from`, `lines` | | Can return session transcript hits | yes, when session indexing is on | no | ## The usual sequence 1. The owner asks about something not in the current conversation. 2. The agent calls `memory_search` with a query in its own words. 3. It picks the promising hit and calls `memory_get` with that path and a line range around the snippet. 4. It answers from the excerpt, and can cite the source path. Reading a slice keeps the prompt small: a daily note can be long, and the agent rarely needs all of it. ## Edges worth knowing - **Session transcripts.** Transcripts join the search sources through session indexing (`memory.search.experimental.sessionMemory: true` plus `"sessions"` in `memory.search.sources`) or through `memory.search.rememberAcrossConversations`, which is on by default for personal installs without DM isolation and implies transcript indexing. Their hits carry `sessions/...jsonl` paths, which are search references rather than files `memory_get` can open. The agent follows up with `sessions_search` and `sessions_history`, which check session visibility on every request. - **Imported memory.** Files imported from other assistants land under `memory/imports/...`; they are searchable and readable but never merged into `MEMORY.md`. - **Embedding provider down.** With the provider left unset (OpenAI embeddings by default) or set to `none`, recall can still fall back to keyword ranking. An explicitly named remote provider that fails makes `memory_search` report memory as unavailable instead of silently degrading. - **Tool policy decides availability.** The `coding` tool profile includes `group:memory`; the `minimal` and `messaging` profiles do not, so an agent on those needs the tools added, for example through `tools.alsoAllow`. A workspace file asking the agent to search memory cannot grant a tool that policy removed. ## Wording a query Because retrieval is hybrid, the two halves reward different queries. The vector half matches meaning, so "the machine running OpenClaw" can find a note that says "gateway host". The keyword half matches exact tokens, so an order number, an error string or a config key is best searched verbatim. When every ranked result falls below `minScore`, search still keeps keyword matches rather than returning nothing, and hybrid search can fill spare slots with keyword-only hits. In keyword-only mode (no embeddings) the wording matters much more: a note that never uses the word in the query will not be found. That is the practical reason to configure an embedding provider, local or remote, on any assistant expected to recall conversations. ## What a good answer shows That search and read are separate steps with separate inputs, that ranking favours recent dated notes and evergreen curated files, and that availability is a tool-policy question rather than a prompt question.
- What does memory_search do when the embedding provider fails?It depends on how the provider was chosen. With `memory.search.provider` unset (OpenAI embeddings by default) or set to `none`, recall can still use keyword FTS ranking. With an explicitly named remote provider such as `openai` or `gemini` that is unavailable at request time, `memory_search` returns an unavailable result instead of quietly degrading, so the broken configuration stays visible.
- Why can't memory_get open a session transcript hit returned by memory_search?A `sessions/...jsonl` hit is a search reference, not a memory file. The agent passes distinctive text to `sessions_search`, then gives its returned session and message identifiers to `sessions_history` for a bounded excerpt. Those session tools enforce session visibility on each request, which a plain file read would bypass.
- memory_search loads every memory file into context and lets the model scan it.
- memory_get takes a natural-language query and returns the best matching note.
- memory_search only matches exact keywords, so paraphrased questions always miss.
- A sessions/...jsonl path from memory_search can be opened directly with memory_get.
- Old daily notes rank exactly like MEMORY.md no matter how old they are.