Skip to content

API quickstart

Use Python, TypeScript or curl to add a document, wait until the Memory has learned it, and search the result.

This walkthrough adds one note to a Memory, waits for learning to finish, and searches for what it said. Choose Python, TypeScript or curl; each follows the same sequence.

You need a Membase account, a Memory you can write to, and a working model with available turns. Create a Memory in the app quickstart and check AI Setup if a run cannot use a model.

In the app, open Connect › Skills › Manage keys › Create key. Name the key, choose Read & write, and select exactly one Memory under Memory access for this walkthrough. Choose an expiry and create the key. Copy the token while it is shown; it is shown only once. The profile permission is optional and is not needed for this example.

One Memory matters: no request names a Memory, so a write lands in the key’s write target, the one text Memory it reaches. A key that reaches several is refused with 422 write_target_required and nothing is written.

Terminal window
export MEMBASE_API_KEY="mbk_…"

The key guide explains rotation and revocation. The curl example and the SDKs call https://api.app.membase.com. Point either SDK elsewhere with base_url / baseUrl or MEMBASE_BASE_URL.

add returns 202 with a receipt ({id, kind, status, learning}) when material is accepted; it does not promise that learning has finished. Read documents.get(id) until every entry of its learning is succeeded before searching for the new content. The status is pending while it waits for a run, processing while one reads it and failed when the run failed. The examples stop on a failed learning run and have a polling limit, so they cannot wait indefinitely.

Install with pip install unibaseio-membase (0.4.0 or newer), save this as quickstart.py, and run python quickstart.py in the shell where you exported the key.

import time
from membase import Membase
client = Membase()
custom_id = "quickstart-ledger-v1"
added = client.add(
"We chose Postgres for the Lumen ledger.",
title="Lumen decision",
custom_id=custom_id,
)
document_id = added["id"]
if not document_id:
raise RuntimeError("Accepted, but the document id is pending. See API troubleshooting.")
for _ in range(60):
learning = client.documents.get(document_id).get("learning") or []
statuses = {entry["status"] for entry in learning}
if learning and statuses == {"succeeded"}:
break
if "failed" in statuses:
raise RuntimeError("Learning failed. Open the Memory's Report in the app.")
time.sleep(5)
else:
raise TimeoutError("Still unread. Check the Memory's Report and model settings before retrying.")
found = client.search("Which database did we choose for the Lumen ledger?")
errors = [p for p in found["partial"] if p["reason"] == "error"]
if errors:
raise RuntimeError(f"Some Memories could not answer: {errors}")
for hit in found["items"]:
print(hit["memory_name"], "·", hit["content"])
if not found["items"]:
print("No matching passages. Inspect the Memory and its latest Report in the app.")

Expect a passage naming Postgres and the Memory it came from. The exact wording can vary. An empty items list is not enough to diagnose a problem: inspect partial first (a Memory named there with reason: "error" could not answer), then the Memory’s learned content and latest Report.

Re-running this example with the same custom_id does not add a second copy: the receipt names the document already there. If learning was deferred or failed, fix the cause and run Update now in the app; resending the same document is not a way to force another learning run. See API troubleshooting.