Arcana.Config (Arcana v1.3.3)

View Source

Configuration management for Arcana.

Handles parsing and resolving configuration for embedders, chunkers, and other pluggable components.

Redacting Sensitive Values

Use Arcana.Config.redact/1 to wrap any config value for safe inspection:

config = Application.get_env(:arcana, :llm)
inspect(Arcana.Config.redact(config))
# => {"zai:glm-4.7", [api_key: "[REDACTED]"]}

Embedder Configuration

# Default: Local Bumblebee with bge-small-en-v1.5
config :arcana, embedder: :local

# Local with different model
config :arcana, embedder: {:local, model: "BAAI/bge-large-en-v1.5"}

# OpenAI (requires req_llm and OPENAI_API_KEY)
config :arcana, embedder: :openai
config :arcana, embedder: {:openai, model: "text-embedding-3-large"}

# Custom function
config :arcana, embedder: fn text -> {:ok, embedding} end

# Custom module implementing Arcana.Embedder behaviour
config :arcana, embedder: MyApp.CohereEmbedder
config :arcana, embedder: {MyApp.CohereEmbedder, api_key: "..."}

Chunker Configuration

# Default: text_chunker-based chunking
config :arcana, chunker: :default

# Default chunker with custom options
config :arcana, chunker: {:default, chunk_size: 512, chunk_overlap: 100}

# Custom function (receives text, opts; returns list of chunk maps)
config :arcana, chunker: fn text, _opts ->
  [%{text: text, chunk_index: 0, token_count: 10}]
end

# Custom module implementing Arcana.Chunker behaviour
config :arcana, chunker: MyApp.SemanticChunker
config :arcana, chunker: {MyApp.SemanticChunker, model: "..."}

PDF Parser Configuration

# Default: poppler's pdftotext
config :arcana, pdf_parser: :poppler

# Custom module implementing Arcana.FileParser.PDF behaviour
config :arcana, pdf_parser: MyApp.PDFParser
config :arcana, pdf_parser: {MyApp.PDFParser, some_option: "value"}

Summary

Functions

Returns the configured chunker as a {module, opts} tuple.

Returns the current Arcana configuration.

Returns the configured embedder as a {module, opts} tuple.

Returns whether GraphRAG is enabled globally or for specific options.

Returns the configured PDF parser as a {module, opts} tuple.

Wraps a config value for safe inspection with sensitive data redacted.

Resolves chunker from options, falling back to global config.

Functions

chunker()

Returns the configured chunker as a {module, opts} tuple.

current()

Returns the current Arcana configuration.

Useful for logging, debugging, and storing with evaluation runs to track which settings produced which results.

Example

Arcana.Config.current()
# => %{
#   embedding: %{module: Arcana.Embedder.Local, model: "BAAI/bge-small-en-v1.5", dimensions: 384},
#   vector_store: :pgvector
# }

embedder()

Returns the configured embedder as a {module, opts} tuple.

graph_enabled?(opts)

Returns whether GraphRAG is enabled globally or for specific options.

Checks the :graph option in the provided opts first, then falls back to the global configuration.

Examples

# Check global config
Arcana.Config.graph_enabled?([])

# Override with per-call option
Arcana.Config.graph_enabled?(graph: true)

pdf_parser()

Returns the configured PDF parser as a {module, opts} tuple.

redact(value)

Wraps a config value for safe inspection with sensitive data redacted.

Returns a struct that implements the Inspect protocol and automatically redacts sensitive keys like :api_key, :token, :password, etc.

Example

iex> config = {"zai:glm-4.7", [api_key: "secret123"]}
iex> inspect(Arcana.Config.redact(config))
~s|{"zai:glm-4.7", [api_key: "[REDACTED]"]}|

resolve_chunker(opts)

Resolves chunker from options, falling back to global config.