Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8b8d1fe
add langchain loaders to docs
shahules786 Oct 19, 2023
cd7f411
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Oct 20, 2023
5b18325
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Oct 26, 2023
bb8d984
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Oct 26, 2023
9cbb57d
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Oct 29, 2023
479e636
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 7, 2023
3eeb7ea
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 12, 2023
b09003f
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 17, 2023
0d28d62
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 20, 2023
8e7c0c4
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 24, 2023
dd218e1
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 26, 2023
eab12df
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 27, 2023
a0f1b9b
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Nov 29, 2023
2487430
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Dec 1, 2023
fb5064e
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Dec 10, 2023
fd8f458
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Dec 10, 2023
c2f4be8
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Dec 13, 2023
3247925
hindi prompts for faithfulness
shahules786 Dec 17, 2023
a5fcded
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Dec 18, 2023
f39a9ca
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Dec 25, 2023
30a82ba
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Jan 3, 2024
5fecf0f
Merge branch 'main' of https://github.com/explodinggradients/ragas
shahules786 Jan 5, 2024
90cd438
add langsmith docs
shahules786 Jan 7, 2024
ba5d87e
Merge branch 'main' of https://github.com/shahules786/ragas into dev#…
shahules786 Jan 7, 2024
fe85ea8
add tracing
shahules786 Jan 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/_static/imgs/trace-langsmith.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/howtos/applications/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ compare_embeddings
compare_llms
custom_prompts
use_prompt_adaptation
tracing
```
41 changes: 41 additions & 0 deletions docs/howtos/applications/tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Logging and tracing

Logging and tracing results from llm are important for any language model-based application. This is a tutorial on how to do tracing with Ragas. Ragas provides `callbacks` functionality which allows you to hook various tracers like Langmsith, wandb, etc easily. In this notebook, I will be using Langmith for tracing

To set up Langsmith, we need to set some environment variables that it needs. For more information, you can refer to the [docs](https://docs.smith.langchain.com/)

```{code-block} bash
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
```

Now we have to import the required tracer from langchain, here we are using `LangChainTracer` but you can similarly use any tracer supported by langchain like [WandbTracer](https://python.langchain.com/docs/integrations/providers/wandb_tracing)

```{code-block} python
# langsmith
from langchain.callbacks.tracers import LangChainTracer

tracer = LangChainTracer(project_name="callback-experiments")
```

We now pass the tracer to the `callbacks` parameter when calling `evaluate`

```{code-block} python
from datasets import load_dataset
from ragas.metrics import context_precision
from ragas import evaluate

dataset = load_dataset("explodinggradients/amnesty_qa","english")
evaluate(dataset["train"],metrics=[context_precision],callbacks=[tracer])
```

```
{'context_precision': 1.0000}
```
![](./../../_static/imgs/trace-langsmith.png)


You can also write your own custom callbacks using langchain’s `BaseCallbackHandler`, refer [here](https://www.notion.so/Docs-logging-and-tracing-6f21cde9b3cb4d499526f48fd615585d?pvs=21) to read more about it.