Skip to main content

Patterns

Patterns capture reusable coding conventions, best practices, and architectural patterns. They can be scoped globally or to specific projects, and adopted across your project portfolio.

Create Pattern

POST /v1/patterns

Request Body

FieldTypeRequiredDescription
titlestringYesPattern title (1-500 characters)
descriptionstringYesFull description with rationale (1-50,000 characters)
scopestringNoglobal (all projects, default) or project (specific projects only)
categorystringNoCategory (e.g. validation, error-handling, auth, testing, max 100 characters)
tagsarrayNoTags for categorization (max 20 tags, each max 100 characters)
example_codestringNoCode snippet demonstrating the pattern (max 50,000 characters)
source_projectstringNoSlug of the project where this pattern originated
metadataobjectNoCustom metadata (max 10KB)

Response 201 Created

{
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas before processing. This ensures type safety and provides clear error messages to clients.",
"scope": "global",
"category": "validation",
"tags": ["api", "validation", "zod", "typescript"],
"example_code": "const schema = z.object({\n name: z.string().min(1).max(255),\n email: z.string().email(),\n});\n\nexport async function POST(req: Request) {\n const body = schema.parse(await req.json());\n // ...\n}",
"source_project_id": null,
"source_project_slug": "northrelay",
"metadata": {},
"adoption_count": 0,
"created_at": "2026-03-17T10:00:00Z",
"updated_at": "2026-03-17T10:00:00Z"
}

curl

curl -X POST https://api.memoryrelay.net/v1/patterns \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas before processing.",
"category": "validation",
"tags": ["api", "validation", "zod"],
"source_project": "northrelay",
"example_code": "const schema = z.object({\n name: z.string().min(1).max(255)\n});"
}'

Python SDK

from memoryrelay import MemoryRelay

client = MemoryRelay(api_key="mem_prod_...")

pattern = client.patterns.create(
title="Zod validation at API boundaries",
description="All API route handlers validate input with Zod schemas before processing.",
category="validation",
tags=["api", "validation", "zod"],
source_project="northrelay",
)
print(pattern.id)

Search Patterns

POST /v1/patterns/search

Semantic search across patterns. Useful for finding relevant patterns when starting work on a new feature.

Request Body

FieldTypeRequiredDescription
querystringYesNatural language search query
limitintegerNoNumber of results (default: 10)
categorystringNoFilter by category

Response

{
"data": [
{
"pattern": {
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas...",
"scope": "global",
"category": "validation",
"tags": ["api", "validation", "zod"],
"adoption_count": 3,
"created_at": "2026-03-17T10:00:00Z",
"updated_at": "2026-03-17T10:00:00Z"
},
"score": 0.92
}
],
"query": "How should I validate API request bodies?",
"total": 1
}

curl

curl -X POST https://api.memoryrelay.net/v1/patterns/search \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "How should I validate API request bodies?",
"limit": 5
}'

Python SDK

results = client.patterns.search(
query="How should I validate API request bodies?",
limit=5,
)
for r in results.data:
print(f"[{r.score:.2f}] {r.pattern.title}")

List Patterns

GET /v1/patterns

Query Parameters

ParameterTypeDefaultDescription
limitinteger20Results per page (1-100)
offsetinteger0Number of results to skip
categorystring--Filter by category
scopestring--Filter by scope: global or project
tagstring--Filter by tag

Response

{
"data": [
{
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas...",
"scope": "global",
"category": "validation",
"tags": ["api", "validation", "zod"],
"adoption_count": 3,
"created_at": "2026-03-17T10:00:00Z",
"updated_at": "2026-03-17T10:00:00Z"
}
],
"next_cursor": null,
"has_more": false,
"total_count": 1
}

curl

curl "https://api.memoryrelay.net/v1/patterns?category=validation&limit=20" \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"

Python SDK

patterns = client.patterns.list(category="validation")
for p in patterns.data:
print(f"{p.title} (adopted by {p.adoption_count} projects)")

Get Pattern

GET /v1/patterns/{id}

Path Parameters

ParameterTypeDescription
idUUIDPattern ID

Response

Returns a single pattern object including example_code if present.

curl

curl https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901 \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"

Python SDK

pattern = client.patterns.get("b1c2d3e4-f5a6-7890-bcde-f12345678901")
if pattern.example_code:
print(pattern.example_code)

Update Pattern

PATCH /v1/patterns/{id}

Path Parameters

ParameterTypeDescription
idUUIDPattern ID

Request Body

FieldTypeRequiredDescription
titlestringNoUpdated title (max 500 characters)
descriptionstringNoUpdated description (max 50,000 characters)
scopestringNoUpdated scope: global or project
categorystringNoUpdated category
tagsarrayNoUpdated tags
example_codestringNoUpdated code snippet
metadataobjectNoUpdated metadata

Response

Returns the updated pattern object.

curl

curl -X PATCH https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901 \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tags": ["api", "validation", "zod", "best-practice"]
}'

Python SDK

updated = client.patterns.update(
"b1c2d3e4-f5a6-7890-bcde-f12345678901",
tags=["api", "validation", "zod", "best-practice"],
)

Delete Pattern

DELETE /v1/patterns/{id}

Path Parameters

ParameterTypeDescription
idUUIDPattern ID

Response

Returns 204 No Content on success.

curl

curl -X DELETE https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901 \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"

Python SDK

client.patterns.delete("b1c2d3e4-f5a6-7890-bcde-f12345678901")

Adopt Pattern

POST /v1/patterns/{id}/adopt

Adopt a pattern for a specific project. This registers the project as using this pattern and increments the pattern's adoption_count.

Path Parameters

ParameterTypeDescription
idUUIDPattern ID

Request Body

FieldTypeRequiredDescription
projectstringYesProject slug to adopt this pattern for (1-100 characters)

Response

Returns the updated pattern object with incremented adoption_count.

curl

curl -X POST https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901/adopt \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"project": "my-api"
}'

Python SDK

client.patterns.adopt(
"b1c2d3e4-f5a6-7890-bcde-f12345678901",
project="my-api",
)

Unadopt Pattern

DELETE /v1/patterns/{id}/adopt

Remove a pattern adoption for a specific project.

Path Parameters

ParameterTypeDescription
idUUIDPattern ID

Query Parameters

ParameterTypeRequiredDescription
projectstringYesProject slug to unadopt

Response

Returns 204 No Content on success.

curl

curl -X DELETE "https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901/adopt?project=my-api" \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"

Python SDK

client.patterns.unadopt(
"b1c2d3e4-f5a6-7890-bcde-f12345678901",
project="my-api",
)
Pattern Discovery

When starting work on a new feature, call POST /v1/patterns/search with a description of what you are building. Your agent can then follow established patterns instead of inventing new approaches.