Arcana - Embeddable RAG library for Elixir/Phoenix

I’m excited to share Arcana, a RAG (Retrieval Augmented Generation) library I’ve been building for Elixir/Phoenix applications.

What is it?

Arcana lets you add vector search, document retrieval, and AI-powered Q&A to any Phoenix app. It’s designed to be embeddable - it uses your existing Ecto Repo and PostgreSQL with pgvector, no separate vector database needed.

Key Features

Simple API for basic RAG:

  {:ok, doc} = Arcana.ingest("Your content", repo: MyApp.Repo)
  results = Arcana.search("query", repo: MyApp.Repo, mode: :hybrid)
  {:ok, answer} = Arcana.ask("What is Elixir?", repo: MyApp.Repo, llm: "openai:gpt-4o")

Agentic RAG Pipeline for complex questions:

  ctx =
    Agent.new("Compare Elixir and Erlang")
    |> Agent.select(collections: ["elixir-docs", "erlang-docs"])
    |> Agent.expand()
    |> Agent.decompose()
    |> Agent.search()
    |> Agent.rerank(threshold: 7)
    |> Agent.answer(self_correct: true)

The pipeline includes query rewriting, collection routing, query expansion, question decomposition, re-ranking, and self-correcting answers (reduces hallucinations by verifying answers are grounded in context).

Embeddings with Nx/Bumblebee:

  • Local embeddings with bge-small-en-v1.5 - no API keys needed
  • Or use OpenAI embeddings
  • Or bring your own via the Arcana.Embedder behaviour

Pluggable Everything:

Every pipeline step has a behaviour you can implement:

defmodule MyApp.CrossEncoderReranker do
    @behaviour Arcana.Agent.Reranker

    @impl true
    def rerank(question, chunks, opts) do
      # Your cross-encoder logic
      {:ok, scored_chunks}
    end
  end

Other highlights:

  • Hybrid search (vector + fulltext with Reciprocal Rank Fusion)
  • In-memory HNSWLib backend for testing or smaller apps
  • Built-in telemetry for all operations
  • Evaluation metrics (MRR, Recall@k, Precision@k)
  • Optional LiveView dashboard
  • File ingestion (text, markdown, PDF)

Links

GitHub: GitHub - georgeguimaraes/arcana: Embeddable RAG library for Elixir/Phoenix with agentic pipelines and dashboard
Hex: arcana | Hex
Demo app with Doctor Who corpus: GitHub - georgeguimaraes/arcana-adept: Example Phoenix app demonstrating Arcana RAG toolkit

Would love feedback from the community!

14 Likes

Dashboard example here:

8 Likes