embedding-pipeline-builder
Builds document embedding pipelines with text chunking, embedding generation, indexing, and retrieval optimization. Use when users request "embedding pipeline", "document indexing", "text chunking", "RAG preprocessing", or "semantic indexing".
What this skill does
# Embedding Pipeline Builder
Build production-ready document embedding and retrieval pipelines.
## Core Workflow
1. **Load documents**: Ingest from various sources
2. **Preprocess text**: Clean and normalize
3. **Chunk documents**: Split into optimal sizes
4. **Generate embeddings**: Create vector representations
5. **Index vectors**: Store in vector database
6. **Optimize retrieval**: Tune for accuracy
## Pipeline Architecture
```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Loader │───▶│ Preprocessor │───▶│ Chunker │
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Retriever │◀───│ Indexer │◀───│ Embedder │
└─────────────┘ └─────────────┘ └─────────────┘
```
## Document Loading
### Multi-Source Loader
```typescript
// pipeline/loaders.ts
import { readFile, readdir } from 'fs/promises';
import { join, extname } from 'path';
import pdf from 'pdf-parse';
import mammoth from 'mammoth';
interface LoadedDocument {
id: string;
content: string;
metadata: {
source: string;
type: string;
title?: string;
createdAt?: Date;
[key: string]: any;
};
}
export class DocumentLoader {
async loadFile(filePath: string): Promise<LoadedDocument> {
const ext = extname(filePath).toLowerCase();
const content = await this.extractContent(filePath, ext);
return {
id: this.generateId(filePath),
content,
metadata: {
source: filePath,
type: ext.slice(1),
},
};
}
async loadDirectory(dirPath: string): Promise<LoadedDocument[]> {
const files = await readdir(dirPath, { recursive: true });
const documents: LoadedDocument[] = [];
for (const file of files) {
const filePath = join(dirPath, file);
try {
const doc = await this.loadFile(filePath);
documents.push(doc);
} catch (error) {
console.error(`Failed to load ${filePath}:`, error);
}
}
return documents;
}
private async extractContent(filePath: string, ext: string): Promise<string> {
const buffer = await readFile(filePath);
switch (ext) {
case '.txt':
case '.md':
return buffer.toString('utf-8');
case '.pdf':
const pdfData = await pdf(buffer);
return pdfData.text;
case '.docx':
const result = await mammoth.extractRawText({ buffer });
return result.value;
case '.json':
const json = JSON.parse(buffer.toString('utf-8'));
return this.flattenJson(json);
default:
throw new Error(`Unsupported file type: ${ext}`);
}
}
private flattenJson(obj: any, prefix = ''): string {
const parts: string[] = [];
for (const [key, value] of Object.entries(obj)) {
const path = prefix ? `${prefix}.${key}` : key;
if (typeof value === 'object' && value !== null) {
parts.push(this.flattenJson(value, path));
} else {
parts.push(`${path}: ${value}`);
}
}
return parts.join('\n');
}
private generateId(source: string): string {
return `doc_${Buffer.from(source).toString('base64url').slice(0, 16)}`;
}
}
```
### Web Loader
```typescript
// pipeline/web-loader.ts
import { JSDOM } from 'jsdom';
import { Readability } from '@mozilla/readability';
export class WebLoader {
async loadUrl(url: string): Promise<LoadedDocument> {
const response = await fetch(url);
const html = await response.text();
const dom = new JSDOM(html, { url });
const reader = new Readability(dom.window.document);
const article = reader.parse();
return {
id: this.generateId(url),
content: article?.textContent || '',
metadata: {
source: url,
type: 'webpage',
title: article?.title,
byline: article?.byline,
},
};
}
async loadSitemap(sitemapUrl: string): Promise<LoadedDocument[]> {
const response = await fetch(sitemapUrl);
const xml = await response.text();
const urlMatches = xml.match(/<loc>([^<]+)<\/loc>/g) || [];
const urls = urlMatches.map((match) =>
match.replace('<loc>', '').replace('</loc>', '')
);
const documents: LoadedDocument[] = [];
for (const url of urls.slice(0, 100)) { // Limit for safety
try {
const doc = await this.loadUrl(url);
documents.push(doc);
await new Promise((r) => setTimeout(r, 1000)); // Rate limit
} catch (error) {
console.error(`Failed to load ${url}:`, error);
}
}
return documents;
}
}
```
## Text Preprocessing
```typescript
// pipeline/preprocessor.ts
export class TextPreprocessor {
process(text: string): string {
return this.pipeline(text, [
this.normalizeWhitespace,
this.removeSpecialCharacters,
this.normalizeUnicode,
this.removeExcessiveNewlines,
]);
}
private pipeline(text: string, transforms: Array<(t: string) => string>): string {
return transforms.reduce((t, fn) => fn(t), text);
}
private normalizeWhitespace(text: string): string {
return text
.replace(/\t/g, ' ')
.replace(/[ ]+/g, ' ')
.trim();
}
private removeSpecialCharacters(text: string): string {
return text
.replace(/[^\w\s\n.,!?;:'"()-]/g, '')
.replace(/\s+/g, ' ');
}
private normalizeUnicode(text: string): string {
return text.normalize('NFKC');
}
private removeExcessiveNewlines(text: string): string {
return text.replace(/\n{3,}/g, '\n\n');
}
}
```
## Text Chunking
### Smart Chunker
```typescript
// pipeline/chunker.ts
export interface Chunk {
id: string;
content: string;
metadata: {
documentId: string;
chunkIndex: number;
startChar: number;
endChar: number;
[key: string]: any;
};
}
export interface ChunkerOptions {
chunkSize: number;
chunkOverlap: number;
separators?: string[];
}
export class RecursiveChunker {
private options: ChunkerOptions;
private separators: string[];
constructor(options: ChunkerOptions) {
this.options = options;
this.separators = options.separators || [
'\n\n', // Paragraphs
'\n', // Lines
'. ', // Sentences
', ', // Clauses
' ', // Words
'', // Characters
];
}
chunk(document: LoadedDocument): Chunk[] {
const chunks: Chunk[] = [];
const textChunks = this.splitText(document.content, 0);
textChunks.forEach((text, index) => {
chunks.push({
id: `${document.id}_chunk_${index}`,
content: text.content,
metadata: {
documentId: document.id,
chunkIndex: index,
startChar: text.start,
endChar: text.end,
...document.metadata,
},
});
});
return chunks;
}
private splitText(
text: string,
separatorIndex: number
): Array<{ content: string; start: number; end: number }> {
const separator = this.separators[separatorIndex];
const { chunkSize, chunkOverlap } = this.options;
// If text fits in chunk size, return as is
if (text.length <= chunkSize) {
return [{ content: text, start: 0, end: text.length }];
}
// Try splitting with current separator
const parts = separator ? text.split(separator) : text.split('');
const results: Array<{ content: string; start: number; end: number }> = [];
let currentChunk = '';
let currentStart = 0;
let position = 0;
for (const part of parts) {
const partWithSep = part + (separator || '');
if ((currentChunk + partWithSep).length > chunkSize) {
if (currentChunk) {
// If chunk is still too large, try next separator
if (currentChunk.length > chunkSize && separatorIndex < this.separators.length - 1) {
const subChunks = this.splitText(currentChunk, separatorIndex + 1);
resulRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.