Skip to content

Commit 28062f4

Browse files
docs: multimodal (#777)
Co-authored-by: Tanushree <[email protected]>
1 parent 108d38b commit 28062f4

9 files changed

+128
-46
lines changed

docs/evaluation/how_to_guides/evaluate_with_attachments.mdx

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
---
2+
table_of_contents: false
3+
hide_table_of_contents: true
4+
---
5+
16
import {
27
python,
38
CodeTabs,
49
PythonBlock,
510
TypeScriptBlock,
611
} from "@site/src/components/InstructionsWithCode";
12+
import Tabs from '@theme/Tabs';
13+
import TabItem from '@theme/TabItem';
14+
15+
# Run an evaluation with multimodal content
716

8-
# Run an evaluation with large file inputs
17+
LangSmith lets you create dataset examples with file attachments—like images, audio files, or documents—so you can reference them when evaluating an application that uses multimodal inputs or outputs.
918

10-
LangSmith supports creating dataset examples with file attachments, which you can consume when running evals over that dataset.
19+
While you can include multimodal data in your examples by base64 encoding it, this approach is inefficient - the encoded data takes up more space than the original binary files, resulting in slower transfers to and from LangSmith. Using attachments instead provides two key benefits:
1120

12-
Attachments are most useful when working with LLM applications that require multimodal inputs or produce multimodal outputs.
13-
While multimodal data can be base64 encoded and uploaded as part of an example's inputs/outputs, base64 encodings are fairly space inefficient relative to the underlying binary data making them slower to upload/download to/from LangSmith.
14-
By using attachments you can speed up uploads/downloads and get nicer renderings of different file types in the LangSmith UI.
21+
1. Faster upload and download speeds due to more efficient binary file transfers
22+
2. Enhanced visualization of different file types in the LangSmith UI
1523

16-
## Create examples with attachments
24+
<Tabs className="interface-tabs" queryString="mode">
25+
<TabItem value="sdk" label="SDK">
1726

18-
### Using the SDK
27+
## 1. Create examples with attachments
1928

2029
To upload examples with attachments using the SDK, use the [create_examples](https://docs.smith.langchain.com/reference/python/client/langsmith.client.Client#langsmith.client.Client.create_examples) / [update_examples](https://docs.smith.langchain.com/reference/python/client/langsmith.client.Client#langsmith.client.Client.update_examples) Python methods or the [uploadExamplesMultipart](https://docs.smith.langchain.com/reference/js/classes/client.Client#uploadexamplesmultipart) / [updateExamplesMultipart](https://docs.smith.langchain.com/reference/js/classes/client.Client#updateexamplesmultipart) TypeScript methods.
2130

@@ -147,7 +156,7 @@ Note that you cannot directly pass in a file path in the TypeScript SDK, as acce
147156
]}
148157
groupId="client-language"
149158
/>
150-
159+
151160
:::info Uploading from filesystem
152161

153162
Along with being passed in as bytes, attachments can be specified as paths to local files.
@@ -159,29 +168,7 @@ client.create_examples(..., dangerously_allow_filesystem=True)
159168

160169
:::
161170

