Grep
Find every passage that holds an exact phrase, ignoring case. For a quoted phrase, an id or an error code that a similarity search would blur.
POST /v1/memory/grepGrep matches a substring, ignoring ASCII case, against each passage's text and heading. It does not rank. It
returns where the phrase is and a fragment around the start of each passage, so the next call can
read or around it. Makes no model call.
Headers
AuthorizationstringBearer tm_…. A read key is enough.
X-Twin-AccountstringThe end user whose memory to search. See End users.
X-Request-IdstringYour id for this request, echoed on the response.
Body
patternstringThe exact text to find. 1 to 2,000 characters. % and _ are matched literally.
scopestringA path prefix to search under, such as passages/memory/notes. Up to 512 characters.
limitintegerHow many matches to return. 1 to 50, default 50.
Response
patternstringThe pattern as sent.
totalintegerHow many passages match, before limit.
matchesobject[]Each match: path, id (the passage id) and text, the first 320 characters of the passage.
Errors
400bad requestX-Twin-Account is missing or not a usable id.
401unauthorizedThe bearer is not a key this service issued.
404not foundno memory for end user 'user_42' yet.
422invalidAn empty pattern, or a limit outside 1 to 50.
503unavailableAt capacity, or this end user is being rebuilt. Retry after Retry-After seconds.
curl https://api.twinmemory.dev/v1/memory/grep \
-H "Authorization: Bearer $TWIN_MEMORY_API_KEY" \
-H "X-Twin-Account: user_42" \
-H "Content-Type: application/json" \
-d '{ "pattern": "peanuts" }'{
"pattern": "peanuts",
"total": 1,
"matches": [
{
"path": "passages/memory/notes/th_1c3a2421d280764f/p_0001.md",
"id": "th_1c3a2421d280764f/p_0001",
"text": "Alice is vegan and allergic to peanuts."
}
]
}