A Ruby library for retrieval-augmented generation, unified LLM APIs, prompt templates, and tool-using assistants.
Overview
Langchain.rb helps Ruby developers build LLM-powered features inside their applications. It focuses on practical patterns such as retrieval augmented generation, chat assistants, and structured outputs rather than shipping a standalone service.
The Langchain::LLM namespace offers a shared interface across providers including Anthropic, OpenAI, Google Gemini and Vertex AI, AWS Bedrock, Azure OpenAI, Cohere, Mistral, Ollama, HuggingFace, and Replicate, with embed, complete, and chat operations and consistent response objects. Prompt templates, few-shot templates, and output parsers turn model text into JSON or fixed schemas, with helpers to repair invalid JSON.
RAG workflows connect to multiple vector search backends through one interface, supporting indexing plain text or parsed files in formats such as PDF, HTML, DOCX, and CSV. The Langchain::Assistant class combines an LLM with built-in or custom tools, conversation state, and optional callbacks for tool execution.
Evaluation helpers include RAGAS-style faithfulness and relevance metrics. A separate langchainrb_rails gem is noted for deeper Rails integration. The core package is installed as a Ruby gem and imported from application code.
Key features
- Unified LLM provider interface
- Prompt and few-shot templates
- Structured output parsers
- Vector search database adapters
- RAG indexing and retrieval
- Assistant with tool calling
- Built-in tools such as calculator and search
- RAGAS evaluation metrics
Use cases
- RAG question answering in Ruby apps
- Chat assistants with tools
- Switching between LLM vendors
- Parsing LLM output to JSON