LLM-readable documentation index

Structured Memory

Give Extract saved records as context and keep its output for later workflow calls

Hand off to an LLM

Use Structured Memory to give an Extract information missing from a document or save its results for later calls. For example, an invoice workflow can read a supplier's default currency, then save the processed invoice in that supplier's bucket. A claims workflow can keep policy details and extracted correspondence in one bucket per claim.

TermWhat you chooseInvoice example
BucketHow to group related entriesBucket supplier-1042
KindWhat type of record to storeSupplier profile or invoice
Kind versionWhich schema and file requirements to useInvoice schema v1
EntryThe record you want to read or saveInvoice INV-2041
AttributesThe values stored in the entry as JSONInvoice number, amount, and currency
Read selectorWhich entries to pass to ExtractThe supplier profile in supplier-1042

In the web app

Open Data → Structured Memory. Buckets and kinds belong to the selected environment.

  1. In Buckets, select New bucket. Use a key that your workflow caller can supply, such as a supplier or case ID.
  2. In Kinds, select New kind. Define the JSON fields the entry can store and choose whether each entry requires a file.
  3. Open the bucket and select Add entry. Choose a kind, enter a key, and fill in the attributes. The dashboard uses the latest published kind version.

Use Read Memory, Write Memory, or both in a workflow.

Read saved records in a workflow

  1. In the Workflow Editor, add Read Memory and connect it to the Context row of the Extract.
  2. In Tests → Memory → Read, choose a bucket. Select All kinds to read the whole bucket, or choose a kind and optionally a specific entry.
  3. Run the test. Open the call details and expand Read Memory to see which selectors and entries the call captured.

For API calls, copy a read selector from a bucket or entry and pass it in memory.read.

Save Extract results in a workflow

  1. Connect Write Memory after an Extract and choose the kind and version to save. Use the same schema in the Extract and the kind version. Choose a version without a file requirement.
  2. In Tests → Memory → Write, choose an existing bucket and enter an unused key for that kind.
  3. Run the test. A successful Write saves a real entry. Open the call details or the bucket to find it.

To add a field or change the file requirements, open the kind and select New version. Publish when the schema and file settings are ready. Update the Write Memory node if you want it to use that version.

Worked example

The API walkthrough shows how to create a supplier profile, use it to fill in a missing invoice currency, and verify the saved invoice in a call output or webhook.

Memory URIs

Use Memory URIs to identify the entries a call reads or the entry it saves.

UseURINames
Read a bucketbem://memory/buckets/{bucketKey}Every entry in the bucket
Read one kindbem://memory/buckets/{bucketKey}?kind={kindName}Every entry of the kind in the bucket
Read one entrybem://memory/buckets/{bucketKey}/entries/{entryKey}?kind={kindName}One entry. kind is required.
Write an entrybem://memory/buckets/{bucketKey}/entries/{entryKey}The entry the Write Memory node saves

The Write Memory function sets the kind. Pass only the bucket and entry key in memory.write. bem may normalize selectors when it saves them to the call trace.

Versions and saved entries

  • A kind version fixes the schema and file requirements. Publish a new version to change either. Existing entries and Write Memory nodes keep their assigned version.
  • A read selector for a kind matches entries of any version of that kind.
  • To replace an entry, delete it and add it again with the same bucket, kind, and key.
  • Deleting a bucket deletes all its entries and frees the bucket key for reuse.
  • Read JSON attributes by key. bem may return fields in a different order than you submitted them.

How a call reads and writes

  • A Read Memory call takes 1 to 10 selectors and can match up to 20 entries in total. Every named bucket and kind must exist. If all selectors return zero matches, the Extract runs without memory entries.
  • bem resolves read selectors when it accepts the call. The trace stores the selectors and matching entries as trace.readCapture. Later changes to the bucket leave that snapshot intact. Entries are sorted by kind name, then bucket key, then entry key.
  • Each call has one write destination. If several Write Memory nodes run, they use that bucket and entry key with their own kinds.
  • Create the bucket before making the call. To save an entry, use a key that is free for that kind in the bucket.

Files

