AutoRAG 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- autorag/__init__.py +82 -0
- autorag/chunker.py +51 -0
- autorag/cli.py +209 -0
- autorag/dashboard.py +199 -0
- autorag/data/__init__.py +109 -0
- autorag/data/chunk/__init__.py +2 -0
- autorag/data/chunk/base.py +128 -0
- autorag/data/chunk/langchain_chunk.py +76 -0
- autorag/data/chunk/llama_index_chunk.py +96 -0
- autorag/data/chunk/run.py +38 -0
- autorag/data/legacy/__init__.py +0 -0
- autorag/data/legacy/corpus/__init__.py +2 -0
- autorag/data/legacy/corpus/langchain.py +47 -0
- autorag/data/legacy/corpus/llama_index.py +93 -0
- autorag/data/legacy/qacreation/__init__.py +6 -0
- autorag/data/legacy/qacreation/base.py +239 -0
- autorag/data/legacy/qacreation/llama_index.py +253 -0
- autorag/data/legacy/qacreation/llama_index_default_prompt.txt +54 -0
- autorag/data/legacy/qacreation/ragas.py +75 -0
- autorag/data/legacy/qacreation/simple.py +99 -0
- autorag/data/parse/__init__.py +1 -0
- autorag/data/parse/base.py +79 -0
- autorag/data/parse/clova.py +194 -0
- autorag/data/parse/langchain_parse.py +87 -0
- autorag/data/parse/llamaparse.py +126 -0
- autorag/data/parse/run.py +141 -0
- autorag/data/parse/table_hybrid_parse.py +134 -0
- autorag/data/qa/__init__.py +3 -0
- autorag/data/qa/evolve/__init__.py +0 -0
- autorag/data/qa/evolve/llama_index_query_evolve.py +64 -0
- autorag/data/qa/evolve/openai_query_evolve.py +81 -0
- autorag/data/qa/evolve/prompt.py +288 -0
- autorag/data/qa/extract_evidence.py +1 -0
- autorag/data/qa/filter/__init__.py +0 -0
- autorag/data/qa/filter/dontknow.py +117 -0
- autorag/data/qa/filter/passage_dependency.py +88 -0
- autorag/data/qa/filter/prompt.py +73 -0
- autorag/data/qa/generation_gt/__init__.py +0 -0
- autorag/data/qa/generation_gt/base.py +16 -0
- autorag/data/qa/generation_gt/llama_index_gen_gt.py +41 -0
- autorag/data/qa/generation_gt/openai_gen_gt.py +84 -0
- autorag/data/qa/generation_gt/prompt.py +27 -0
- autorag/data/qa/query/__init__.py +0 -0
- autorag/data/qa/query/llama_gen_query.py +82 -0
- autorag/data/qa/query/openai_gen_query.py +95 -0
- autorag/data/qa/query/prompt.py +201 -0
- autorag/data/qa/sample.py +26 -0
- autorag/data/qa/schema.py +322 -0
- autorag/data/utils/__init__.py +0 -0
- autorag/data/utils/util.py +103 -0
- autorag/deploy/__init__.py +9 -0
- autorag/deploy/api.py +303 -0
- autorag/deploy/base.py +235 -0
- autorag/deploy/gradio.py +74 -0
- autorag/deploy/swagger.yml +202 -0
- autorag/embedding/__init__.py +0 -0
- autorag/embedding/base.py +144 -0
- autorag/embedding/vllm.py +256 -0
- autorag/evaluation/__init__.py +3 -0
- autorag/evaluation/generation.py +88 -0
- autorag/evaluation/metric/__init__.py +22 -0
- autorag/evaluation/metric/deepeval_prompt.py +322 -0
- autorag/evaluation/metric/g_eval_prompts/coh_detailed.txt +32 -0
- autorag/evaluation/metric/g_eval_prompts/con_detailed.txt +33 -0
- autorag/evaluation/metric/g_eval_prompts/flu_detailed.txt +26 -0
- autorag/evaluation/metric/g_eval_prompts/rel_detailed.txt +33 -0
- autorag/evaluation/metric/generation.py +504 -0
- autorag/evaluation/metric/retrieval.py +115 -0
- autorag/evaluation/metric/retrieval_contents.py +65 -0
- autorag/evaluation/metric/util.py +88 -0
- autorag/evaluation/retrieval.py +83 -0
- autorag/evaluation/retrieval_contents.py +65 -0
- autorag/evaluation/util.py +43 -0
- autorag/evaluator.py +559 -0
- autorag/node_line.py +65 -0
- autorag/nodes/__init__.py +0 -0
- autorag/nodes/generator/__init__.py +4 -0
- autorag/nodes/generator/base.py +103 -0
- autorag/nodes/generator/llama_index_llm.py +169 -0
- autorag/nodes/generator/openai_llm.py +329 -0
- autorag/nodes/generator/run.py +148 -0
- autorag/nodes/generator/vllm.py +147 -0
- autorag/nodes/generator/vllm_api.py +191 -0
- autorag/nodes/hybridretrieval/__init__.py +2 -0
- autorag/nodes/hybridretrieval/base.py +58 -0
- autorag/nodes/hybridretrieval/hybrid_cc.py +227 -0
- autorag/nodes/hybridretrieval/hybrid_rrf.py +149 -0
- autorag/nodes/hybridretrieval/run.py +137 -0
- autorag/nodes/lexicalretrieval/__init__.py +1 -0
- autorag/nodes/lexicalretrieval/bm25.py +381 -0
- autorag/nodes/lexicalretrieval/run.py +148 -0
- autorag/nodes/passageaugmenter/__init__.py +2 -0
- autorag/nodes/passageaugmenter/base.py +76 -0
- autorag/nodes/passageaugmenter/pass_passage_augmenter.py +43 -0
- autorag/nodes/passageaugmenter/prev_next_augmenter.py +155 -0
- autorag/nodes/passageaugmenter/run.py +131 -0
- autorag/nodes/passagecompressor/__init__.py +4 -0
- autorag/nodes/passagecompressor/base.py +78 -0
- autorag/nodes/passagecompressor/longllmlingua.py +115 -0
- autorag/nodes/passagecompressor/pass_compressor.py +16 -0
- autorag/nodes/passagecompressor/refine.py +54 -0
- autorag/nodes/passagecompressor/run.py +186 -0
- autorag/nodes/passagecompressor/tree_summarize.py +56 -0
- autorag/nodes/passagefilter/__init__.py +6 -0
- autorag/nodes/passagefilter/base.py +40 -0
- autorag/nodes/passagefilter/pass_passage_filter.py +14 -0
- autorag/nodes/passagefilter/percentile_cutoff.py +58 -0
- autorag/nodes/passagefilter/recency.py +105 -0
- autorag/nodes/passagefilter/run.py +138 -0
- autorag/nodes/passagefilter/similarity_percentile_cutoff.py +134 -0
- autorag/nodes/passagefilter/similarity_threshold_cutoff.py +112 -0
- autorag/nodes/passagefilter/threshold_cutoff.py +78 -0
- autorag/nodes/passagereranker/__init__.py +16 -0
- autorag/nodes/passagereranker/base.py +44 -0
- autorag/nodes/passagereranker/cohere.py +118 -0
- autorag/nodes/passagereranker/colbert.py +213 -0
- autorag/nodes/passagereranker/flag_embedding.py +112 -0
- autorag/nodes/passagereranker/flag_embedding_llm.py +101 -0
- autorag/nodes/passagereranker/flashrank.py +245 -0
- autorag/nodes/passagereranker/jina.py +115 -0
- autorag/nodes/passagereranker/koreranker.py +136 -0
- autorag/nodes/passagereranker/mixedbreadai.py +126 -0
- autorag/nodes/passagereranker/monot5.py +190 -0
- autorag/nodes/passagereranker/openvino.py +191 -0
- autorag/nodes/passagereranker/pass_reranker.py +31 -0
- autorag/nodes/passagereranker/rankgpt.py +170 -0
- autorag/nodes/passagereranker/run.py +145 -0
- autorag/nodes/passagereranker/sentence_transformer.py +129 -0
- autorag/nodes/passagereranker/tart/__init__.py +1 -0
- autorag/nodes/passagereranker/tart/modeling_enc_t5.py +152 -0
- autorag/nodes/passagereranker/tart/tart.py +139 -0
- autorag/nodes/passagereranker/tart/tokenization_enc_t5.py +112 -0
- autorag/nodes/passagereranker/time_reranker.py +72 -0
- autorag/nodes/passagereranker/upr.py +160 -0
- autorag/nodes/passagereranker/voyageai.py +109 -0
- autorag/nodes/promptmaker/__init__.py +12 -0
- autorag/nodes/promptmaker/base.py +32 -0
- autorag/nodes/promptmaker/chat_fstring.py +73 -0
- autorag/nodes/promptmaker/fstring.py +49 -0
- autorag/nodes/promptmaker/long_context_reorder.py +83 -0
- autorag/nodes/promptmaker/run.py +283 -0
- autorag/nodes/promptmaker/window_replacement.py +85 -0
- autorag/nodes/queryexpansion/__init__.py +4 -0
- autorag/nodes/queryexpansion/base.py +62 -0
- autorag/nodes/queryexpansion/hyde.py +43 -0
- autorag/nodes/queryexpansion/multi_query_expansion.py +57 -0
- autorag/nodes/queryexpansion/pass_query_expansion.py +22 -0
- autorag/nodes/queryexpansion/query_decompose.py +111 -0
- autorag/nodes/queryexpansion/run.py +308 -0
- autorag/nodes/retrieval/__init__.py +0 -0
- autorag/nodes/retrieval/base.py +127 -0
- autorag/nodes/retrieval/run_util.py +152 -0
- autorag/nodes/semanticretrieval/__init__.py +1 -0
- autorag/nodes/semanticretrieval/run.py +148 -0
- autorag/nodes/semanticretrieval/vectordb.py +339 -0
- autorag/nodes/util.py +16 -0
- autorag/parser.py +37 -0
- autorag/schema/__init__.py +3 -0
- autorag/schema/base.py +35 -0
- autorag/schema/metricinput.py +99 -0
- autorag/schema/module.py +24 -0
- autorag/schema/node.py +144 -0
- autorag/strategy.py +165 -0
- autorag/support.py +235 -0
- autorag/utils/__init__.py +8 -0
- autorag/utils/cast.py +45 -0
- autorag/utils/preprocess.py +149 -0
- autorag/utils/util.py +759 -0
- autorag/validator.py +98 -0
- autorag/vectordb/__init__.py +75 -0
- autorag/vectordb/base.py +73 -0
- autorag/vectordb/chroma.py +118 -0
- autorag/vectordb/couchbase.py +239 -0
- autorag/vectordb/milvus.py +169 -0
- autorag/vectordb/pinecone.py +121 -0
- autorag/vectordb/qdrant.py +155 -0
- autorag/vectordb/weaviate.py +184 -0
- autorag/web.py +81 -0
- autorag-0.0.0.dist-info/METADATA +780 -0
- autorag-0.0.0.dist-info/RECORD +184 -0
- autorag-0.0.0.dist-info/WHEEL +5 -0
- autorag-0.0.0.dist-info/entry_points.txt +2 -0
- autorag-0.0.0.dist-info/licenses/LICENSE +201 -0
- autorag-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from autorag.schema.metricinput import MetricInput
|
|
7
|
+
from autorag.utils.util import convert_inputs_to_list
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def calculate_cosine_similarity(a, b):
|
|
11
|
+
dot_product = np.dot(a, b)
|
|
12
|
+
norm_a = np.linalg.norm(a)
|
|
13
|
+
norm_b = np.linalg.norm(b)
|
|
14
|
+
similarity = dot_product / (norm_a * norm_b)
|
|
15
|
+
return similarity
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def calculate_l2_distance(a, b):
|
|
19
|
+
return np.linalg.norm(a - b)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def calculate_inner_product(a, b):
|
|
23
|
+
return np.dot(a, b)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def autorag_metric(fields_to_check: List[str]):
|
|
27
|
+
def decorator_autorag_metric(func):
|
|
28
|
+
@functools.wraps(func)
|
|
29
|
+
@convert_inputs_to_list
|
|
30
|
+
def wrapper(metric_inputs: List[MetricInput], **kwargs) -> List[float]:
|
|
31
|
+
"""
|
|
32
|
+
Use 'for loop' to run each metric input.
|
|
33
|
+
Put the single metric input into the metric function.
|
|
34
|
+
|
|
35
|
+
:param metric_inputs: A list MetricInput schema for AutoRAG metric.
|
|
36
|
+
:param kwargs: The additional arguments for metric function.
|
|
37
|
+
:return: A list of computed metric scores.
|
|
38
|
+
"""
|
|
39
|
+
results = []
|
|
40
|
+
for metric_input in metric_inputs:
|
|
41
|
+
if metric_input.is_fields_notnone(fields_to_check=fields_to_check):
|
|
42
|
+
results.append(func(metric_input, **kwargs))
|
|
43
|
+
else:
|
|
44
|
+
results.append(None)
|
|
45
|
+
return results
|
|
46
|
+
|
|
47
|
+
return wrapper
|
|
48
|
+
|
|
49
|
+
return decorator_autorag_metric
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def autorag_metric_loop(fields_to_check: List[str]):
|
|
53
|
+
def decorator_autorag_generation_metric(func):
|
|
54
|
+
@functools.wraps(func)
|
|
55
|
+
@convert_inputs_to_list
|
|
56
|
+
def wrapper(metric_inputs: List[MetricInput], **kwargs) -> List[float]:
|
|
57
|
+
"""
|
|
58
|
+
Put the list of metric inputs into the metric function.
|
|
59
|
+
|
|
60
|
+
:param metric_inputs: A list MetricInput schema for AutoRAG metric.
|
|
61
|
+
:param kwargs: The additional arguments for metric function.
|
|
62
|
+
:return: A list of computed metric scores.
|
|
63
|
+
"""
|
|
64
|
+
bool_list = [
|
|
65
|
+
metric_input.is_fields_notnone(fields_to_check=fields_to_check)
|
|
66
|
+
for metric_input in metric_inputs
|
|
67
|
+
]
|
|
68
|
+
valid_inputs = [
|
|
69
|
+
metric_input
|
|
70
|
+
for metric_input, is_valid in zip(metric_inputs, bool_list)
|
|
71
|
+
if is_valid
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
results = [None] * len(metric_inputs)
|
|
75
|
+
if valid_inputs:
|
|
76
|
+
processed_valid = func(valid_inputs, **kwargs)
|
|
77
|
+
|
|
78
|
+
valid_index = 0
|
|
79
|
+
for i, is_valid in enumerate(bool_list):
|
|
80
|
+
if is_valid:
|
|
81
|
+
results[i] = processed_valid[valid_index]
|
|
82
|
+
valid_index += 1
|
|
83
|
+
|
|
84
|
+
return results
|
|
85
|
+
|
|
86
|
+
return wrapper
|
|
87
|
+
|
|
88
|
+
return decorator_autorag_generation_metric
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import warnings
|
|
3
|
+
from typing import List, Callable, Any, Tuple, Union, Dict
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from autorag.evaluation.metric import (
|
|
8
|
+
retrieval_recall,
|
|
9
|
+
retrieval_precision,
|
|
10
|
+
retrieval_f1,
|
|
11
|
+
retrieval_ndcg,
|
|
12
|
+
retrieval_mrr,
|
|
13
|
+
retrieval_map,
|
|
14
|
+
)
|
|
15
|
+
from autorag.evaluation.util import cast_metrics
|
|
16
|
+
from autorag.schema.metricinput import MetricInput
|
|
17
|
+
|
|
18
|
+
RETRIEVAL_METRIC_FUNC_DICT = {
|
|
19
|
+
func.__name__: func
|
|
20
|
+
for func in [
|
|
21
|
+
retrieval_recall,
|
|
22
|
+
retrieval_precision,
|
|
23
|
+
retrieval_f1,
|
|
24
|
+
retrieval_ndcg,
|
|
25
|
+
retrieval_mrr,
|
|
26
|
+
retrieval_map,
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def evaluate_retrieval(
|
|
32
|
+
metric_inputs: List[MetricInput],
|
|
33
|
+
metrics: Union[List[str], List[Dict]],
|
|
34
|
+
):
|
|
35
|
+
def decorator_evaluate_retrieval(
|
|
36
|
+
func: Callable[
|
|
37
|
+
[Any], Tuple[List[List[str]], List[List[str]], List[List[float]]]
|
|
38
|
+
],
|
|
39
|
+
):
|
|
40
|
+
"""
|
|
41
|
+
Decorator for evaluating retrieval results.
|
|
42
|
+
You can use this decorator to any method that returns (contents, scores, ids),
|
|
43
|
+
which is the output of conventional retrieval modules.
|
|
44
|
+
|
|
45
|
+
:param func: Must return (contents, scores, ids)
|
|
46
|
+
:return: wrapper function that returns pd.DataFrame, which is the evaluation result.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
@functools.wraps(func)
|
|
50
|
+
def wrapper(*args, **kwargs) -> pd.DataFrame:
|
|
51
|
+
contents, pred_ids, scores = func(*args, **kwargs)
|
|
52
|
+
for metric_input, pred_id in zip(metric_inputs, pred_ids):
|
|
53
|
+
metric_input.retrieved_ids = pred_id
|
|
54
|
+
|
|
55
|
+
metric_scores = {}
|
|
56
|
+
metric_names, metric_params = cast_metrics(metrics)
|
|
57
|
+
|
|
58
|
+
for metric_name, metric_param in zip(metric_names, metric_params):
|
|
59
|
+
if metric_name in RETRIEVAL_METRIC_FUNC_DICT:
|
|
60
|
+
metric_func = RETRIEVAL_METRIC_FUNC_DICT[metric_name]
|
|
61
|
+
metric_scores[metric_name] = metric_func(
|
|
62
|
+
metric_inputs=metric_inputs, **metric_param
|
|
63
|
+
)
|
|
64
|
+
else:
|
|
65
|
+
warnings.warn(
|
|
66
|
+
f"metric {metric_name} is not in supported metrics: {RETRIEVAL_METRIC_FUNC_DICT.keys()}"
|
|
67
|
+
f"{metric_name} will be ignored."
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
metric_result_df = pd.DataFrame(metric_scores)
|
|
71
|
+
execution_result_df = pd.DataFrame(
|
|
72
|
+
{
|
|
73
|
+
"retrieved_contents": contents,
|
|
74
|
+
"retrieved_ids": pred_ids,
|
|
75
|
+
"retrieve_scores": scores,
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
result_df = pd.concat([execution_result_df, metric_result_df], axis=1)
|
|
79
|
+
return result_df
|
|
80
|
+
|
|
81
|
+
return wrapper
|
|
82
|
+
|
|
83
|
+
return decorator_evaluate_retrieval
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
from typing import List, Callable, Any, Tuple
|
|
3
|
+
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
from autorag.evaluation.metric import (
|
|
7
|
+
retrieval_token_f1,
|
|
8
|
+
retrieval_token_precision,
|
|
9
|
+
retrieval_token_recall,
|
|
10
|
+
)
|
|
11
|
+
from autorag.schema.metricinput import MetricInput
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def evaluate_retrieval_contents(metric_inputs: List[MetricInput], metrics: List[str]):
|
|
15
|
+
def decorator_evaluate_retrieval_contents(
|
|
16
|
+
func: Callable[
|
|
17
|
+
[Any], Tuple[List[List[str]], List[List[str]], List[List[float]]]
|
|
18
|
+
],
|
|
19
|
+
):
|
|
20
|
+
"""
|
|
21
|
+
Decorator for evaluating retrieval contents.
|
|
22
|
+
You can use this decorator to any method that returns (contents, scores, ids),
|
|
23
|
+
which is the output of conventional retrieval modules.
|
|
24
|
+
|
|
25
|
+
:param func: Must return (contents, scores, ids)
|
|
26
|
+
:return: pd.DataFrame, which is the evaluation result and function result.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
@functools.wraps(func)
|
|
30
|
+
def wrapper(*args, **kwargs) -> pd.DataFrame:
|
|
31
|
+
contents, pred_ids, scores = func(*args, **kwargs)
|
|
32
|
+
metric_funcs = {
|
|
33
|
+
retrieval_token_recall.__name__: retrieval_token_recall,
|
|
34
|
+
retrieval_token_precision.__name__: retrieval_token_precision,
|
|
35
|
+
retrieval_token_f1.__name__: retrieval_token_f1,
|
|
36
|
+
}
|
|
37
|
+
for metric_input, content in zip(metric_inputs, contents):
|
|
38
|
+
metric_input.retrieved_contents = content
|
|
39
|
+
|
|
40
|
+
metrics_scores = {}
|
|
41
|
+
for metric in metrics:
|
|
42
|
+
if metric not in metric_funcs:
|
|
43
|
+
raise ValueError(
|
|
44
|
+
f"metric {metric} is not in supported metrics: {metric_funcs.keys()}"
|
|
45
|
+
)
|
|
46
|
+
else:
|
|
47
|
+
metric_func = metric_funcs[metric]
|
|
48
|
+
# Extract each required field from all payloads
|
|
49
|
+
metric_scores = metric_func(metric_inputs=metric_inputs)
|
|
50
|
+
metrics_scores[metric] = metric_scores
|
|
51
|
+
|
|
52
|
+
metric_result_df = pd.DataFrame(metrics_scores)
|
|
53
|
+
execution_result_df = pd.DataFrame(
|
|
54
|
+
{
|
|
55
|
+
"retrieved_contents": contents,
|
|
56
|
+
"retrieved_ids": pred_ids,
|
|
57
|
+
"retrieve_scores": scores,
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
result_df = pd.concat([execution_result_df, metric_result_df], axis=1)
|
|
61
|
+
return result_df
|
|
62
|
+
|
|
63
|
+
return wrapper
|
|
64
|
+
|
|
65
|
+
return decorator_evaluate_retrieval_contents
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
from typing import Union, List, Dict, Tuple, Any
|
|
3
|
+
|
|
4
|
+
from autorag.embedding.base import EmbeddingModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def cast_metrics(
|
|
8
|
+
metrics: Union[List[str], List[Dict]],
|
|
9
|
+
) -> Tuple[List[str], List[Dict[str, Any]]]:
|
|
10
|
+
"""
|
|
11
|
+
Turn metrics to list of metric names and parameter list.
|
|
12
|
+
|
|
13
|
+
:param metrics: List of string or dictionary.
|
|
14
|
+
:return: The list of metric names and dictionary list of metric parameters.
|
|
15
|
+
"""
|
|
16
|
+
metrics_copy = deepcopy(metrics)
|
|
17
|
+
if not isinstance(metrics_copy, list):
|
|
18
|
+
raise ValueError("metrics must be a list of string or dictionary.")
|
|
19
|
+
if isinstance(metrics_copy[0], str):
|
|
20
|
+
return metrics_copy, [{} for _ in metrics_copy]
|
|
21
|
+
elif isinstance(metrics_copy[0], dict):
|
|
22
|
+
# pop 'metric_name' key from dictionary
|
|
23
|
+
metric_names = list(map(lambda x: x.pop("metric_name"), metrics_copy))
|
|
24
|
+
metric_params = [
|
|
25
|
+
dict(
|
|
26
|
+
map(
|
|
27
|
+
lambda x, y: cast_embedding_model(x, y),
|
|
28
|
+
metric.keys(),
|
|
29
|
+
metric.values(),
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
for metric in metrics_copy
|
|
33
|
+
]
|
|
34
|
+
return metric_names, metric_params
|
|
35
|
+
else:
|
|
36
|
+
raise ValueError("metrics must be a list of string or dictionary.")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def cast_embedding_model(key, value):
|
|
40
|
+
if key == "embedding_model":
|
|
41
|
+
return key, EmbeddingModel.load(value)()
|
|
42
|
+
else:
|
|
43
|
+
return key, value
|