IronFlowDocs

ai_chunk_semantic

Split text into semantic chunks using embedding similarity to detect topic boundaries.

Parameters

source_keystringrequired
Context key holding the text to chunk
output_keystringdefault "semantic"
Prefix for output context keys
providerstringdefault "openai"
Embedding provider: "openai", "ollama", "oauth"
modelstringdefault per provider
Model name (same defaults as ai_embed)
timeoutnumberdefault 120
HTTP request timeout in seconds
sim_windownumberdefault 3
Cross-similarity window size (odd, >= 3)
sg_windownumberdefault 11
Savitzky-Golay smoothing window (odd)
poly_ordernumberdefault 3
Savitzky-Golay polynomial order
thresholdnumberdefault 0.5
Percentile of candidate boundary strengths kept as splits (0.0-1.0); higher admits more splits
min_distancenumberdefault 2
Minimum block gap between split points

Provider auth parameters

Same as ai_embedapi_key, base_url, ollama_host, token_url, client_id, client_secret, scope with identical environment variable fallbacks.

Context Output

KeyTypeDescription
{output_key}arrayArray of semantic chunk strings
{output_key}_countnumberNumber of chunks
{output_key}_successbooleantrue on success

Algorithm

  1. Split text into sentences (boundary detection on .!? followed by whitespace)
  2. Embed all sentences using the selected provider
  3. Compute windowed cross-similarity (cosine distance between adjacent embedding windows)
  4. Apply Savitzky-Golay smoothing to the distance curve
  5. Detect local minima (topic boundaries) using first/second derivatives
  6. Filter split points by percentile threshold and minimum distance
  7. Group sentences at boundaries into chunks

Tuning

threshold is a percentile of candidate boundary strengths, not an absolute similarity cutoff. A split is kept when its value falls at or below the percentile, so a lower percentile admits fewer boundaries:

  • Lower threshold (e.g. 0.3) → fewer splits, larger chunks
  • Higher threshold (e.g. 0.7) → more splits, smaller chunks
  • Larger sg_window → smoother curve, fewer but more confident splits
  • Smaller min_distance → allow splits closer together

Examples

Semantic chunking with OpenAI

flow:step("chunk", nodes.ai_chunk_semantic({
    source_key = "document",
    output_key = "topics",
    provider = "openai",
    model = "text-embedding-3-small",
    threshold = 0.5
}))

Semantic chunking with Ollama (local)

flow:step("chunk", nodes.ai_chunk_semantic({
    source_key = "document",
    output_key = "topics",
    provider = "ollama",
    model = "nomic-embed-text"
}))

Fine-tuned splitting

flow:step("chunk", nodes.ai_chunk_semantic({
    source_key = "article",
    output_key = "sections",
    provider = "openai",
    threshold = 0.3,
    min_distance = 3,
    sg_window = 15
}))

IronFlow documentation

Find the next step

Type a keyword to search the documentation.

to move · Enter to open · Esc to close