Batch ingest/upsert multiple runs in the Langsmith system.
multipart_ingest(
self,
create: Optional[Sequence[Union[ls_schemas.Run, ls_schemas.RunLikeDict, dict]]] = None,
update: Optional[Sequence[Union[ls_schemas.Run, ls_schemas.RunLikeDict, dict]]] = None,
*,
pre_sampled: bool = False,
dangerously_allow_filesystem: bool = False
) -> NoneThe run objects MUST contain the dotted_order and trace_id fields
to be accepted by the API.
Example:
from langsmith import Client
import datetime
from uuid import uuid4
client = Client()
_session = "__test_batch_ingest_runs"
trace_id = uuid4()
trace_id_2 = uuid4()
run_id_2 = uuid4()
current_time = datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y%m%dT%H%M%S%fZ"
)
later_time = (
datetime.datetime.now(datetime.timezone.utc) + timedelta(seconds=1)
).strftime("%Y%m%dT%H%M%S%fZ")
runs_to_create = [
{
"id": str(trace_id),
"session_name": _session,
"name": "run 1",
"run_type": "chain",
"dotted_order": f"{current_time}{str(trace_id)}",
"trace_id": str(trace_id),
"inputs": {"input1": 1, "input2": 2},
"outputs": {"output1": 3, "output2": 4},
},
{
"id": str(trace_id_2),
"session_name": _session,
"name": "run 3",
"run_type": "chain",
"dotted_order": f"{current_time}{str(trace_id_2)}",
"trace_id": str(trace_id_2),
"inputs": {"input1": 1, "input2": 2},
"error": "error",
},
{
"id": str(run_id_2),
"session_name": _session,
"name": "run 2",
"run_type": "chain",
"dotted_order": f"{current_time}{str(trace_id)}."
f"{later_time}{str(run_id_2)}",
"trace_id": str(trace_id),
"parent_run_id": str(trace_id),
"inputs": {"input1": 5, "input2": 6},
},
]
runs_to_update = [
{
"id": str(run_id_2),
"dotted_order": f"{current_time}{str(trace_id)}."
f"{later_time}{str(run_id_2)}",
"trace_id": str(trace_id),
"parent_run_id": str(trace_id),
"outputs": {"output1": 4, "output2": 5},
},
]
client.multipart_ingest(create=runs_to_create, update=runs_to_update)| Name | Type | Description |
|---|---|---|
create | Optional[Sequence[Union[ls_schemas.Run, RunLikeDict]]] | Default: NoneA sequence of |
update | Optional[Sequence[Union[ls_schemas.Run, RunLikeDict]]] | Default: NoneA sequence of |
pre_sampled | bool, default=False | Default: FalseWhether the runs have already been subject to sampling, and therefore should not be sampled again. |