-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplification of Document Search Evaluation interface (#258)
Co-authored-by: Michał Pstrąg <[email protected]>
- Loading branch information
1 parent
0fa1308
commit f62a084
Showing
66 changed files
with
900 additions
and
769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 14 additions & 10 deletions
24
...ples/evaluation/document-search/README.md → ...uation/document-search/advanced/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
# Document Search Evaluation | ||
|
||
## Ingest | ||
## Evaluation | ||
|
||
### Evaluation on ingested data | ||
|
||
```sh | ||
uv run ingest.py | ||
uv run evaluate.py | ||
``` | ||
|
||
```sh | ||
uv run ingest.py +experiments=chunking-250 | ||
uv run evaluate.py +experiments=chunking-250 | ||
``` | ||
|
||
```sh | ||
uv run ingest.py --multirun +experiments=chunking-250,chunking-500,chunking-1000 | ||
uv run evaluate.py --multirun +experiments=chunking-250,chunking-500,chunking-1000 | ||
``` | ||
|
||
## Evaluate | ||
### Logging | ||
|
||
```sh | ||
uv run evaluate.py | ||
uv run evaluate.py logger.local=True | ||
``` | ||
|
||
```sh | ||
uv run evaluate.py +experiments=chunking-250 | ||
uv run evaluate.py logger.neptune=True | ||
``` | ||
|
||
## Optimization | ||
|
||
```sh | ||
uv run evaluate.py --multirun +experiments=chunking-250,chunking-500,chunking-1000 | ||
uv run optimize.py | ||
``` | ||
|
||
### Log to Neptune | ||
### Monitoring | ||
|
||
```sh | ||
uv run evaluate.py neptune.run=True | ||
uv run optimize.py neptune_callback=True | ||
``` |
4 changes: 4 additions & 0 deletions
4
examples/evaluation/document-search/advanced/config/dataloader/hf.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type: ragbits.evaluate.dataloaders.hf:HFDataLoader | ||
config: | ||
path: "micpst/hf-docs-retrieval" | ||
split: "train" |
21 changes: 21 additions & 0 deletions
21
examples/evaluation/document-search/advanced/config/experiments/chunking-1000.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# @package _global_ | ||
|
||
task: | ||
name: chunking-1000 | ||
|
||
pipeline: | ||
config: | ||
providers: | ||
txt: | ||
config: | ||
chunking_kwargs: | ||
max_characters: 1000 | ||
new_after_n_chars: 200 | ||
md: | ||
config: | ||
chunking_kwargs: | ||
max_characters: 1000 | ||
new_after_n_chars: 200 | ||
vector_store: | ||
config: | ||
index_name: chunk-1000 |
21 changes: 21 additions & 0 deletions
21
examples/evaluation/document-search/advanced/config/experiments/chunking-250.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# @package _global_ | ||
|
||
task: | ||
name: chunking-250 | ||
|
||
pipeline: | ||
config: | ||
providers: | ||
txt: | ||
config: | ||
chunking_kwargs: | ||
max_characters: 250 | ||
new_after_n_chars: 50 | ||
md: | ||
config: | ||
chunking_kwargs: | ||
max_characters: 250 | ||
new_after_n_chars: 50 | ||
vector_store: | ||
config: | ||
index_name: chunk-250 |
21 changes: 21 additions & 0 deletions
21
examples/evaluation/document-search/advanced/config/experiments/chunking-500.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# @package _global_ | ||
|
||
task: | ||
name: chunking-500 | ||
|
||
pipeline: | ||
config: | ||
providers: | ||
txt: | ||
config: | ||
chunking_kwargs: | ||
max_characters: 500 | ||
new_after_n_chars: 100 | ||
md: | ||
config: | ||
chunking_kwargs: | ||
max_characters: 500 | ||
new_after_n_chars: 100 | ||
vector_store: | ||
config: | ||
index_name: chunk-500 |
7 changes: 7 additions & 0 deletions
7
examples/evaluation/document-search/advanced/config/metrics/precision_recall_f1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
precision_recall_f1: | ||
type: ragbits.evaluate.metrics.document_search:DocumentSearchPrecisionRecallF1 | ||
config: | ||
matching_strategy: | ||
type: RougeChunkMatch | ||
config: | ||
threshold: 0.5 |
7 changes: 7 additions & 0 deletions
7
examples/evaluation/document-search/advanced/config/metrics/ranked_retrieval.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ranked_retrieval: | ||
type: ragbits.evaluate.metrics.document_search:DocumentSearchRankedRetrievalMetrics | ||
config: | ||
matching_strategy: | ||
type: RougeChunkMatch | ||
config: | ||
threshold: 0.5 |
14 changes: 14 additions & 0 deletions
14
examples/evaluation/document-search/advanced/config/optimization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defaults: | ||
- [email protected]: hf | ||
- [email protected]: document_search_optimization | ||
- [email protected]: | ||
- precision_recall_f1 | ||
- ranked_retrieval | ||
- _self_ | ||
|
||
optimizer: | ||
direction: maximize | ||
n_trials: 5 | ||
max_retries_for_trial: 1 | ||
|
||
neptune_callback: False |
10 changes: 10 additions & 0 deletions
10
examples/evaluation/document-search/advanced/config/pipeline/document_search.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defaults: | ||
- [email protected]: litellm | ||
- [email protected]_store: chroma | ||
- [email protected]: noop | ||
- [email protected]: noop | ||
- [email protected]: unstructured | ||
- [email protected]: hf | ||
- _self_ | ||
|
||
type: ragbits.evaluate.pipelines.document_search:DocumentSearchPipeline |
10 changes: 10 additions & 0 deletions
10
...les/evaluation/document-search/advanced/config/pipeline/document_search_optimization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defaults: | ||
- [email protected]: litellm_optimization | ||
- [email protected]_store: chroma | ||
- [email protected]: noop | ||
- [email protected]: noop | ||
- [email protected]: unstructured_optimization | ||
- [email protected]: hf | ||
- _self_ | ||
|
||
type: ragbits.evaluate.pipelines.document_search:DocumentSearchPipeline |
2 changes: 1 addition & 1 deletion
2
...rch/config/pipeline/embedder/litellm.yaml → ...ced/config/pipeline/embedder/litellm.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
type: ragbits.core.embeddings.litellm:LiteLLMEmbeddings | ||
config: | ||
model: "text-embedding-3-small" | ||
options: | ||
default_options: | ||
dimensions: 768 | ||
encoding_format: float |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
examples/evaluation/document-search/advanced/config/pipeline/source/hf.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type: ragbits.document_search.documents.sources:HuggingFaceSource | ||
config: | ||
path: "micpst/hf-docs" | ||
split: "train[:5]" |
6 changes: 2 additions & 4 deletions
6
.../config/pipeline/vector_store/chroma.yaml → .../config/pipeline/vector_store/chroma.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
examples/evaluation/document-search/advanced/config/retrieval.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defaults: | ||
- dataloader: hf | ||
- pipeline: document_search | ||
- metrics: | ||
- precision_recall_f1 | ||
- ranked_retrieval | ||
- _self_ | ||
|
||
logger: | ||
local: True | ||
neptune: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [ | ||
# "ragbits-core[chroma]", | ||
# "ragbits-document-search[huggingface]", | ||
# "ragbits-evaluate[relari]", | ||
# ] | ||
# /// | ||
import asyncio | ||
import logging | ||
from typing import cast | ||
|
||
import hydra | ||
from omegaconf import DictConfig, OmegaConf | ||
|
||
from ragbits.evaluate.evaluator import Evaluator | ||
from ragbits.evaluate.utils import log_evaluation_to_file, log_evaluation_to_neptune | ||
|
||
logging.getLogger("LiteLLM").setLevel(logging.ERROR) | ||
logging.getLogger("httpx").setLevel(logging.ERROR) | ||
|
||
|
||
async def evaluate(config: DictConfig) -> None: | ||
""" | ||
Document search evaluation runner. | ||
Args: | ||
config: Hydra configuration. | ||
""" | ||
print("Starting evaluation...") | ||
|
||
evaluator_config = cast(dict, OmegaConf.to_container(config)) | ||
results = await Evaluator.run_from_config(evaluator_config) | ||
|
||
if config.logger.local: | ||
output_dir = log_evaluation_to_file(results) | ||
print(f"Evaluation results saved under directory: {output_dir}") | ||
|
||
if config.logger.neptune: | ||
log_evaluation_to_neptune(results, config) | ||
print("Evaluation results uploaded to Neptune") | ||
|
||
|
||
@hydra.main(config_path="config", config_name="retrieval", version_base="3.2") | ||
def main(config: DictConfig) -> None: | ||
""" | ||
Runs the evaluation process. | ||
Args: | ||
config: Hydra configuration. | ||
""" | ||
asyncio.run(evaluate(config)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [ | ||
# "ragbits-core[chroma]", | ||
# "ragbits-document-search[huggingface]", | ||
# "ragbits-evaluate[relari]", | ||
# ] | ||
# /// | ||
import logging | ||
from typing import cast | ||
|
||
import hydra | ||
from omegaconf import DictConfig, OmegaConf | ||
|
||
from ragbits.evaluate.optimizer import Optimizer | ||
from ragbits.evaluate.utils import log_optimization_to_file | ||
|
||
logging.getLogger("LiteLLM").setLevel(logging.ERROR) | ||
logging.getLogger("httpx").setLevel(logging.ERROR) | ||
|
||
|
||
@hydra.main(config_path="config", config_name="optimization", version_base="3.2") | ||
def main(config: DictConfig) -> None: | ||
""" | ||
Runs the optimization process. | ||
Args: | ||
config: Hydra configuration. | ||
""" | ||
print("Starting optimization...") | ||
|
||
optimizer_config = cast(dict, OmegaConf.to_container(config)) | ||
configs_with_scores = Optimizer.run_from_config(optimizer_config) | ||
|
||
output_dir = log_optimization_to_file(configs_with_scores) | ||
print(f"Optimization results saved under directory: {output_dir}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.