brainstorming
Structured design dialogue that validates ideas before implementation begins.
contextual-chunking
Contextual Retrieval implementation for RAG - chunks clinical notes with LLM-generated context prepended to each chunk before embedding. Improves citation accuracy by 49% per Anthropic research.
Full skill instructions
This skill implements Anthropic's Contextual Retrieval pattern for RAG systems. It chunks clinical notes into fixed-size segments (1000 tokens, 200 token overlap) and generates 50-100 token contextual summaries for each chunk using Phi-4. The context is prepended to chunks before embedding, significantly improving retrieval accuracy for citation extraction.
Use this skill when:
Anthropic Contextual Retrieval Paper: Prepending chunk-specific context improves retrieval accuracy by 49% over standard RAG. The context helps the embedding model understand each chunk's role within the larger document.
IMPORTANT: This skill has its own isolated virtual environment (.venv) managed by uv. Do NOT use system Python.
Initialize the skill's environment:
# From the skill directory
cd .agent/skills/contextual-chunking
uv sync # Creates .venv and installs dependencies from pyproject.toml
Dependencies are in pyproject.toml:
tiktoken - Token counting for Phi-4CRITICAL: Always use uv run to execute code with this skill's .venv, NOT system Python.
# From .agent/skills/contextual-chunking/ directory
# Run with: uv run python -c "..."
from contextual_chunking import ContextualChunker
# You'll need to import ollama-client separately
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "ollama-client"))
from ollama_client import OllamaClient
# Initialize
chunker = ContextualChunker(
ollama_client=OllamaClient(),
chunk_size=1000, # Tokens per chunk
chunk_overlap=200, # Overlap between chunks (20%)
context_size=75 # Context tokens (50-100 range)
)
# Chunk clinical note
clinical_note = "Patient presents with chest pain radiating to left arm..."
enriched_chunks = chunker.chunk_with_context(
document_text=clinical_note,
doc_id="note_123"
)
# Each enriched chunk contains:
for chunk in enriched_chunks:
print(f"Chunk ID: {chunk['id']}")
print(f"Original text: {chunk['original_text'][:100]}...")
print(f"Context: {chunk['context']}")
print(f"Enriched (context + text): {chunk['enriched_text'][:150]}...")
print(f"Offsets: {chunk['start_offset']}-{chunk['end_offset']}")
print("---")
from src.skills.chroma_client.chroma_client import ChromaClient
# 1. Chunk with context
enriched_chunks = chunker.chunk_with_context(clinical_note, "note_123")
# 2. Store enriched chunks in ChromaDB
chroma_client = ChromaClient()
chroma_client.add_chunks(
collection_name="clinical_note_session_456",
chunks=[chunk['enriched_text'] for chunk in enriched_chunks],
metadatas=[{
'chunk_id': chunk['id'],
'start_offset': chunk['start_offset'],
'end_offset': chunk['end_offset'],
'original_text': chunk['original_text']
} for chunk in enriched_chunks],
ids=[chunk['id'] for chunk in enriched_chunks]
)
The LLM generates context with this prompt template:
Given the whole document context, provide succinct context (50-100 tokens) to situate this chunk for search retrieval purposes.
Document title/type: Clinical Note
Document context: [First 2000 chars of full document]
Chunk to contextualize:
{chunk_text}
Provide ONLY the context (no explanations):
Example Output:
Context: This section describes the patient's presenting symptoms during initial triage, specifically cardiovascular complaints requiring urgent evaluation.
Each enriched chunk dictionary contains:
{
'id': 'note_123_chunk_0',
'original_text': 'Patient presents with chest pain...',
'context': 'This section describes presenting symptoms...',
'enriched_text': 'This section describes presenting symptoms... Patient presents with chest pain...',
'start_offset': 0,
'end_offset': 1200,
'token_count': 1000
}
Parameters:
chunk_size: Tokens per chunk (default: 1000)
chunk_overlap: Token overlap (default: 200, ~20%)
context_size: Context tokens (default: 75, range: 50-100)
Chunking a 10-page note (5000 tokens):
Trade-offs:
Workflow:
citation-extraction skill to validate citationsSee contextual_chunking.py for the full Python implementation.
Structured design dialogue that validates ideas before implementation begins.
Comprehensive design intelligence for web and mobile UI/UX across 10 technology stacks.
Comprehensive implementation plans for multi-step tasks, breaking down specs into bite-sized, testable steps.
Introduction to the obra skills system with mandatory skill invocation rules and best practices.
Execute a written implementation plan with critical review and task checkpoints.
Delegate independent tasks to specialized agents working concurrently with isolated context.
Isolated git worktrees with smart directory selection and safety verification.
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Plan searchable and shareable content that drives traffic, builds authority, and generates leads.
README-first repository scanner that extracts commands and classifies reproduction candidates without executing them.
Brainstorm and prioritize marketing strategies tailored to your SaaS stage, budget, and goals.
Plan and optimize your website's page hierarchy, navigation, URL structure, and internal linking.
The world's fastest calendar for remote work
Capture, organize, and utilize your knowledge effortlessly.
Instant Summaries of Audio & Video Interviews with AnySummary
Transform PDFs into engaging mind maps.
Chat with any PDF instantly
Create an optimal daily plan using your voice
A productivity platform to centralize organizational knowledge and workflows with contextual AI assistance.
AskYourPDF Pricing Plans: Tailored to Your Needs