Skip to content

Commit

Permalink
Add Uptrain Callback Handler (run-llama#10432)
Browse files Browse the repository at this point in the history
* Add UpTrain Callback Handler

* Add logging

* Add note for project_name prefix

* Minor fixes

* Add explanations

* Add showcase

* Add callback to uptrain.md

* update import

* linter

* Update .gitignore file to ignore .venv and __pycache__ directories

* Fix imports

* create llama-index-callback-uptrain

* Update UpTrainCallback.ipynb

* Update README.md

* Run pants tailor
  • Loading branch information
Dominastorm authored and Izuki Matsuba committed Mar 29, 2024
1 parent 23252e9 commit bd25267
Show file tree
Hide file tree
Showing 17 changed files with 6,052 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
dist/
migration_scripts/
venv/
.venv/
.ipynb_checkpoints
.__pycache__
__pycache__
dev_notebooks/
llamaindex_registry.txt
packages_to_bump_deduped.txt
368 changes: 364 additions & 4 deletions docs/community/integrations/uptrain.md

Large diffs are not rendered by default.

643 changes: 643 additions & 0 deletions docs/examples/callbacks/UpTrainCallback.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/evaluation/UpTrain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "ec212316",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/uptrain-ai/llama_index/blob/uptrain_integration/docs/examples/evaluation/UpTrain.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/evaluation/UpTrain.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
poetry_requirements(
name="poetry",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)

help: ## Show all Makefile targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'

format: ## Run code autoformatters (black).
pre-commit install
git ls-files | xargs pre-commit run black --files

lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files

test: ## Run tests via pytest.
pytest tests

watch-docs: ## Build and watch documentation.
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# LlamaIndex Callbacks Integration: UpTrain

UpTrain is an open-source tool to evaluate and monitor the performance of language models. It provides a set of pre-built evaluations to assess the quality of responses generated by the model. Once you add UpTrainCallbackHandler to your existing LlamaIndex pipeline, it will take care of sending the generated responses to the UpTrain Managed Service for evaluations and display the results in the output.

Three additional evaluations for Llamaindex have been introduced, complementing existing ones. These evaluations run automatically, with results displayed in the output. More details on UpTrain's evaluations can be found [here](https://github.com/uptrain-ai/uptrain?tab=readme-ov-file#pre-built-evaluations-we-offer-).

Selected operators from the LlamaIndex pipeline are highlighted for demonstration:

## 1. **RAG Query Engine Evaluations**:

The RAG query engine plays a crucial role in retrieving context and generating responses. To ensure its performance and response quality, we conduct the following evaluations:

- **Context Relevance**: Determines if the context extracted from the query is relevant to the response.
- **Factual Accuracy**: Assesses if the LLM is hallcuinating or providing incorrect information.
- **Response Completeness**: Checks if the response contains all the information requested by the query.

## 2. **Sub-Question Query Generation Evaluation**:

The SubQuestionQueryGeneration operator decomposes a question into sub-questions, generating responses for each using a RAG query engine. Given the complexity, we include the previous evaluations and add:

- **Sub Query Completeness**: Assures that the sub-questions accurately and comprehensively cover the original query.

## 3. **Re-Ranking Evaluations**:

Re-ranking involves reordering nodes based on relevance to the query and choosing top n nodes. Different evaluations are performed based on the number of nodes returned after re-ranking.

a. Same Number of Nodes

- **Context Reranking**: Checks if the order of re-ranked nodes is more relevant to the query than the original order.

b. Different Number of Nodes:

- **Context Conciseness**: Examines whether the reduced number of nodes still provides all the required information.

These evaluations collectively ensure the robustness and effectiveness of the RAG query engine, SubQuestionQueryGeneration operator, and the re-ranking process in the LlamaIndex pipeline.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from llama_index.callbacks.uptrain.base import UpTrainCallbackHandler

__all__ = ["UpTrainCallbackHandler"]
Loading

0 comments on commit bd25267

Please sign in to comment.