> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memvid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n

> Production n8n integration with Memvid REST API and importable workflow

Integrate Memvid with n8n using HTTP Request nodes and a reusable production workflow.

<Info>
  **API-based integration.** This guide uses `https://api.memvid.com` directly (no SDK and no local `.mv2` file).
</Info>

## Prerequisites

* A Memvid API key (`mv2_...`)
* n8n instance (cloud or self-hosted)
* Optional: existing memory ID

## Set Up Credentials in n8n

1. Create a new **HTTP Header Auth** credential in n8n.
2. Set:
   * Header Name: `Authorization`
   * Header Value: `Bearer mv2_YOUR_API_KEY`
3. Reuse this credential across all Memvid HTTP Request nodes.

You can also use `X-API-Key: mv2_YOUR_API_KEY` if preferred.

## Golden Path Workflow

1. Create memory (once)
2. Add documents
3. Find context
4. Ask with RAG

## Importable n8n Workflow JSON

Import the following JSON in n8n (**Workflows -> Import from Clipboard**). It creates a simple manual pipeline for `create -> ingest -> find -> ask`.

```json theme={null}
{
  "name": "Memvid API Golden Path",
  "nodes": [
    {
      "parameters": {},
      "id": "manual-trigger",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            { "name": "memoryName", "value": "n8n Support KB" },
            { "name": "question", "value": "What is our P1 SLA?" },
            { "name": "query", "value": "How fast should P1 incidents be acknowledged?" }
          ]
        }
      },
      "id": "seed-input",
      "name": "Seed Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [460, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.memvid.com/v1/memories",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\"name\": $json.memoryName, \"description\": \"Created from n8n workflow\"}"
      },
      "id": "create-memory",
      "name": "Create Memory",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300],
      "credentials": {
        "httpHeaderAuth": {
          "name": "Memvid API Key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.memvid.com/v1/memories/{{$json.id}}/documents",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\"documents\":[{\"title\":\"Escalation Policy\",\"text\":\"P1 incidents must be acknowledged within 10 minutes.\",\"tags\":[\"support\",\"policy\"]}]}"
      },
      "id": "add-document",
      "name": "Add Document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 300],
      "credentials": {
        "httpHeaderAuth": {
          "name": "Memvid API Key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.memvid.com/v1/memories/{{$node[\"Create Memory\"].json[\"id\"]}}/find",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\"query\": $node[\"Seed Input\"].json[\"query\"], \"topK\": 5}"
      },
      "id": "find",
      "name": "Find",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1180, 220],
      "credentials": {
        "httpHeaderAuth": {
          "name": "Memvid API Key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.memvid.com/v1/memories/{{$node[\"Create Memory\"].json[\"id\"]}}/ask",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\"question\": $node[\"Seed Input\"].json[\"question\"], \"options\": {\"model\":\"gpt-4o-mini\",\"includeSources\": true}}"
      },
      "id": "ask",
      "name": "Ask",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1180, 380],
      "credentials": {
        "httpHeaderAuth": {
          "name": "Memvid API Key"
        }
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [[{ "node": "Seed Input", "type": "main", "index": 0 }]]
    },
    "Seed Input": {
      "main": [[{ "node": "Create Memory", "type": "main", "index": 0 }]]
    },
    "Create Memory": {
      "main": [[{ "node": "Add Document", "type": "main", "index": 0 }]]
    },
    "Add Document": {
      "main": [
        [{ "node": "Find", "type": "main", "index": 0 }],
        [{ "node": "Ask", "type": "main", "index": 0 }]
      ]
    }
  }
}
```

## Node-by-Node Reference

### 1) Create Memory

Add an HTTP Request node:

* Method: `POST`
* URL: `https://api.memvid.com/v1/memories`
* Authentication: your Memvid header credential
* Body (JSON):

```json theme={null}
{
  "name": "Customer Support KB",
  "description": "Docs and runbooks for support agents"
}
```

Store `id` from the response as `memoryId` in your workflow.

### 2) Add Documents

Add another HTTP Request node:

* Method: `POST`
* URL: `https://api.memvid.com/v1/memories/{{$json.memoryId}}/documents`
* Body (JSON):

```json theme={null}
{
  "documents": [
    {
      "title": "Escalation Policy",
      "text": "P1 incidents must be acknowledged within 10 minutes.",
      "tags": ["support", "policy"]
    }
  ]
}
```

### 3) Search (`find`)

* Method: `POST`
* URL: `https://api.memvid.com/v1/memories/{{$json.memoryId}}/find`
* Body (JSON):

```json theme={null}
{
  "query": "How fast should P1 incidents be acknowledged?",
  "topK": 5
}
```

### 4) Ask (`ask`)

* Method: `POST`
* URL: `https://api.memvid.com/v1/memories/{{$json.memoryId}}/ask`
* Body (JSON):

```json theme={null}
{
  "question": "What is the P1 response SLA?",
  "options": {
    "model": "gpt-4o-mini",
    "includeSources": true
  }
}
```

## Reliability Upgrades

* Add error branches from each HTTP node and alert on non-2xx responses.
* Retry `429` and `5xx` failures with Wait + loop nodes.
* Use one memory per tenant/project for cleaner access boundaries.
* Prefer memory-scoped keys for least-privilege workflows.
* Start with `find` for retrieval-only steps, then use `ask` when synthesis is needed.

## Smoke Test

After importing, run the workflow manually and verify:

* `Create Memory` returns an `id`
* `Find` returns at least one hit
* `Ask` returns answer text and sources

## Related Docs

* [API Integration Patterns](/frameworks/api-integration-patterns)
* [REST API Reference](/api-reference/rest-api)
* [API Overview](/api-reference/index)
