Setup
Addreq_llm to your dependencies:
mix.exs
config/runtime.exs
Basic RAG with Arcana.ask/2
Pass a model string directly toArcana.ask/2:
provider:model-name. Req.LLM supports 45+ providers including OpenAI, Anthropic, Google, Groq, and OpenRouter.
Custom Prompts
Use the:prompt option for custom system prompts:
Custom RAG Module
Wrap Arcana in a module for cleaner usage:lib/my_app/rag.ex
Streaming Responses
For real-time streaming in LiveView, use Req.LLM’s streaming directly:lib/my_app_web/live/chat_live.ex
Agentic RAG
For complex questions, use the Agent pipeline:Cost Tracking
Req.LLM includes built-in cost tracking via telemetry:lib/my_app/llm_logger.ex
MyApp.LLMLogger.setup() in your application startup.
Tips
Use hybrid search
Use hybrid search
Combines semantic understanding with keyword matching for better results:
Set appropriate limits
Set appropriate limits
More context isn’t always better - it increases cost and noise:
Use streaming for chat interfaces
Use streaming for chat interfaces
Better UX for long responses:
Monitor costs
Monitor costs
Attach telemetry handlers to track LLM spending:
Consider caching
Consider caching
LLM calls are expensive - cache common queries:
Next Steps
Agentic RAG
Build sophisticated multi-step RAG pipelines
Telemetry
Monitor LLM performance and costs
Evaluation
Measure answer quality and faithfulness
Dashboard
Test questions and view results in the web UI