Rag.Ai.Capabilities (rag v0.3.4)

View Source

Provider capability registry and selection helpers.

This module maintains metadata about all available LLM providers, their capabilities, costs, and strengths. It helps in:

  • Auto-detecting available providers
  • Selecting the best provider for a task
  • Understanding provider limitations

Examples

# Get capabilities for a specific provider
caps = Capabilities.get(:gemini)
caps.embeddings  # => true
caps.max_context # => 1_000_000

# Find providers with specific capability
providers = Capabilities.with_capability(:embeddings)
# => [{:gemini, %{...}}]

# Find best provider for a task
Capabilities.best_for(:code_generation)
# => :codex

Summary

Functions

Get all provider capabilities.

Get list of available providers (those with loaded modules and credentials).

Find the best provider for a specific task type.

Check if a provider is available and has the required capability.

Check if a provider module is available (loaded and functional).

Get the default provider (first available).

Get capabilities for a specific provider.

Filter providers by a specific capability.

Functions

all()

@spec all() :: map()

Get all provider capabilities.

Examples

iex> all = Capabilities.all()
iex> Map.keys(all)
[:gemini, :codex, :claude]

available()

@spec available() :: [{atom(), map()}]

Get list of available providers (those with loaded modules and credentials).

Only returns providers that are actually usable in the current environment.

Examples

iex> Capabilities.available()
[{:gemini, %{...}}, {:codex, %{...}}]

best_for(task)

@spec best_for(atom()) :: atom()

Find the best provider for a specific task type.

Returns the provider key (:gemini, :codex, or :claude) that is best suited for the given task.

Task Types

  • :embeddings - Embedding generation
  • :code_generation - Writing new code
  • :code_review - Reviewing existing code
  • :analysis - Deep analysis and reasoning
  • :writing - Content creation
  • :long_context - Tasks requiring large context windows
  • :structured_output - JSON/structured data generation
  • :agentic - Multi-step agentic workflows
  • :reasoning - Complex reasoning tasks

Examples

iex> Capabilities.best_for(:embeddings)
:gemini

iex> Capabilities.best_for(:code_generation)
:codex

iex> Capabilities.best_for(:analysis)
:claude

can_handle?(provider, capability)

@spec can_handle?(atom(), atom()) :: boolean()

Check if a provider is available and has the required capability.

Examples

iex> Capabilities.can_handle?(:gemini, :embeddings)
true

iex> Capabilities.can_handle?(:codex, :embeddings)
false

check_available(module)

@spec check_available(module()) :: boolean()

Check if a provider module is available (loaded and functional).

Examples

iex> Capabilities.check_available(Rag.Ai.Gemini)
true

iex> Capabilities.check_available(NonExistent.Module)
false

default_provider()

@spec default_provider() :: atom()

Get the default provider (first available).

Prefers Gemini > Codex > Claude based on cost and versatility.

Examples

iex> Capabilities.default_provider()
:gemini

get(provider)

@spec get(atom()) :: map() | nil

Get capabilities for a specific provider.

Returns nil if the provider is not known.

Examples

iex> Capabilities.get(:gemini)
%{module: Rag.Ai.Gemini, embeddings: true, ...}

iex> Capabilities.get(:unknown)
nil

with_capability(capability)

@spec with_capability(atom()) :: [{atom(), map()}]

Filter providers by a specific capability.

Examples

iex> Capabilities.with_capability(:embeddings)
[{:gemini, %{...}}]

iex> Capabilities.with_capability(:tools)
[{:gemini, %{...}}, {:codex, %{...}}, {:claude, %{...}}]