Skip to content

Ingestion (ingest.* spans)

ctxflow never connects to your vector store or your document storage. It learns what is in your index, and which version of each source is current, from the process that writes them: your ingestion pipeline, instrumented with the SDK. Run ctxflow_otel.init() (or ctxflow-instrument) in the pipeline as in the agent (Python SDK). The same [llamaindex] extra also gives the agent side: LlamaIndex agent spans.

What the core builds from the ingest.* spans:

Span Becomes Unlocks
ingest.parse A read of the original document: source_id, source_version, source_hash, on every run, changed or not S10: Sources, C6 for live documents
ingest.chunk The C1 of each chunk of a document, joined to the writes by chunk id C1 coverage
ingest.upsert A write of chunks: ctxflow.chunks.ids with ctxflow.chunks.text_hashes S9: Index, C4, Never retrieved
ingest.delete With chunk ids: those chunks are deleted. Without chunk ids: every live chunk of that source Deletions, stale · source_deleted
ingest.run, ingest.embed The run and the embedding step (ids, counts, model name) —

A span with status ERROR is no event. The name of the index and of the source in the app is the service.name of the pipeline: set OTEL_SERVICE_NAME. Event times are exact (the end of the span). The spans hold ids, hashes and lengths, never text.

Limits. A source that changed and nobody re-ingested is not seen. No ingestion extra emits ingest.delete today (LlamaIndex has no deletion hook; the Unstructured pipeline does not propagate deletions): emit it yourself where your pipeline deletes, see Deletions. Without it, a chunk your pipeline deleted or replaced stays live in the Index and Never retrieved views, and a deleted document is never stale · source_deleted.

Terminal window
pip install "ctxflow-otel[llamaindex]==0.2.2" # llama-index-core 0.14.19 or later, below 0.15

Level 0 (no code). init() or ctxflow-instrument registers a span handler when llama_index.core is imported. It stamps every node parser output in IngestionPipeline.run, run_transformations, VectorStoreIndex.from_documents, index.insert, chained and hierarchical parsers and custom parsers. Your pipeline is not changed.

Level 1 (one line). For arun, num_workers > 1 or a pipeline cache whose version changes, wrap your transformations:

from ctxflow_otel.ingest.llamaindex import ctxflow_transformations
from llama_index.core.ingestion import IngestionPipeline
from llama_index.core.node_parser import SentenceSplitter
pipeline = IngestionPipeline(transformations=ctxflow_transformations([SentenceSplitter()]))

Example (level 0), with deterministic ids and an explicit version:

import ctxflow_otel
from ctxflow_otel.ingest.common import source_version
from ctxflow_otel.ingest.llamaindex import load_documents
from llama_index.core import VectorStoreIndex
from llama_index.core.embeddings import MockEmbedding
from llama_index.core.ingestion import IngestionPipeline
from llama_index.core.node_parser import SentenceSplitter
provider = ctxflow_otel.init() # enables the LlamaIndex ingestion extra
with source_version("2026-11-26"):
documents = load_documents("docs") # source_id, source_hash of each original file
pipeline = IngestionPipeline(transformations=[SentenceSplitter(chunk_size=256), MockEmbedding(embed_dim=8)])
nodes = pipeline.run(documents=documents)
index = VectorStoreIndex(nodes, embed_model=MockEmbedding(embed_dim=8))
print(nodes[0].metadata)
provider.shutdown()
Terminal window
OTEL_SERVICE_NAME=kb-ingest CTXFLOW_DETERMINISTIC_IDS=on python ingest.py

Every chunk then carries in its metadata ctxflow.source_id, ctxflow.source_version, ctxflow.source_hash, ctxflow.chunker_version and ctxflow.id_mode (and ctxflow.embed_model), hidden from the embedding and LLM text. Your retriever returns them with each chunk, which is what the agent side needs.

  • source_id: ctxflow.source_id in the document metadata, else file_path relative to CTXFLOW_SOURCE_ROOT, else the document id. load_documents(root) sets it to the path relative to root (extension kept) and computes source_hash from the original file.
  • source_version: the metadata, else with source_version("v2"):, else CTXFLOW_SOURCE_VERSION, else a label derived from the content hash (h:<12 hex>). Set it explicitly.
  • CTXFLOW_DETERMINISTIC_IDS=on: chunk ids are uuid5 of (source id, version, chunker version, position), so re-ingesting the same version keeps the ids (the Index page measures this as ID stability). The chunker version includes the parser settings that move chunk boundaries.

Limits: level 0 does not cover arun, num_workers > 1 or parser.get_nodes_from_documents(docs) called directly (call parser(docs)). A transformation served from the pipeline cache emits no span. Only llama-index-core 0.14.x is supported.

Your own splitter and direct vector store writes

Section titled “Your own splitter and direct vector store writes”

