---
title: "Batch Operations"
description: "High-throughput batch endpoints for queries, memory, vectors, and events"
canonical: "https://docs.ainative.studio/docs/zerodb/batch-operations"
last-updated: "2026-10-13T21:42:35.442Z"
---

# Batch Operations

Source: https://docs.ainative.studio/docs/zerodb/batch-operations

> High-throughput batch endpoints for queries, memory, vectors, and events

## Batch Operations

ZeroDB batch endpoints let you execute multiple operations in a single request — reducing round-trips and improving throughput for bulk ingestion, migration, and agent pipelines.

## Batch Query

Execute up to 50 table queries in one call:

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/batch/query \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "operations": [
      {
        "table": "agents",
        "filters": {"status": "active"},
        "limit": 10
      },
      {
        "table": "sessions",
        "filters": {"user_id": "usr-123"},
        "limit": 5
      }
    ],
    "parallel": true,
    "stop_on_error": false
  }'
```

## Batch Memory Upsert

Insert or update up to 500 memory records:

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/memory/batch/upsert \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "records": [
      {
        "content": "User prefers concise responses",
        "memory_type": "semantic",
        "importance": 0.8,
        "tags": ["preference", "communication"]
      },
      {
        "content": "Project uses FastAPI + SQLAlchemy",
        "memory_type": "semantic",
        "importance": 0.9,
        "tags": ["tech-stack"]
      }
    ]
  }'
```

## Batch Memory Delete

Delete up to 500 memory records by ID:

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/memory/batch/delete \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ids": [
      "mem-abc123",
      "mem-def456",
      "mem-ghi789"
    ]
  }'
```

## Batch Memory Update

Partial-update up to 500 memory records:

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/memory/batch/update \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "updates": [
      {
        "id": "mem-abc123",
        "importance": 0.95,
        "tags": ["preference", "high-priority"]
      }
    ]
  }'
```

## Batch Vector Upsert

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/vectors/upsert-batch \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "vectors": [
      {
        "id": "vec-001",
        "vector_embedding": [0.021, -0.043, 0.118],
        "namespace": "documents",
        "metadata": {"source": "upload", "doc_id": "doc-42"}
      }
    ]
  }'
```

## Batch Event Publish

Publish up to 100 events in one request:

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/events/batch \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "topic": "agent.task.completed",
        "event_payload": {"task_id": "task-001", "duration_ms": 1200}
      },
      {
        "topic": "agent.task.completed",
        "event_payload": {"task_id": "task-002", "duration_ms": 850}
      }
    ]
  }'
```

## Batch RLHF Interactions

Log up to 1,000 RLHF interactions at once:

```bash
curl -X POST https://api.ainative.studio/api/v1/projects/{project_id}/database/rlhf/interactions/batch \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "interactions": [
      {
        "prompt": "Explain async/await",
        "response": "Async/await is a syntax for non-blocking I/O...",
        "metadata": {"model": "qwen-coder-32b"}
      },
      {
        "prompt": "What is a decorator in Python?",
        "response": "A decorator wraps a function to extend its behavior...",
        "metadata": {"model": "qwen-coder-32b"}
      }
    ]
  }'
```

## Python SDK

```python
import requests

API_KEY = "your-api-key"
PROJECT_ID = "your-project-id"
BASE = f"https://api.ainative.studio/api/v1/projects/{PROJECT_ID}/database"
headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}

## Batch upsert memory
r = requests.post(f"{BASE}/memory/batch/upsert", headers=headers, json={
    "records": [
        {"content": f"Fact #{i}", "memory_type": "semantic", "importance": 0.7}
        for i in range(100)
    ]
})
print(f"Upserted: {r.json()['inserted']} records")

## Batch publish events
r = requests.post(f"{BASE}/events/batch", headers=headers, json={
    "events": [
        {"topic": "user.action", "event_payload": {"action": "click", "item": f"item-{i}"}}
        for i in range(50)
    ]
})
print(f"Published: {r.json()['published']} events")
```

## Limits

| Operation | Max per batch |
|-----------|---------------|
| Batch query | 50 operations |
| Memory upsert | 500 records |
| Memory delete | 500 IDs |
| Memory update | 500 records |
| Vector upsert | No fixed limit (per vector store capacity) |
| Event publish | 100 events |
| RLHF interactions | 1,000 interactions |

## Endpoints

| Method | Path | Description |
|--------|------|-------------|
| POST | `/database/batch/query` | Execute batch table queries (parallel optional) |
| POST | `/database/memory/batch/upsert` | Batch insert/update memory records |
| POST | `/database/memory/batch/delete` | Batch delete memory by ID list |
| POST | `/database/memory/batch/update` | Batch partial-update memory records |
| POST | `/database/vectors/upsert-batch` | Batch upsert vectors |
| POST | `/database/events/batch` | Batch publish events |
| POST | `/database/rlhf/interactions/batch` | Batch log RLHF interactions |
