Instrument LlamaIndex
Recipe — instrument a LlamaIndex pipeline. SDK adapter + manual trace upload patterns.
Approach 1 — SDK adapter (when available)
pip install 'layerlens[frameworks-llamaindex]'Approach 2 — manual trace upload from your pipeline
from layerlens import Stratix
client = Stratix()
# Run your LlamaIndex query
response = query_engine.query("What did the report say about Q3?")
# Build a trace record (any flexible Dict[str, Any] for `data`)
trace_record = {
"input": "What did the report say about Q3?",
"output": str(response),
"spans": [
{"name": "retrieval", "chunks": [n.node.text for n in response.source_nodes]},
{"name": "synthesis", "text": str(response)},
],
}
# Write to JSONL and upload (≤50 MB per file)
import json
from pathlib import Path
Path("trace.jsonl").write_text(json.dumps(trace_record))
result = client.traces.upload("trace.jsonl")
# Score with a faithfulness judge
client.trace_evaluations.create(trace_id=result.trace_ids[0], judge_id=FAITHFULNESS_JUDGE_ID)See also
Last updated
Was this helpful?