Skip to main content

Prerequisites

  • Understanding of Context Arithmetic
  • Data to contextualize
  • Familiarity with the Alchemyst SDKs and APIs.

Introduction

Context Arithmetic is a very simple but powerful tool. Leveraging that system, we can derive context spaces, merge them, segregate them, or even apply access controls on top of them - all while maintaining the tractability and other benefits that Alchemyst offers. In an agentic environment where non-determinism exists not as a byproduct, but as a foundational principle, it offers verifiability across large systems. This gives enterprise teams control over their data usage and governance patterns and scopes. In this section we explore patterns that you can leverage to build robust context-aware AI systems using context arithmetic.

Pattern 1: Hierarchical groupName Design

The Problem

Flat groupName structures become unmanageable at scale. You end up with searches that are either too broad (returning 1000+ documents) or too narrow (returning nothing).

The Solution: Think in Layers

Design your groupName hierarchy like a file system - broad categories at the top, specific tags as you go deeper.

Three-Layer Strategy

Layer 1: Organization/Domain (Required for all documents)
  • "engineering", "marketing", "sales", "support"
  • Purpose: Top-level access control
Layer 2: Category/Time (Recommended)
  • "q4_2024", "product_alpha", "codebase", "customer_tickets"
  • Purpose: Logical grouping and temporal filtering
Layer 3: Specifics (Optional, use sparingly)
  • "auth", "api", "campaign", "billing"
  • Purpose: Fine-grained filtering

Example: Engineering Team

Query Patterns

πŸ’‘ Pro Tip: The 3-5-10 Rule

  • Maximum 3 groupName layers for 90% of queries
  • Maximum 5 tags in any single groupName array
  • Maximum 10 unique tag combinations per user query pattern

⚠️ Common Mistake: Over-nesting


Pattern 2: Handling Document Updates

The Deduplication Gotcha

Alchemyst uses metadata.fileName as the deduplication key. This means:
  1. Same fileName = Alchemyst treats it as an update attempt
  2. Update attempts without delete = 409 Conflict error
  3. This is by design to prevent accidental duplicates

Three Update Strategies

Strategy B: Versioned FileNames (Keep history)

Strategy C: Conversational Updates (Incremental context)

Decision Tree: Which Strategy?

πŸ”§ Advanced: Batch Updates

⚠️ Warning: The Race Condition


Pattern 3: Composable Context Strategies

The Dilemma

Should you store one big document or many small ones? This affects retrieval quality, performance, and maintenance.

Rule of Thumb: Split by Access Pattern

When to COMBINE contexts:

Scenario 1: Tightly Coupled Information
Scenario 2: Always Retrieved Together

When to SPLIT contexts:

Scenario 1: Different Access Patterns
Scenario 2: Different Update Frequencies
Scenario 3: Size Optimization

The Goldilocks Size: 500-2000 words per document

πŸ’‘ Pro Tip: The Chapter Pattern

Structure large content like a book:

Advanced: Cross-References


Pattern 4: Bulk Operations at Scale

The Performance Cliff

Optimal Batch Sizes

Based on production usage patterns:

The 1000-Document Sweet Spot

πŸš€ Advanced: Parallel Processing with Limits

Error Handling in Bulk Operations

πŸ’‘ Pro Tip: Progress Tracking for Large Ingests


Anti-Pattern 1: Over-segmentation

The Problem

Creating too many small, fragmented contexts that should be combined.

Real Example: Support Ticket System

The Acid Test: Query Simulation

Ask yourself: β€œWhat will my users search for?”

πŸ’‘ Rule: The Paragraph Test

If your document content is less than a paragraph (< 100 words), you’re probably over-segmenting. Exception: Structured data with high retrieval value

Anti-Pattern 2: Metadata Bloat

The Problem

Storing too much or redundant information in metadata, slowing down queries and wasting storage.

Real Example: Product Catalog

Decision Framework: Metadata vs Content

Store in METADATA if:
  • βœ… You filter or sort by it (price, inStock, category)
  • βœ… You need exact matching (productId, sku)
  • βœ… It’s used for access control (department, classification)
  • βœ… It changes frequently and independently (stock, price)
Store in CONTENT if:
  • βœ… It’s descriptive text (description, features)
  • βœ… It’s rarely filtered (dimensions, weight)
  • βœ… It’s only needed when document is retrieved (warranty, origin)
  • βœ… It’s part of the semantic meaning (reviews, specifications)

πŸ’‘ Pro Tip: The 5-Field Rule

Start with maximum 5 metadata fields. Add more ONLY when you have a specific query pattern that requires it.

⚠️ Common Mistake: Duplicating Content in Metadata

Real Impact: Before & After

Before optimization (metadata bloat):
  • Storage: 2.3GB for 10,000 products
  • Query time: 450ms average
  • Index time: 12 minutes
  • Maintenance: 3 fields out of sync per 100 updates
After optimization (lean metadata):
  • Storage: 0.8GB for 10,000 products (65% reduction)
  • Query time: 180ms average (60% faster)
  • Index time: 4 minutes (67% faster)
  • Maintenance: Consistency issues eliminated

Quick Reference: Pattern Selection