View Source Rag.Retrieval (rag v0.1.0)

Functions to transform retrieval results.

Summary

Functions

Gets the retrieval result for each key in retrieval_result_keys from generation. Then, appends the retrieval result to the list at output_key.

Deduplicates entries at entries_keys in retrieval_results of generation. Two entries are considered duplicates if they hold the same value at all unique_by_keys. In case of duplicates, the first entry is kept.

Gets the retrieval result for each key in retrieval_result_keys from retrieval. Then, applies Reciprocal Rank Fusion to combine the retrieval results into a single list at output_key. There is no guaranteed order for results with the same score.

Calls retrieval_function with generation as only argument. retrieval_function must return only the retrieval result. The main purpose of retrieve/3 is to emit telemetry events.

Functions

concatenate_retrieval_results(generation, retrieval_result_keys, output_key)

@spec concatenate_retrieval_results(map(), [atom()], atom()) :: map()

Gets the retrieval result for each key in retrieval_result_keys from generation. Then, appends the retrieval result to the list at output_key.

deduplicate(generation, entries_key, unique_by_keys)

@spec deduplicate(Rag.Generation.t(), atom(), [atom()]) :: Rag.Generation.t()

Deduplicates entries at entries_keys in retrieval_results of generation. Two entries are considered duplicates if they hold the same value at all unique_by_keys. In case of duplicates, the first entry is kept.

reciprocal_rank_fusion(generation, retrieval_result_keys_and_weights, output_key, opts \\ [])

@spec reciprocal_rank_fusion(
  Rag.Generation.t(),
  %{required(key :: atom()) => weight :: integer()},
  output_key :: atom(),
  keyword([atom()])
) :: Rag.Generation.t()

Gets the retrieval result for each key in retrieval_result_keys from retrieval. Then, applies Reciprocal Rank Fusion to combine the retrieval results into a single list at output_key. There is no guaranteed order for results with the same score.

Options:

  • identity: list of keys which define the identity of a result. Results with same identity will be fused.

retrieve(generation, result_key, retrieval_function)

@spec retrieve(
  Rag.Generation.t(),
  result_key :: atom(),
  (Rag.Generation.t() -> any())
) :: Rag.Generation.t()

Calls retrieval_function with generation as only argument. retrieval_function must return only the retrieval result. The main purpose of retrieve/3 is to emit telemetry events.