Skip to main content
Bulk operations allow you to add multiple episodes to your knowledge graph in a single operation, dramatically improving throughput and reducing API costs.

Why Use Bulk Operations?

Performance

Process multiple episodes in parallel with shared context

Cost Efficiency

Reduce LLM API calls through batched processing

Deduplication

Better entity deduplication across episodes

Consistency

Atomic operations for data integrity

Basic Bulk Ingestion

Use add_episode_bulk() to add multiple episodes:

RawEpisode Structure

The RawEpisode model defines episodes for bulk processing:

Processing JSON Data

Convert JSON objects to strings for bulk ingestion:

Loading from Files

Read episodes from external files:

Bulk Parameters

The add_episode_bulk() method supports the same parameters as add_episode():

Bulk Results

The add_episode_bulk() method returns an AddBulkEpisodeResults object:

Bulk vs Sequential Processing

Advantages:
  • Faster overall throughput
  • Better entity deduplication
  • Reduced API calls
  • More efficient embeddings
Disadvantages:
  • No edge invalidation
  • No date extraction
  • All-or-nothing operation
Best for:
  • Initial data loading
  • Batch imports
  • Historical data

Example: E-commerce Bulk Ingest

Chunking Large Datasets

For very large datasets, process in chunks:

Sagas with Bulk Operations

Associate bulk episodes with a saga:
Sagas connect episodes with:
  • HAS_EPISODE edges from saga to each episode
  • NEXT_EPISODE edges linking consecutive episodes

Performance Optimization

1

Batch size

Process 50-200 episodes per batch for optimal performance
2

Parallel processing

Split large datasets into chunks and process sequentially
3

Group IDs

Use different group_id values to partition data
4

Monitor memory

Large batches increase memory usage - adjust based on available RAM

Error Handling

Custom Extraction Instructions

Provide additional context for entity extraction:

Best Practices

Batch Size

Process 50-200 episodes per batch for optimal performance and memory usage

Error Recovery

Implement chunking and retry logic for large datasets

Consistent Schemas

Use the same entity types across all episodes in a batch

Monitor Progress

Log results after each batch to track progress

Limitations

Bulk operations do not support:
  • Edge invalidation - Old relationships are not automatically invalidated
  • Date extraction - Temporal information is not extracted from content
  • Community updates - Use build_communities() separately if needed
For temporal data with evolving relationships, use sequential add_episode() calls instead of bulk operations.

Next Steps

Adding Episodes

Learn about sequential episode addition

Custom Entities

Define entity types for bulk ingestion

Searching

Search your bulk-loaded knowledge graph