View Source Rag.Retrieval (rag v0.2.1)
Functions to retrieve data and transform retrieval results.
Summary
Functions
Gets the retrieval result for each key in retrieval_result_keys
from generation.retrieval_results
.
Then, concatenates all results into a list at output_key
.
Deduplicates entries at entries_keys
in generation.retrieval_results
.
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_and_weights
from generation.retrieval_results
.
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 either {:ok, retrieval_result} or {:error, error}.
Types
@type retrieval_function() :: (Rag.Generation.t() -> {:ok, result :: any()} | {:error, error :: any()})
Functions
@spec concatenate_retrieval_results(Rag.Generation.t(), [atom()], atom()) :: map()
Gets the retrieval result for each key in retrieval_result_keys
from generation.retrieval_results
.
Then, concatenates all results into a list at output_key
.
@spec deduplicate(Rag.Generation.t(), atom(), [atom()]) :: Rag.Generation.t()
Deduplicates entries at entries_keys
in generation.retrieval_results
.
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.
@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_and_weights
from generation.retrieval_results
.
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 sameidentity
will be fused.
@spec retrieve( Rag.Generation.t(), result_key :: atom(), retrieval_function() ) :: Rag.Generation.t()
Calls retrieval_function
with generation
as only argument.
retrieval_function
must return either {:ok, retrieval_result} or {:error, error}.