Hands-on Jupyter Notebook recipes covering the entire Anchor context engineering toolkit API. Clone this repo, install dependencies, and start exploring.
Quick Start
git clone https://github.com/arthurgranja/anchor-cookbook.git cd anchor-cookbook uv venv && uv pip install -e . jupyter notebook
Start with setup.ipynb to verify your environment.
Recipes
| Module | Recipe | Description |
|---|---|---|
| Pipeline | Basic Pipeline | ContextPipeline with system prompt, memory, and formatter |
| Pipeline | Built-in Steps | retriever_step, filter_step, reranker_step, and more |
| Pipeline | Custom Steps | @pipeline.step decorator for custom logic |
| Pipeline | Async Pipelines | abuild() and async step execution |
| Pipeline | Pipeline Diagnostics | ContextResult timing, tokens, step diagnostics |
| Pipeline | Context Window | ContextWindow, ContextItem, priority ranking |
| Pipeline | Enrichers | MemoryContextEnricher, ContextQueryEnricher |
| Memory | Sliding Window | SlidingWindowMemory with token cap |
| Memory | Summary Buffer | SummaryBufferMemory progressive summarization |
| Memory | Graph Memory | SimpleGraphMemory entity-relationship tracking |
| Memory | Memory Manager | MemoryManager facade for conversation + persistent memory |
| Memory | Eviction Policies | FIFO, importance-based, paired eviction |
| Memory | Decay Strategies | Ebbinghaus, linear decay, recency scoring |
| Memory | Consolidation | Content-hash dedup, similarity merging |
| Memory | Garbage Collection | Two-phase GC: expired + decayed pruning |
| Retrieval | Dense Retriever | Embedding-based semantic search |
| Retrieval | Sparse Retriever | BM25 keyword matching |
| Retrieval | Hybrid Retriever | Dense + sparse with Reciprocal Rank Fusion |
| Retrieval | Scored Memory Retriever | Multi-signal memory retrieval |
| Retrieval | Async Retrievers | AsyncDenseRetriever, AsyncHybridRetriever |
| Retrieval | Late Interaction | ColBERT-style token-level matching |
| Retrieval | Rerankers | Cross-encoder, FlashRank, RerankerPipeline |
| Retrieval | Routers | Callback, keyword, metadata query routing |
| Retrieval | Custom Retriever | Implementing the Retriever protocol |
| Agents | Basic Agent | Agent with system prompt, memory, chat() |
| Agents | Tool Decorator | @tool decorator, AgentTool schemas |
| Agents | Skills System | Skill, SkillRegistry, SKILL.md loading |
| Agents | Agent with Retrieval | Agent + ContextPipeline integration |
| Agents | Streaming Agent | Streaming responses, StreamDelta |
| Ingestion | Document Ingester | DocumentIngester orchestration |
| Ingestion | Chunking Strategies | Fixed, recursive, semantic, code, table-aware |
| Ingestion | Parsers | Text, Markdown, HTML, PDF parsing |
| Ingestion | Metadata Enrichment | Auto IDs, metadata extraction |
| Ingestion | Parent-Child Chunks | Hierarchical chunking |
| Query | HyDE Transformer | Hypothetical document generation |
| Query | Multi-Query | Query expansion + ensemble |
| Query | Decomposition | Sub-query breakdown |
| Query | Step-Back | Abstraction-level reformulation |
| Query | Classifiers | Keyword, callback, embedding classifiers |
| Query | Query Pipeline | QueryTransformPipeline, chaining |
| Evaluation | Retrieval Metrics | NDCG, MAP, MRR, P@K, R@K |
| Evaluation | LLM Evaluator | LLM-as-judge for RAG quality |
| Evaluation | Pipeline Evaluator | End-to-end pipeline assessment |
| Evaluation | Batch Evaluator | Dataset-level runs |
| Evaluation | A/B Testing | ABTestRunner comparative harness |
| Evaluation | Human Evaluation | Human judgment collection |
| Observability | Tracing | Tracer, spans, structured traces |
| Observability | Exporters | Console, file, in-memory, OTLP exporters |
| Observability | Cost Tracking | Token cost calculation |
| Observability | Metrics | OpenTelemetry metrics, collectors |
| Formatters | Anthropic Formatter | Claude API output format |
| Formatters | OpenAI Formatter | OpenAI API output format |
| Formatters | Generic Text | Plain text output |
| Formatters | Custom Formatter | Implementing custom formatters |
| Multimodal | Multimodal Converter | Document-to-multimodal conversion |
| Multimodal | Image Encoding | Image description encoder |
| Multimodal | Table Extraction | Markdown/HTML table parsing |
| Tokens | Token Budgets | TokenBudget, allocations, overflow |
| Tokens | Budget Presets | Chat, RAG, agent budget defaults |
| Tokens | Tiktoken Counter | TiktokenCounter tokenization |
| Tokens | Custom Tokenizer | Implementing Tokenizer protocol |
| Caching | Cache Backend | CacheBackend protocol |
| Caching | In-Memory Cache | InMemoryCacheBackend usage |
| Storage | Vector Store | InMemoryVectorStore |
| Storage | Document Store | InMemoryDocumentStore |
| Storage | Context Store | InMemoryContextStore |
| Storage | Entry Store | InMemoryEntryStore |
| Storage | JSON File Store | JsonFileMemoryStore persistence |
| Storage | Custom Store | Implementing storage protocols |
Total: 69 recipes across 13 modules.
Requirements
- Python 3.11+
- astro-anchor (installed via requirements.txt)
License
MIT