A kind version can require one file per entry. In the dashboard, select File required and choose the accepted types. In the API, set file.inputTypes to the accepted types, or omit file for entries that store JSON only.

  • {"inputTypes": ["pdf", "png"]} accepts only PDF and PNG files.
  • inputTypes is required and holds at least one type. file: {} and an empty inputTypes array return 400 with MEMORY_REQUEST_INVALID.
  • Entry file types are pdf, png, jpeg, heic, heif, and webp. jpg and jfif are accepted as jpeg.
  • Send the file base64-encoded in file.inputContent of a JSON body, or as the file part of a multipart body.
  • Responses return the file with a short-lived downloadURL. Each response signs a new link.
  • A Write Memory function saves no file, so it can't save under a kind version that has a file rule.
  • When a call selects an entry that holds a file, the call input must be one PDF or one image.

Limits

LimitValue
Selectors per call10
Entries per Read Capture20
Read Memory nodes per workflow1
Entry file size50 MB
Entry file name255 bytes, no control characters
Page size (limit)1 to 200, default 50
Bucket key, kind name1 to 128 letters, digits, _, or -
Entry key1 to 256 letters, digits, _, -, or ., other than . and ..
Violations listed in MEMORY_ATTRIBUTES_INVALID10

List and page

Lists return items sorted by key, with totalCount. To get the next page, pass the last key of the page as startingAfter. For kinds, pass the last name. The bucket list also takes endingBefore.

curl -G https://api.bem.ai/v3/structured-memory/buckets/supplier-1042/kinds/invoice/entries \
  -H "x-api-key: $BEM_API_KEY" \
  -d limit=200 \
  -d startingAfter=INV-2041

Error codes

A Structured Memory route that fails returns a body with error and code.

{
  "error": "attributes do not match the kind schema: at \"\": missing properties 'currency', 'paymentTermsDays'",
  "code": "MEMORY_ATTRIBUTES_INVALID"
}

A workflow call whose memory input doesn't fit the workflow returns the same shape with status 400, and it runs no function. Use code to handle the response and error for details.

CodeStatusMeaning
MEMORY_REQUEST_INVALID400The body, a path key, limit, a cursor, a file rule, an attributesSchema that isn't a valid JSON Schema, or the call's memory input isn't valid.
MEMORY_BUCKET_NOT_FOUND404 or 400No live bucket has the key.
MEMORY_KIND_NOT_FOUND404 or 400No kind has the name.
MEMORY_KIND_VERSION_NOT_FOUND404 or 400The kind has no version with the number.
MEMORY_ENTRY_NOT_FOUND404No live entry has the bucket, kind, and key.
MEMORY_BUCKET_KEY_TAKEN409A live bucket already has the key.
MEMORY_KIND_NAME_TAKEN409A kind already has the name.
MEMORY_IDENTITY_OCCUPIED409A live entry of the kind already has the key in the bucket.
MEMORY_ATTRIBUTES_INVALID400The attributes don't match the kind version's schema. error lists up to 10 violations.
MEMORY_FILE_INVALID400The entry file is missing, not allowed, of a type the rule refuses, not valid base64, or not a file of its type.
MEMORY_KIND_REQUIRES_FILE400A Write Memory function names a kind version that has a file rule.
MEMORY_INPUT_MISSING400The workflow has a Read Memory or Write Memory node, and the call lacks memory.read or memory.write.
MEMORY_INPUT_UNEXPECTED400The call sends memory.read or memory.write, and the workflow has no node that uses it.
MEMORY_URI_MALFORMED400A Memory URI in the call's memory input isn't valid.
MEMORY_READ_LIMIT_EXCEEDED400The call's selectors resolve to more than 20 entries.
MEMORY_SOURCE_TYPE_UNSUPPORTED400A workflow with a Read Memory node can't take this call input. See Read Memory.

A not-found code returns 404 when the path names the missing item, and 400 when the body or the call names it.

Errors during a run

A Read or a Write that fails after bem accepts the call ends the call with an error event. The error event's kind names the failure, and message says what failed.

kindMeaning
memory_read_capture_not_deliveredThe Extract couldn't receive the Read Capture, such as when the entry files are too large to send with the document.
memory_attributes_invalidThe Extract output doesn't match the schema of the Write Memory function's kind version.
memory_identity_occupiedA live entry of the kind already has the write destination's key in the bucket.
memory_bucket_not_foundThe write destination's bucket doesn't exist when the Write runs, such as after it was deleted.
memory_write_destination_invalidThe call has no valid memory.write destination.
memory_write_not_savedbem couldn't save the entry.

A failed Write saves nothing. Retrying the Write function call doesn't run the Extract again.

On this page