Repository navigation
Scenario 3 Advanced Workflows
Master complex, multi-model workflows and integration patterns with Context Processor.
This scenario covers:
- Multi-step processing pipelines
- Concurrent operations and load handling
- Classification and tagging systems
- Integration with external systems
- Large-scale content management
Time: ~15 minutes | Complexity: Advanced
You're building a sophisticated content management system:
- Processing hundreds of documents
- Multiple processing stages
- Classification and organization
- Performance requirements
- Integration with other systems
Process content through multiple stages:
async function processingPipeline(rawContent: string) {
const processor = new ContextProcessor();
// Stage 1: Save raw content
const raw = processor.save({
title: "Raw Content",
content: rawContent,
tags: ["raw"]
});
// Stage 2: Clarify
const clarified = processor.save({
...raw,
tags: ["clarified"]
}, "clarify");
// Stage 3: Optimize for search
const optimized = processor.save({
...clarified,
tags: ["optimized"]
}, "search_optimized");
// Stage 4: Full analysis
const analyzed = processor.save({
...optimized,
tags: ["analyzed", "complete"]
}, "comprehensive");
return { raw, clarified, optimized, analyzed };
}
const result = await processingPipeline("Your content here...");
console.log("Processing complete!");Process many documents efficiently:
async function batchProcess(documents: string[]) {
const processor = new ContextProcessor();
const results = [];
for (const doc of documents) {
const processed = processor.save({
title: doc.substring(0, 50),
content: doc,
tags: ["batch-processed"]
}, "comprehensive");
results.push(processed);
}
console.log(`✓ Processed ${results.length} documents`);
return results;
}
// Process 100 articles
const articles = Array(100).fill(null)
.map((_, i) => `Article ${i + 1}: Content...`);
await batchProcess(articles);Auto-classify content based on analysis:
function classifyContent(content: string, processor: ContextProcessor) {
const analysis = processor.analyze(content, "comprehensive");
// Determine category by keywords
let category = "general";
const keywords = analysis.keywords || [];
if (keywords.some(k => ["react", "vue", "angular"].includes(k))) {
category = "frontend";
} else if (keywords.some(k => ["node", "express", "database"].includes(k))) {
category = "backend";
}
// Classify by complexity
const difficulty = analysis.complexity_score > 70 ? "advanced"
: analysis.complexity_score > 40 ? "intermediate"
: "beginner";
return { category, difficulty };
}Build knowledge graph of content relationships:
function buildGraph(processor: ContextProcessor) {
const graph = {};
processor.list().forEach(context => {
const related = processor.search({ tags: context.tags })
.filter(c => c.id !== context.id);
graph[context.id] = {
title: context.title,
relations: related.map(r => ({
id: r.id,
title: r.title,
commonTags: context.tags.filter(t => r.tags.includes(t))
}))
};
});
return graph;
}
const graph = buildGraph(processor);
console.log("Knowledge graph built!");Use different models for different content types:
async function smartProcess(content: string, contentType: string) {
const processor = new ContextProcessor();
// Select model based on type
let model = "comprehensive";
if (contentType === "documentation") {
model = "clarify"; // Focus on clarity
} else if (contentType === "blog") {
model = "search_optimized"; // Focus on SEO
} else if (contentType === "web") {
model = "web_enhanced"; // Focus on URLs
}
return processor.save({
title: `${contentType.toUpperCase()} Content`,
content: content,
tags: [contentType]
}, model);
}
// Usage
const docResult = await smartProcess("API docs...", "documentation");
const blogResult = await smartProcess("Blog post...", "blog");Handle failures gracefully:
async function robustProcessing(contents: string[], processor: ContextProcessor) {
const results = { successful: [], failed: [] };
for (const content of contents) {
try {
const saved = processor.save({
title: content.substring(0, 50),
content: content,
tags: ["batch"]
}, "comprehensive");
results.successful.push(saved);
} catch (error) {
results.failed.push({
content: content.substring(0, 50),
error: error.message
});
}
}
console.log(`✓ Success: ${results.successful.length}`);
console.log(`✗ Failed: ${results.failed.length}`);
return results;
}✅ Pipelines - Process through multiple stages
✅ Batch Operations - Handle large volumes efficiently
✅ Smart Classification - Auto-categorize based on analysis
✅ Relationships - Build knowledge graphs
✅ Error Handling - Gracefully handle failures
✅ Scalability - Manage hundreds of documents
| Task | Time |
|---|---|
| Process 100 docs | <5 seconds |
| Search 1000 items | <100ms |
| Relationship analysis | Depends on size |
| Concurrent (20 items) | <500ms |
- Review API Reference for complete docs
- Check Troubleshooting for performance tips
- Join Community Testing
Congratulations! You've mastered advanced workflows. Happy processing! 🚀