Retriever behaviour and dispatch boundary for RAG-style Imp programs.
A retriever is a struct whose module implements this behaviour, such a
module itself, or a two-argument function (query, opts). All retrievers
return {:ok, docs} or {:error, reason}. Documents are normalized to maps,
so keyword-list documents are accepted while malformed rows fail before they
reach a RAG program.
Summary
Callbacks
Returns the documents for query. retriever is the struct or the module
as it was given.
Functions
Calls a retriever and normalizes returned documents.
Types
Callbacks
Functions
Calls a retriever and normalizes returned documents.
iex> retriever = fn query, opts ->
...> {:ok, [[text: "query=" <> query, k: opts[:k]]]}
...> end
iex> Imp.Retrieve.retrieve(retriever, "beam", k: 1)
{:ok, [%{text: "query=beam", k: 1}]}
iex> Imp.Retrieve.retrieve(fn _query, _opts -> {:ok, [:bad_doc]} end, "beam")
{:error, {:invalid_retriever_document, :bad_doc}}