Arcana.Agent.Reranker behaviour (Arcana v1.3.3)
View SourceBehaviour for re-ranking search results.
Re-rankers improve retrieval quality by scoring chunks based on their relevance to the question, then filtering and re-sorting by score.
Built-in Implementations
Arcana.Agent.Reranker.LLM- Uses your LLM to score relevance (default)
Custom Implementations
Implement the rerank/3 callback:
defmodule MyApp.CrossEncoderReranker do
@behaviour Arcana.Agent.Reranker
@impl Arcana.Agent.Reranker
def rerank(question, chunks, opts) do
# Your custom logic
{:ok, scored_and_filtered_chunks}
end
endOr provide a function directly:
Agent.rerank(ctx, reranker: fn question, chunks, opts ->
{:ok, my_rerank(question, chunks)}
end)
Summary
Callbacks
Re-ranks chunks based on relevance to the question.
Callbacks
@callback rerank( question :: String.t(), chunks :: [map()], opts :: keyword() ) :: {:ok, [map()]} | {:error, term()}
Re-ranks chunks based on relevance to the question.
Returns chunks filtered by threshold and sorted by score (highest first).
Options
:threshold- Minimum score to keep (default: 7, range 0-10):llm- LLM function for scoring (required for LLM reranker):prompt- Custom prompt functionfn question, chunk_text -> prompt end