-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Simplification of Document Search Evaluation interface #258
Open
kdziedzic68
wants to merge
4
commits into
main
Choose a base branch
from
eval-interface-simpification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.
9 changes: 9 additions & 0 deletions
9
examples/evaluation/document-search/advanced/config/pipeline/document_ingestion.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,9 @@ | ||
defaults: | ||
- embedder: litellm | ||
- providers: unstructured | ||
- vector_store: chroma | ||
- _self_ | ||
|
||
type: ragbits.evaluate.pipelines.document_search:DocumentSearchWithIngestionPipeline | ||
ingest: true | ||
search: 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
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.
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,26 @@ | ||
import sys | ||
|
||
import hydra | ||
from omegaconf import DictConfig, OmegaConf | ||
|
||
from ragbits.evaluate.optimizer import Optimizer | ||
from ragbits.evaluate.utils import log_optimization_to_file | ||
|
||
module = sys.modules[__name__] | ||
|
||
|
||
@hydra.main(config_path="config", config_name="optimization", version_base="3.2") | ||
def main(config: DictConfig) -> None: | ||
""" | ||
Function running evaluation for all datasets and evaluation tasks defined in hydra config. | ||
|
||
Args: | ||
config: Hydra configuration. | ||
""" | ||
exp_config = {"optimizer": OmegaConf.create({"direction": "maximize", "n_trials": 10}), "experiment_config": config} | ||
configs_with_scores = Optimizer.run_experiment_from_config(config=exp_config) | ||
log_optimization_to_file(configs_with_scores) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
79 changes: 79 additions & 0 deletions
79
examples/evaluation/document-search/basic/basic_evaluate.py
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,79 @@ | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [ | ||
# "ragbits-document-search[huggingface]", | ||
# "ragbits-core[chroma]", | ||
# "hydra-core~=1.3.2", | ||
# "unstructured[md]>=0.15.13", | ||
# ] | ||
# /// | ||
import asyncio | ||
import logging | ||
import uuid | ||
from pathlib import Path | ||
|
||
from omegaconf import OmegaConf | ||
|
||
from ragbits.evaluate.evaluator import Evaluator | ||
from ragbits.evaluate.utils import log_to_file | ||
|
||
logging.getLogger("LiteLLM").setLevel(logging.ERROR) | ||
logging.getLogger("httpx").setLevel(logging.ERROR) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
async def evaluate() -> dict: | ||
""" | ||
Basic example of document search evaluation. | ||
|
||
""" | ||
log.info("Ingesting documents...") | ||
|
||
config = OmegaConf.create( | ||
{ | ||
"pipeline": { | ||
"type": "ragbits.evaluate.pipelines.document_search:DocumentSearchWithIngestionPipeline", | ||
"ingest": False, | ||
"search": True, | ||
"providers": { | ||
"txt": { | ||
"type": "ragbits.document_search.ingestion.providers.unstructured:UnstructuredDefaultProvider" | ||
} | ||
}, | ||
}, | ||
"data": { | ||
"type": "ragbits.evaluate.loaders.hf:HFDataLoader", | ||
"options": {"name": "hf-docs-retrieval", "path": "micpst/hf-docs-retrieval", "split": "train"}, | ||
}, | ||
"metrics": [ | ||
{ | ||
"type": "ragbits.evaluate.metrics.document_search:DocumentSearchPrecisionRecallF1", | ||
"matching_strategy": "RougeChunkMatch", | ||
"options": {"threshold": 0.5}, | ||
} | ||
], | ||
"neptune": {"project": "ragbits", "run": False}, | ||
"task": {"name": "default", "type": "document-search"}, | ||
} | ||
) | ||
|
||
results = await Evaluator.run_experiment_from_config(config=config) | ||
|
||
log.info("Evaluation finished.") | ||
|
||
return results | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Run the evaluation process. | ||
|
||
""" | ||
results = asyncio.run(evaluate()) | ||
out_dir = Path(str(uuid.uuid4())) | ||
out_dir.mkdir() | ||
log_to_file(results, output_dir=out_dir) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() # pylint: disable=no-value-for-parameter |
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,61 @@ | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [ | ||
# "ragbits-document-search[huggingface]", | ||
# "ragbits-core[chroma]", | ||
# "hydra-core~=1.3.2", | ||
# "unstructured[md]>=0.15.13", | ||
# ] | ||
# /// | ||
import asyncio | ||
import logging | ||
|
||
from omegaconf import OmegaConf | ||
|
||
from ragbits.evaluate.pipelines import pipeline_factory | ||
|
||
logging.getLogger("LiteLLM").setLevel(logging.ERROR) | ||
logging.getLogger("httpx").setLevel(logging.ERROR) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
async def ingest() -> None: | ||
""" | ||
Ingest documents into the document search system. | ||
|
||
Args: | ||
config: Hydra configuration. | ||
""" | ||
log.info("Ingesting documents...") | ||
|
||
config = OmegaConf.create( | ||
{ | ||
"type": "ragbits.evaluate.pipelines.document_search:DocumentSearchWithIngestionPipeline", | ||
"ingest": True, | ||
"search": False, | ||
"answer_data_source": {"name": "hf-docs", "path": "micpst/hf-docs", "split": "train", "num_docs": 5}, | ||
"providers": { | ||
"txt": {"type": "ragbits.document_search.ingestion.providers.unstructured:UnstructuredDefaultProvider"} | ||
}, | ||
} | ||
) | ||
|
||
ingestor = pipeline_factory(config) # type: ignore | ||
|
||
await ingestor() | ||
|
||
log.info("Ingestion finished.") | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Run the ingestion process. | ||
|
||
Args: | ||
config: Hydra configuration. | ||
""" | ||
asyncio.run(ingest()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() # pylint: disable=no-value-for-parameter |
61 changes: 61 additions & 0 deletions
61
examples/evaluation/document-search/basic/basic_optimize.py
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,61 @@ | ||
import sys | ||
|
||
from omegaconf import OmegaConf | ||
|
||
from ragbits.evaluate.optimizer import Optimizer | ||
from ragbits.evaluate.utils import log_optimization_to_file | ||
|
||
module = sys.modules[__name__] | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Function running evaluation for all datasets and evaluation tasks defined in config. | ||
""" | ||
config = OmegaConf.create( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have to wrap these configs with hydra? |
||
{ | ||
"pipeline": { | ||
"type": "ragbits.evaluate.pipelines.document_search:DocumentSearchWithIngestionPipeline", | ||
"ingest": True, | ||
"search": True, | ||
"answer_data_source": { | ||
"name": "hf-docs", | ||
"path": "micpst/hf-docs", | ||
"split": "train", | ||
"num_docs": 5, | ||
}, | ||
"providers": { | ||
"txt": { | ||
"type": "ragbits.document_search.ingestion.providers.unstructured:UnstructuredDefaultProvider" | ||
} | ||
}, | ||
"embedder": { | ||
"type": "ragbits.core.embeddings.litellm:LiteLLMEmbeddings", | ||
"config": { | ||
"model": "text-embedding-3-small", | ||
"options": { | ||
"dimensions": {"optimize": True, "range": [32, 512]}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"data": { | ||
"type": "ragbits.evaluate.loaders.hf:HFDataLoader", | ||
"options": {"name": "hf-docs-retrieval", "path": "micpst/hf-docs-retrieval", "split": "train"}, | ||
}, | ||
"metrics": [ | ||
{ | ||
"type": "ragbits.evaluate.metrics.document_search:DocumentSearchPrecisionRecallF1", | ||
"matching_strategy": "RougeChunkMatch", | ||
"options": {"threshold": 0.5}, | ||
} | ||
], | ||
} | ||
) | ||
exp_config = {"optimizer": OmegaConf.create({"direction": "maximize", "n_trials": 10}), "experiment_config": config} | ||
configs_with_scores = Optimizer.run_experiment_from_config(config=exp_config) | ||
log_optimization_to_file(configs_with_scores) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
5 changes: 0 additions & 5 deletions
5
examples/evaluation/document-search/config/pipeline/document_ingestion.yaml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
12 changes: 11 additions & 1 deletion
12
packages/ragbits-core/src/ragbits/core/vector_stores/__init__.py
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,4 +1,14 @@ | ||
from ragbits.core.vector_stores.base import VectorStore, VectorStoreEntry, VectorStoreOptions, WhereQuery | ||
from ragbits.core.vector_stores.chroma import ChromaVectorStore | ||
from ragbits.core.vector_stores.in_memory import InMemoryVectorStore | ||
from ragbits.core.vector_stores.qdrant import QdrantVectorStore | ||
|
||
__all__ = ["InMemoryVectorStore", "VectorStore", "VectorStoreEntry", "VectorStoreOptions", "WhereQuery"] | ||
__all__ = [ | ||
"ChromaVectorStore", | ||
"InMemoryVectorStore", | ||
"QdrantVectorStore", | ||
"VectorStore", | ||
"VectorStoreEntry", | ||
"VectorStoreOptions", | ||
"WhereQuery", | ||
] |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it commented?