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
Useadd_episode_bulk() to add multiple episodes:
RawEpisode Structure
TheRawEpisode 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
Theadd_episode_bulk() method supports the same parameters as add_episode():
Bulk Results
Theadd_episode_bulk() method returns an AddBulkEpisodeResults object:
Bulk vs Sequential Processing
- Bulk Processing
- Sequential Processing
Advantages:
- Faster overall throughput
- Better entity deduplication
- Reduced API calls
- More efficient embeddings
- No edge invalidation
- No date extraction
- All-or-nothing operation
- 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:HAS_EPISODEedges from saga to each episodeNEXT_EPISODEedges 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 data4
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