sema-mem0 0.1.0

Store, search, and manage long-term memories for AI agents through the Mem0 platform API

API reference 6 exports

Exported declarations from this release. Parameter names and descriptions come directly from its source.

mem0/add!

Source :194
(mem0/add! client messages . opts)
Store memories extracted from messages. messages is a plain string (stored as one user message) or a list of {:role :content} maps. Options require at least one identity — :user-id, :agent-id, or :run-id — and may include :metadata (map) and :infer (bool, default true; false stores text verbatim). Returns the decoded add result.
View source definition
(define (mem0/add! client messages . opts)
  "Store memories extracted from messages. messages is a plain string (stored as one user message) or a list of {:role :content} maps. Options require at least one identity — :user-id, :agent-id, or :run-id — and may include :metadata (map) and :infer (bool, default true; false stores text verbatim). Returns the decoded add result."
  (let* ((o (if (null? opts) {} (first opts)))
         (ids (identity-fields o)))
    (when (not (has-identity? ids))
      (error "mem0/add!: no identity — pass :user-id, :agent-id, or :run-id in the options map"))
    (let* ((base (assoc ids :messages (normalize-messages messages)))
           (with-meta (if (nil? (get o :metadata))
                        base
                        (assoc base :metadata (get o :metadata))))
           (body (if (nil? (get o :infer))
                   with-meta
                   (assoc with-meta :infer (get o :infer)))))
      (mem0/request client "POST" "/v1/memories/" body))))

mem0/client

Source :96
(mem0/client . opts)
Build a Mem0 API client map. Options: :api-key (default: MEM0_API_KEY env var), :base-url (default "https://api.mem0.ai"), :timeout in ms (default 30000). Errors if no API key is found.
View source definition
(define (mem0/client . opts)
  "Build a Mem0 API client map. Options: :api-key (default: MEM0_API_KEY env var), :base-url (default \"https://api.mem0.ai\"), :timeout in ms (default 30000). Errors if no API key is found."
  (let* ((o (if (null? opts) {} (first opts)))
         (api-key (or (get o :api-key) (env "MEM0_API_KEY"))))
    (when (nil? api-key)
      (error "mem0/client: no API key found — pass {:api-key \"...\"} or set the MEM0_API_KEY environment variable"))
    {:api-key api-key
     :base-url (string/chop-end (get o :base-url "https://api.mem0.ai") "/")
     :timeout (get o :timeout 30000)}))

mem0/delete!

Source :236
(mem0/delete! client memory-id)
Delete a single memory by its id. Returns the decoded confirmation.
View source definition
(define (mem0/delete! client memory-id)
  "Delete a single memory by its id. Returns the decoded confirmation."
  (when (or (not (string? memory-id)) (string/empty? (string/trim memory-id)))
    (error "mem0/delete!: memory-id must be a non-empty string"))
  (mem0/request client "DELETE"
                (string-append "/v1/memories/" (percent-encode memory-id) "/")
                nil)))

mem0/get-all

Source :226
(mem0/get-all client . opts)
List all stored memories for an identity. Options require an identity — :user-id, :agent-id, or :run-id — and may include :page and :page-size for pagination. Returns the decoded list result.
View source definition
(define (mem0/get-all client . opts)
  "List all stored memories for an identity. Options require an identity — :user-id, :agent-id, or :run-id — and may include :page and :page-size for pagination. Returns the decoded list result."
  (let* ((o (if (null? opts) {} (first opts)))
         (ids (identity-fields o)))
    (when (not (has-identity? ids))
      (error "mem0/get-all: no identity — pass :user-id, :agent-id, or :run-id in the options map"))
    (let* ((params (assoc ids :page (get o :page) :page_size (get o :page-size)))
           (path (build-url client "/v1/memories/" params)))
      (mem0/request client "GET" path nil))))

mem0/request

Source :144
(mem0/request client method path body)
Make a raw Mem0 API request. method is "GET"/"POST"/"DELETE"/...; path an API path ("/v1/memories/") or full URL; body a map (auto-JSON) or nil. Returns the decoded JSON body ({} when empty); raises on non-2xx with method, path, status, and the API's message.
View source definition
(define (mem0/request client method path body)
  "Make a raw Mem0 API request. method is \"GET\"/\"POST\"/\"DELETE\"/...; path an API path (\"/v1/memories/\") or full URL; body a map (auto-JSON) or nil. Returns the decoded JSON body ({} when empty); raises on non-2xx with method, path, status, and the API's message."
  (let* ((url (build-url client path nil))
         (opts {:headers (client-headers client) :timeout (get client :timeout)})
         (resp (if (nil? body)
                 (http/request method url opts)
                 (http/request method url opts body)))
         (status (get resp :status)))
    (if (and (>= status 200) (< status 300))
      (decode-body (get resp :body))
      (error (format "mem0: ~a ~a → ~a: ~a"
                     method path status (api-error-message (get resp :body)))))))

mem0/search

Source :209
(mem0/search client query . opts)
Search stored memories by relevance to query. Options require an identity — :user-id, :agent-id, or :run-id — or an explicit :filters map, plus optional :top-k (result count) and :threshold (min relevance score). Returns the decoded search result.
View source definition
(define (mem0/search client query . opts)
  "Search stored memories by relevance to query. Options require an identity — :user-id, :agent-id, or :run-id — or an explicit :filters map, plus optional :top-k (result count) and :threshold (min relevance score). Returns the decoded search result."
  (when (or (not (string? query)) (string/empty? (string/trim query)))
    (error "mem0/search: query must be a non-empty string"))
  (let* ((o (if (null? opts) {} (first opts)))
         (filters (or (get o :filters) (identity-fields o))))
    (when (or (nil? filters) (empty? (keys filters)))
      (error "mem0/search: no filters — pass :user-id, :agent-id, :run-id, or an explicit :filters map"))
    (let* ((base {:query query :filters filters})
           (with-topk (if (nil? (get o :top-k))
                        base
                        (assoc base :top_k (get o :top-k))))
           (body (if (nil? (get o :threshold))
                   with-topk
                   (assoc with-topk :threshold (get o :threshold)))))
      (mem0/request client "POST" "/v2/memories/search/" body))))
About this reference

Generated with sema-reader 1.37.0 without executing package code. These are source declarations; dynamic exports, aliases, and runtime changes are not inferred.

Archive SHA-256 91317bd79aca42f2edf74c741ba430e59b4afc948a3f7826f554af6f1b337739