sema-mem0
0.1.0Store, search, and manage long-term memories for AI agents through the Mem0 platform API
sema-mem0
Store, search, and manage long-term memories for AI agents through the Mem0 platform API.
Install
sema pkg add sema-mem0
Quick start
(import "sema-mem0")
(define c (mem0/client)) ;; reads MEM0_API_KEY
(mem0/add! c "I prefer window seats on flights" {:user-id "alice"})
(mem0/search c "travel preferences" {:user-id "alice" :top-k 3})
;; => {:results (... {:memory "Prefers window seats on flights" :score 0.71 ...})}
(mem0/get-all c {:user-id "alice"})
;; => {:results (...) :count 1 ...}
API
| Function | Description |
|---|---|
(mem0/client opts?) |
Build a client; API key falls back to MEM0_API_KEY. |
(mem0/add! client messages opts) |
Store memories extracted from messages. |
(mem0/search client query opts) |
Search memories by relevance to a query. |
(mem0/get-all client opts) |
List all memories for an identity. |
(mem0/delete! client memory-id) |
Delete a single memory by id. |
(mem0/request client method path body) |
Raw request escape hatch. |
Every memory belongs to an identity: pass at least one of :user-id, :agent-id,
or :run-id in the trailing options map. Responses are JSON-decoded into
keyword-keyed maps; non-2xx statuses raise an error carrying method, path,
status, and the API's own message.
(mem0/client opts?)
Options: :api-key (default: MEM0_API_KEY env var), :base-url
(default "https://api.mem0.ai"), :timeout in ms (default 30000).
(mem0/client) ;; MEM0_API_KEY from the environment
(mem0/client {:api-key "m0-..."}) ;; explicit key
(mem0/add! client messages opts)
messages is a plain string (stored as one user message) or a list of
{:role :content} maps. Options need an identity and may include :metadata
(map) and :infer (bool, default true; false stores the text verbatim).
(mem0/add! c
(list {:role "user" :content "Book me a table for two"}
{:role "assistant" :content "Reserved at 7pm for two"})
{:user-id "alice" :metadata {:topic "dining"}})
(mem0/search client query opts)
Options need an identity (or an explicit :filters map) and may include
:top-k (result count) and :threshold (minimum relevance score).
(mem0/search c "what food do I like" {:user-id "alice" :top-k 5})
(mem0/get-all client opts)
Options need an identity and may include :page and :page-size.
(mem0/get-all c {:user-id "alice" :page 1 :page-size 50})
(mem0/delete! client memory-id)
(mem0/delete! c "0c8...e91")
(mem0/request client method path body)
Escape hatch for endpoints the wrappers don't cover. body is a map (auto-JSON)
or nil.
(mem0/request c "GET" "/v1/memories/abc123/history/" nil)
Authentication
Get an API key from the Mem0 dashboard and export it:
export MEM0_API_KEY="m0-..."
The key is sent as Authorization: Token <key> and is never logged.
Testing
sema tests.sema
Offline tests cover client construction and argument validation. Live tests hit
api.mem0.ai and run only when MEM0_API_KEY is set.
License
MIT
| Version | Size | Published |
|---|---|---|
| 0.1.0 | 6 KB | 2026-07-07 21:28:12 |