Skip to content

Collections

Collections provide a lightweight key-value store with vector similarity search. Use collections to manage reusable content such as prompt templates, tool definitions, knowledge base entries, or any items that benefit from semantic retrieval.


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
}'

Fields:

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

List Items

Terminal window
# All items across collections
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"

Get a Single Item

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

Update an Item

Only provided fields are updated; others remain unchanged.

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"

Search collection items by vector similarity. Provide a pre-computed embedding vector as the query.

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 (must match collection dimension)
collection_nameNoFilter search to a specific collection
limitNoMaximum results to return (1—100, default 10)

Response includes items ranked by similarity score:

{
"results": [
{
"item": {
"id": "col_abc123",
"collection_name": "prompts",
"name": "summarize-email",
"content": "Summarize the following email thread...",
"tags": ["email", "summarization"],
"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 by semantic similarity
Tool registrytoolsRegister tool definitions for agent function calling
Knowledge basekb-articlesSearchable knowledge base entries
FAQfaqFrequently asked questions with semantic lookup
Code snippetssnippetsReusable code patterns searchable by description