If your app splits text itself and writes TextNodes with vector_store.add (or async_add), no node parser runs and nothing stamps the chunks. Level 0 still reports the index write: it wraps add and async_add of every LlamaIndex vector store (also one imported after init()) and emits one ingest.upsert span per source, with the ids and text hashes of the nodes that carry an embedding. It reads the source identity from the nodes, so you set the three ctxflow.source_* keys in the node metadata:

import ctxflow_otel
from llama_index.core.schema import TextNode
ctxflow_otel.init() # or run the process with ctxflow-instrument
def index_document(vector_store, source_id: str, original: bytes, version: str) -> None:
"""Split, embed and write one document; `vector_store` is any LlamaIndex vector store."""
metadata = {
"ctxflow.source_id": source_id, # see "Choose the source id"
"ctxflow.source_version": version,
"ctxflow.source_hash": ctxflow_otel.source_hash(original), # hash of the original bytes
}
pieces = my_splitter(original.decode("utf-8")) # your own splitting
nodes = [
TextNode(
id_=f"{source_id}:{version}:{i}", # the chunk id your retriever returns
text=piece,
metadata=dict(metadata),
excluded_llm_metadata_keys=list(metadata), # keep the ctxflow keys out of LLM text
excluded_embed_metadata_keys=list(metadata), # and out of the text that is embedded
embedding=my_embed(piece),
)
for i, piece in enumerate(pieces)
]
vector_store.add(nodes)

What to know:

  • Only nodes with an embedding are reported, as in the pipeline. Embed before you call add.
  • Keep the keys out of the model text. By default a node’s metadata is part of the text the embedding model and the LLM see. excluded_embed_metadata_keys and excluded_llm_metadata_keys (the example above) hide the ctxflow.* keys from both while they stay in node.metadata. The node parsers of the extra do this for you; hand-built nodes need it.
  • What a node may leave out. source_id falls back to file_path in the metadata (relative to CTXFLOW_SOURCE_ROOT), then to the node’s ref_doc_id. source_version falls back to with source_version("v2"): around the write, then to CTXFLOW_SOURCE_VERSION. A key with no fallback is left out, never invented: with no source_hash, lineage is unknown · no_item_hash. Putting all three keys on every node is the reliable way.
  • A pipeline run (IngestionPipeline.run with a vector_store) reports its own write: the direct write adds no second span. An IngestionPipeline without a vector store writes nothing and reports nothing; the later vector_store.add is the report.
  • This reports index writes (S9) only. Source reads (S10: the Sources page and C6 for live documents) come from ingest.parse spans: emit one per document read, see Any other pipeline.
  • Deletions are not reported: see Deletions.

ctxflow.source_id names the original document, and every chunk of the document, in every version, carries the same value. Use a stable id of the document in its source system: a path relative to a document root (policies/vacation.md), a record key or a URL path. A file name is fine when it is unique and does not change. What to avoid:

  • A value that changes per upload or per run (a random upload id, a temporary path): each re-ingestion would look like a new document and lineage could not follow the document across versions. The same document shows twice in Documents when two conventions are mixed.
  • An absolute path: it differs between machines. Set CTXFLOW_SOURCE_ROOT so that the extractors produce the relative path.
  • A value that differs between your ingestion and your retriever: the retriever must return the same source_id the chunk was indexed with.

Put the version in ctxflow.source_version, not in the id.

The extras log each of these once per process. They do not stop ingestion, but each one means ctxflow got a weaker identity than it could.

Warning Cause Fix
CTXFLOW_SOURCE_ROOT is not set (or does not contain <file>): the source id is the bare file name, so files with the same name in different folders share a source (Unstructured) The extra cannot make a path relative to a root, so the source id is the bare file name Set CTXFLOW_SOURCE_ROOT to the folder that holds your documents (for example your upload folder). The source id becomes the relative path, such as policies/vacation.md. Files outside the root keep the bare name
<file> is not under CTXFLOW_SOURCE_ROOT: its source_id is a content hash h:<hash> (it changes with the content). Set CTXFLOW_SOURCE_ROOT to get path source ids (Docling) The file is outside the root, or no root is set Set CTXFLOW_SOURCE_ROOT to a folder that contains the file. A content hash as source id makes every change look like a new document
No source version for <id> (and maybe others): using a content-hash version h:<hash>. Set CTXFLOW_SOURCE_VERSION, source_version() or the ctxflow.source_version document metadata to label them Nothing gave the source a version, so ctxflow uses a label derived from the content Set the version: CTXFLOW_SOURCE_VERSION for the whole run, with source_version("2026-11-26"): around the ingestion, or ctxflow.source_version in the metadata. The h: label works, but it is not a label you can read
Deterministic ids need a stable source id, but <id> only has a random document id. Set ctxflow.source_id in the metadata, CTXFLOW_SOURCE_ROOT or id_= (LlamaIndex, with CTXFLOW_DETERMINISTIC_IDS=on) The document has a random id and no source id Set ctxflow.source_id in the metadata, set CTXFLOW_SOURCE_ROOT, or give the Document a stable id_