162-
Once you upload examples with attachments, you can view them in the LangSmith UI. Each attachment will be rendered as a file with a preview, making it easy to inspect the contents.
163-
![](./static/attachments_with_examples.png)
164-
165-
166-
### From the UI
167-
168-
#### From existing runs
169-
170-
When adding runs to a LangSmith dataset, attachments can be selectively propagated from the source run to the destination example.
171-
To learn more, please see [this guide](./manage_datasets_in_application#add-runs-from-the-tracing-project-ui).
172-
173-
![](./static/add_trace_with_attachments_to_dataset.png)
174-
175-
#### From scratch
176-
177-
You can also upload examples with attachments directly from the LangSmith UI. You can do so by clicking the `+ Example` button in the `Examples` tab of the dataset UI.
178-
You can then upload the attachments that you want by using the "Upload Files" button:
179-
180-
![](./static/create_example_with_attachments.png)
181-
182-
## Run evaluations
183-
184-
Once you have a dataset that contains examples with file attachments, you can run evaluations that process these attachments.
171+
## 2. Run evaluations
185172

186173
### Define a target function
187174

@@ -334,7 +321,6 @@ groupId="client-language"
334321

335322
### Define custom evaluators
336323

337-
In addition to using attachments inside of your target function, you can also use them inside of your evaluators as follows.
338324
The exact same rules apply as above to determine whether the evaluator should receive attachments.
339325

340326
The evaluator below uses an LLM to judge if the reasoning and the answer are consistent.
@@ -432,9 +418,7 @@ groupId="client-language"
432418

433419
## Update examples with attachments
434420

435-
### Using the SDK
436-
437-
In the code [above](#create-examples-with-attachments), we showed how to add examples with attachments to a dataset.
421+
In the code above, we showed how to add examples with attachments to a dataset.
438422
It is also possible to update these same examples using the SDK.
439423

440424
As with existing examples, datasets are versioned when you update them with attachments. Therefore, you can navigate to the dataset version history to see the changes made to each example.
@@ -507,14 +491,67 @@ dataset.id,
507491
groupId="client-language"
508492
/>
509493

510-
### From the UI
494+
</TabItem>
495+
<TabItem value="ui" label="UI">
496+
## 1. Create examples with attachments
497+
498+
You can add examples with attachments to a dataset in a few different ways.
499+
500+
### From existing runs
501+
502+
When adding runs to a LangSmith dataset, attachments can be selectively propagated from the source run to the destination example.
503+
To learn more, please see [this guide](./manage_datasets_in_application#add-runs-from-the-tracing-project-ui).
504+
505+
![](./static/add_trace_with_attachments_to_dataset.png)
506+
507+
### From scratch
508+
509+
You can create examples with attachments directly from the LangSmith UI. Click the `+ Example` button in the `Examples` tab of the dataset UI.
510+
Then upload attachments using the "Upload Files" button:
511+
512+
![](./static/create_example_with_attachments.png)
513+
514+
Once uploaded, you can view examples with attachments in the LangSmith UI. Each attachment will be rendered with a preview for easy inspection.
515+
![](./static/attachments_with_examples.png)
516+
517+
## 2. Create a multimodal prompt
518+
The LangSmith UI allows you to include attachments in your prompts when evaluating multimodal models:
519+
520+
First, click the file icon in the message where you want to add multimodal content.
521+
Next, add a template variable for the attachment(s) you want to include for each example.
522+
- For a single attachment type: Use the suggested variable name. Note: all examples must have an attachment with this name.
523+
- For multiple attachments or if your attachments have varying names from one example to another: Use the `All attachments` variable to include all available attachments for each example.
524+
525+
![](./static/adding_multimodal_variable.gif)
526+
527+
## Define custom evaluators
528+
529+
:::note Multimodal evaluators
530+
The LangSmith playground does not currently support pulling multimodal content into evaluators. If this would be helpful for your use case, please let us know in the [LangChain's community Slack](https://langchaincommunity.slack.com/) (sign up [here](https://www.langchain.com/join-community) if you're not already a member)!
531+
:::
532+
533+
You can evaluate a model's text output by adding an evaluator that takes in the example's inputs and outputs.
534+
Even without multimodal support in your evaluators, you can still run text-only evaluations. For example:
535+
536+
- OCR → text correction: Use a vision model to extract text from a document, then evaluate the accuracy of the extracted output.
537+
- Speech-to-text → transcription quality: Use a voice model to transcribe audio to text, then evaluate the transcription against your reference.
538+
539+
For more information on defining custom evaluators, see the [LLM as Judge](../how_to_guides/llm_as_judge) guide.
540+
541+
## Update examples with attachments
511542

512543
:::note Attachment Size Limit
513544
Attachments are limited to 20MB in size in the UI.
514545
:::
515546

516-
When editing an example in the UI, you can upload new attachments, rename and delete attachemnts,
517-
and there is also a quick reset button to restore the attachments to what previously existed on the example.
518-
No changes will be saved until you click submit.
547+
When editing an example in the UI, you can:
548+
- Upload new attachments
549+
- Rename and delete attachments
550+
- Reset attachments to their previous state using the quick reset button
551+
552+
Changes are not saved until you click submit.
519553

520554
![](./static/attachment_editing.gif)
555+
556+
</TabItem>
557+
</Tabs>

docs/evaluation/how_to_guides/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Evaluate and improve your application before deploying it.
2929
- [Evaluate an existing experiment (Python only)](./how_to_guides/evaluate_existing_experiment)
3030
- [Run an evaluation from the UI](./how_to_guides/run_evaluation_from_prompt_playground)
3131
- [Run an evaluation via the REST API](./how_to_guides/run_evals_api_only)
32-
- [Run an evaluation with large file inputs](./how_to_guides/evaluate_with_attachments)
32+
- [Run an evaluation with multimodal content](./how_to_guides/evaluate_with_attachments)
3333
- [Set up a multi-turn evaluation](./how_to_guides/multiturn_evaluation)
3434

3535
### Define an evaluator
Loading

docs/prompt_engineering/how_to_guides/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Organize and manage prompts in LangSmith to streamline your LLM development work
1717
Quickly iterate on prompts and models in the LangSmith Playground.
1818

1919
- [Run an evaluation in the Playground](/evaluation?mode=ui)
20+
- [Include multimodal content in a prompt](./how_to_guides/multimodal_content)
2021
- [Manage prompt settings](./how_to_guides/managing_model_configurations)
2122
- [Iterate on your prompts with the Prompt Canvas](./how_to_guides/prompt_canvas)
2223
- [Run the playground against a custom LangServe model server](./how_to_guides/custom_endpoint)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# Include multimodal content in a prompt
6+
7+
Some applications are based around multimodal content, like a chatbot that can answer questions about a PDF or image.
8+
In these cases, you'll want to include multimodal content in your prompt and test the model's ability to answer questions about the content.
9+
10+
The LangSmith Playground supports two methods for incorporating multimodal content in your prompts:
11+
12+
1. Inline content: Embed static files (images, PDFs, audio) directly in your prompt. This is ideal when you want to consistently include the same multimodal content across all uses of the prompt. For example, you might include a reference image that helps ground the model's responses.
13+
2. Template variables: Create dynamic placeholders for attachments that can be populated with different content each time. This approach offers more flexibility, allowing you to:
14+
- Test how the model handles different inputs
15+
- Create reusable prompts that work with varying content
16+
17+
:::note
18+
Not all models support multimodal content. Before using multimodal features in the playground, make sure your selected model supports the file types you want to use.
19+
:::
20+
21+
## Inline content
22+
23+
Click the file icon in the message where you want to add multimodal content.
24+
Under the `Upload content` tab, you can upload a file and include it inline in the prompt.
25+
26+
![](./static/upload_inline_multimodal_content.png)
27+
28+
## Template variables
29+
30+
Click the file icon in the message where you want to add multimodal content.
31+
Under the `Template variables` tab, you can create a template variable for a specific attachment type.
32+
Currently, only images, PDFs, and audio files (.wav, .mp3) are supported.
33+
34+
![](./static/template_variable_multimodal_content.png)
35+
36+
## Populate the template variable
37+
38+
Once you've added a template variable, you can provide content for it using the panel on the right side of the screen. Simply click the `+` button to upload or select content that will be used to populate the template variable.
39+
40+
![](./static/manual_prompt_multimodal.png)
41+
42+
## Run an evaluation
43+
44+
After testing out your prompt manually, you can [run an evaluation](../../evaluation/how_to_guides/evaluate_with_attachments?mode=ui) to see how the prompt performs over a golden dataset of examples.
Loading
Loading
Loading

src/css/custom.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ html[data-theme="dark"] {
267267
}
268268

269269
/* Dark mode specific styling */
270-
[data-theme='dark'] .fold-markers {
270+
[data-theme="dark"] .fold-markers {
271271
/* background: var(--prism-background-color) !important; */
272272
background: #1e1e1e;
273273
}
@@ -322,7 +322,7 @@ html[data-theme="dark"] {
322322
}
323323

324324
.code-block-with-gutter {
325-
padding-left: 12px
325+
padding-left: 12px;
326326
}
327327

328328
/* Remove theme border */
@@ -359,7 +359,7 @@ html[data-theme="dark"] {
359359
.tabs-container > .code-tabs {
360360
background: #1e1e1e;
361361
}
362-
362+
363363
.tabs-container .code-caption {
364364
background: #1e1e1e;
365365
}
@@ -422,7 +422,7 @@ hr {
422422
background-color: var(--joy-palette-background-level2) !important;
423423
}
424424

425-
div[class^='announcementBar_'] {
425+
div[class^="announcementBar_"] {
426426
font-size: 20px;
427427
background-color: #d0c9feff;
428428
font-weight: bold;
@@ -439,9 +439,9 @@ div[class^='announcementBar_'] {
439439
.interface-tabs {
440440
padding: 10px;
441441
border: none;
442-
border-bottom: 1.5px solid #cbbbbb;
442+
border-bottom: 1.5px solid #cbbbbb;
443443
}
444444

445445
.interface-tabs .tabs__item {
446446
font-size: 1.25rem;
447-
}
447+
}

0 commit comments

Comments
 (0)