autorag package

Subpackages

Submodules

autorag.chunker module

class autorag.chunker.Chunker(raw_df: DataFrame, project_dir: str | None = None)[source]

Bases: object

classmethod from_parquet(parsed_data_path: str, project_dir: str | None = None) Chunker[source]
start_chunking(yaml_path: str)[source]

autorag.cli module

autorag.dashboard module

autorag.dashboard.find_node_dir(trial_dir: str) List[str][source]
autorag.dashboard.get_metric_values(node_summary_df: DataFrame) Dict[source]
autorag.dashboard.make_trial_summary_md(trial_dir)[source]
autorag.dashboard.node_view(node_dir: str)[source]
autorag.dashboard.run(trial_dir: str, port: int = 7690)[source]
autorag.dashboard.yaml_to_markdown(yaml_filepath)[source]

autorag.evaluator module

class autorag.evaluator.Evaluator(qa_data_path: str, corpus_data_path: str, project_dir: str | None = None)[source]

Bases: object

restart_trial(trial_path: str)[source]
start_trial(yaml_path: str, skip_validation: bool = False, full_ingest: bool = True)[source]

Start AutoRAG trial. The trial means one experiment to optimize the RAG pipeline. It consists of ingesting corpus data, running all nodes and modules, evaluating and finding the optimal modules.

Parameters:
  • yaml_path – The config YAML path

  • skip_validation – If True, it skips the validation step. The validation step checks the input config YAML file is well formatted, and there is any problem with the system settings. Default is False.

  • full_ingest – If True, it checks the whole corpus data from corpus.parquet that exists in the Vector DB. If your corpus is huge and don’t want to check the whole vector DB, please set it to False.

Returns:

None

autorag.node_line module

autorag.node_line.make_node_lines(node_line_dict: Dict) List[Node][source]

This method makes a list of nodes from node line dictionary. :param node_line_dict: Node_line_dict loaded from yaml file, or get from user input. :return: List of Nodes inside this node line.

autorag.node_line.run_node_line(nodes: List[Node], node_line_dir: str, previous_result: DataFrame | None = None)[source]

Run the whole node line by running each node.

Parameters:
  • nodes – A list of nodes.

  • node_line_dir – This node line’s directory.

  • previous_result – A result of the previous node line. If None, it loads qa data from data/qa.parquet.

Returns:

The final result of the node line.

autorag.parser module

class autorag.parser.Parser(data_path_glob: str, project_dir: str | None = None)[source]

Bases: object

start_parsing(yaml_path: str, all_files: bool = False)[source]

autorag.strategy module

autorag.strategy.avoid_empty_result(return_index: List[int])[source]

Decorator for avoiding empty results from the function. When the func returns an empty result, it will return the origin results. When the func returns a None, it will return the origin results. When the return value is a tuple, it will check all the value or list is empty. If so, it will return the origin results. It keeps parameters at return_index of the function as the origin results.

Parameters:

return_index – The index of the result to be returned when there is no result.

Returns:

The origin results or the results from the function.

autorag.strategy.filter_by_threshold(results, value, threshold, metadatas=None) Tuple[List, List][source]

Filter results by value’s threshold.

Parameters:
  • results – The result list to be filtered.

  • value – The value list to be filtered. It must have the same length with results.

  • threshold – The threshold value.

  • metadatas – The metadata of each result.

Returns:

Filtered list of results and filtered list of metadatas. Metadatas will be returned even if you did not give input metadatas.

Return type:

Tuple[List, List]

autorag.strategy.measure_speed(func, *args, **kwargs)[source]

Method for measuring execution speed of the function.

autorag.strategy.select_best(results: List[DataFrame], columns: Iterable[str], metadatas: List[Any] | None = None, strategy_name: str = 'mean') Tuple[DataFrame, Any][source]
autorag.strategy.select_best_average(results: List[DataFrame], columns: Iterable[str], metadatas: List[Any] | None = None) Tuple[DataFrame, Any][source]

Select the best result by average value among given columns.

Parameters:
  • results – The list of results. Each result must be pd.DataFrame.

  • columns – Column names to be averaged. Standard to select the best result.

  • metadatas – The metadata of each result. It will select one metadata with the best result.

Returns:

The best result and the best metadata. The metadata will be returned even if you did not give input ‘metadatas’ parameter.

Return type:

Tuple[pd.DataFrame, Any]

autorag.strategy.select_best_rr(results: List[DataFrame], columns: Iterable[str], metadatas: List[Any] | None = None) Tuple[DataFrame, Any][source]
autorag.strategy.select_normalize_mean(results: List[DataFrame], columns: Iterable[str], metadatas: List[Any] | None = None) Tuple[DataFrame, Any][source]
autorag.strategy.validate_strategy_inputs(results: List[DataFrame], columns: Iterable[str], metadatas: List[Any] | None = None)[source]

autorag.support module

autorag.support.dynamically_find_function(key: str, target_dict: Dict) Callable[source]
autorag.support.get_support_modules(module_name: str) Callable[source]
autorag.support.get_support_nodes(node_name: str) Callable[source]

autorag.validator module

class autorag.validator.Validator(qa_data_path: str, corpus_data_path: str)[source]

Bases: object

validate(yaml_path: str, qa_cnt: int = 5, random_state: int = 42)[source]

autorag.web module

autorag.web.chat_box(runner: Runner)[source]
autorag.web.get_runner(yaml_path: str | None, project_dir: str | None, trial_path: str | None)[source]
autorag.web.set_initial_state()[source]
autorag.web.set_page_config()[source]
autorag.web.set_page_header()[source]

Module contents

class autorag.AutoRAGBedrock(model: str, temperature: float | None = 0.1, max_tokens: int | None = 512, context_size: int | None = None, profile_name: str | None = None, aws_access_key_id: str | None = None, aws_secret_access_key: str | None = None, aws_session_token: str | None = None, region_name: str | None = None, botocore_session: Any | None = None, client: Any | None = None, timeout: float | None = 60.0, max_retries: int | None = 10, botocore_config: Any | None = None, additional_kwargs: Dict[str, Any] | None = None, callback_manager: CallbackManager | None = None, system_prompt: str | None = None, messages_to_prompt: Callable[[Sequence[ChatMessage]], str] | None = None, completion_to_prompt: Callable[[str], str] | None = None, pydantic_program_mode: PydanticProgramMode = PydanticProgramMode.DEFAULT, output_parser: BaseOutputParser | None = None, guardrail_identifier: str | None = None, guardrail_version: str | None = None, trace: str | None = None, provider_type: ProviderType | None = None, *, query_wrapper_prompt: BasePromptTemplate | None = None)[source]

Bases: Bedrock

async acomplete(prompt: str, formatted: bool = False, **kwargs: Any) CompletionResponse[source]

Async completion endpoint for LLM.

If the LLM is a chat model, the prompt is transformed into a single user message.

Args:
prompt (str):

Prompt to send to the LLM.

formatted (bool, optional):

Whether the prompt is already formatted for the LLM, by default False.

kwargs (Any):

Additional keyword arguments to pass to the LLM.

Returns:

CompletionResponse: Completion response from the LLM.

Examples:

`python response = await llm.acomplete("your prompt") print(response.text) `

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

class autorag.LazyInit(factory, *args, **kwargs)[source]

Bases: object

autorag.handle_exception(exc_type, exc_value, exc_traceback)[source]
autorag.random() x in the interval [0, 1).