For an upload-folder layout, set CTXFLOW_SOURCE_ROOT to the upload root and the version explicitly; then none of these appears.

Terminal window
pip install "ctxflow-otel[unstructured]==0.2.2" # unstructured[md] 0.27.x, unstructured-ingest 1.12.x

Call init() before from unstructured... import partition and before you create an unstructured-ingest Pipeline.

  • partition / partition_* → ingest.parse; chunk_by_title, chunk_elements and partition(chunking_strategy=...) → ingest.chunk.
  • unstructured-ingest: Pipeline.run → ingest.run; chunk, embed and destination write steps → ingest.chunk, ingest.embed, ingest.upsert.
  • C1 is written into each element’s metadata as ctxflow.* keys, and survives JSON export and the pipeline files.
  • source_id: from the parse step, else the path relative to CTXFLOW_SOURCE_ROOT, else the bare file name: set CTXFLOW_SOURCE_ROOT.
  • With CTXFLOW_DETERMINISTIC_IDS=on, chunk ids are deterministic; in the pipeline the destination’s primary key stays the library’s own and the ctxflow id is in element_id.

Limits: run the pipeline with num_processes=1 (forked workers lose their spans); the Unstructured API (partition_by_api, chunk_by_api) is not covered; tested with Markdown, text and HTML.

Terminal window
pip install "ctxflow-otel[docling]==0.2.2" # docling 2.150 or later

DocumentConverter.convert / convert_all → one ingest.parse span per file, with ctxflow.source_id (path relative to CTXFLOW_SOURCE_ROOT), ctxflow.source_hash of the original file and ctxflow.parse.chars. With llama-index-readers-docling, DoclingReader documents get the same C1, so the LlamaIndex extra stamps the chunks of DoclingNodeParser. Without LlamaIndex only ingest.parse is emitted: ctxflow_otel.ingest.docling.source_metadata(path) returns the C1 keys for your own chunks.

Emit the spans yourself with the attribute names of the registry and the helpers of the SDK. A minimal write of one document:

import ctxflow_otel
import ctxflow_semconv as sc
from ctxflow_otel.ingest.common import chunk_text_hashes
from opentelemetry import trace
provider = ctxflow_otel.init()
tracer = trace.get_tracer("kb-ingest")
original = open("docs/policies/vacation.md", "rb").read()
c1 = {
sc.SOURCE_ID: "policies/vacation.md",
sc.SOURCE_VERSION: "2026-11-26",
sc.SOURCE_HASH: ctxflow_otel.source_hash(original),
}
chunks = {"vacation-0": "You have 23 days of vacation per year."} # chunk id -> text as stored
with tracer.start_as_current_span("ingest.run"):
with tracer.start_as_current_span("ingest.parse") as span:
span.set_attributes({k: v for k, v in c1.items() if v is not None})
with tracer.start_as_current_span("ingest.chunk") as span:
span.set_attributes({k: v for k, v in c1.items() if v is not None})
span.set_attribute(sc.CHUNKS_IDS, list(chunks))
span.set_attribute(sc.CHUNKS_TEXT_HASHES, chunk_text_hashes(chunks.values()))
# ... write the chunks to your vector store, with c1 in their metadata ...
with tracer.start_as_current_span("ingest.upsert") as span:
span.set_attribute(sc.CHUNKS_IDS, list(chunks))
span.set_attribute(sc.CHUNKS_TEXT_HASHES, chunk_text_hashes(chunks.values()))
provider.shutdown()

Set the chunk ids as stored in your vector store.

Call it manually, in the pipeline process, right after the delete in your vector store succeeded. Two forms:

Span Attributes Means
ingest.delete with chunk ids ctxflow.chunks.ids (as stored, like on ingest.upsert) These chunks left the index
ingest.delete without chunk ids ctxflow.source_id The whole document was deleted: every chunk of that source live at that time leaves the index, and retrievals after it are stale · source_deleted

A span with status ERROR is no event: if the delete fails, set the status and ctxflow ignores it.

import ctxflow_otel
import ctxflow_semconv as sc
from opentelemetry import trace
provider = ctxflow_otel.init()
tracer = trace.get_tracer("kb-ingest")
# Chunks replaced by a re-ingestion (ids as your vector store holds them):
with tracer.start_as_current_span("ingest.delete") as span:
span.set_attribute(sc.CHUNKS_IDS, ["vacation-0", "vacation-1"])
# A whole document removed from the source and from the index:
with tracer.start_as_current_span("ingest.delete") as span:
span.set_attribute(sc.SOURCE_ID, "policies/travel.md")
provider.shutdown()

Use the same OTEL_SERVICE_NAME as the pipeline that wrote the chunks: the index is named after it.