Skip to content

Collections

Collections provide a lightweight, workspace-scoped item store backed by PostgreSQL with a pgvector similarity index. Use collections to manage reusable content such as prompt templates, tool definitions, or procedures, grouped by a collection_name.

All collection endpoints operate on the workspace of the authenticated request. Reads require collections:read, creates and updates require collections:write, and deletes require collections:delete.


Create a Collection Item

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/collections" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"collection_name": "prompts",
"name": "summarize-email",
"content": "Summarize the following email thread into 3 bullet points...",
"item_type": "prompt_template",
"tags": ["email", "summarization"],
"metadata": {"version": "1.2"},
"enabled": true
}'

Returns 201 Created with the item, including a generated id (prefixed col_), tenant_id, workspace_id, created_at, and updated_at.

Fields:

FieldRequiredDescription
collection_nameYesLogical grouping name (must not be empty)
nameYesItem name
contentYesItem content (text)
item_typeNoFree-form type label within the collection
tagsNoList of string tags
metadataNoArbitrary key-value metadata
enabledNoWhether the item is active (default true)

List Items

Terminal window
# All items in the workspace
curl "$MEMORYLAYER_URL/v1/collections?limit=50&offset=0" \
-H "Authorization: Bearer $API_KEY"
# Filter by collection name
curl "$MEMORYLAYER_URL/v1/collections?collection_name=prompts" \
-H "Authorization: Bearer $API_KEY"

limit defaults to 50 (max 200). The response is {"items": [...], "total_count": N}.


Get a Single Item

Terminal window
curl "$MEMORYLAYER_URL/v1/collections/$ITEM_ID" \
-H "Authorization: Bearer $API_KEY"

Returns 404 if the item does not exist in the workspace.


Update an Item

Only provided fields are updated; others remain unchanged. Updatable fields: name, content, item_type, tags, metadata, enabled.

Terminal window
curl -X PUT "$MEMORYLAYER_URL/v1/collections/$ITEM_ID" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "Updated prompt template text...",
"tags": ["email", "summarization", "v2"]
}'

Delete an Item

Terminal window
curl -X DELETE "$MEMORYLAYER_URL/v1/collections/$ITEM_ID" \
-H "Authorization: Bearer $API_KEY"

Returns 204 No Content on success.


Search collection items by cosine similarity against a query embedding you supply. Only enabled items that have a stored embedding are considered.

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/collections/search" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query_embedding": [0.12, -0.45, 0.78, ...],
"collection_name": "prompts",
"limit": 5
}'

Search parameters:

FieldRequiredDescription
query_embeddingYesQuery embedding vector (length must equal the server’s MEMORYLAYER_EMBEDDING_DIMENSIONS)
collection_nameNoRestrict search to one collection
limitNoMaximum results to return (1—100, default 10)

Results are ordered by similarity (1 - cosine distance):

{
"results": [
{
"item": {
"id": "col_3f9a1c2b7d4e5f60",
"tenant_id": "tenant_abc",
"workspace_id": "my-workspace",
"collection_name": "prompts",
"name": "summarize-email",
"content": "Summarize the following email thread...",
"item_type": "prompt_template",
"tags": ["email", "summarization"],
"metadata": {"version": "1.2"},
"enabled": true,
"created_at": "2026-04-01T12:00:00Z",
"updated_at": "2026-04-01T12:00:00Z"
},
"similarity": 0.92
}
],
"total_count": 1
}

Use Cases

Use CaseCollection NameDescription
Prompt librarypromptsStore and retrieve prompt templates
Tool registrytoolsRegister tool definitions for agent function calling
ProceduresproceduresReusable step-by-step procedures
Code snippetssnippetsReusable code patterns