patterns-ai-core/langchainrb

Build LLM-powered applications in Ruby

What it solves

Langchain.rb is a Ruby gem that simplifies the process of building LLM-powered applications. It provides a unified interface for interacting with multiple LLM providers, managing prompts, and implementing Retrieval Augmented Generation (RAG) and AI assistants.

How it works

The library abstracts the complexities of different LLM APIs into a consistent set of methods for generating embeddings, prompt completions, and chat completions. It includes tools for prompt templating (including few-shot examples), structured output parsing (converting LLM text into JSON), and a unified interface for various vector search databases to facilitate RAG workflows. It also features an Assistant class that manages conversation threads and integrates with external tools for interactive AI agents.

Who it’s for

Ruby and Rails developers who want to integrate Large Language Models into their applications without being tied to a single provider or having to write boilerplate code for each API.

Highlights

  • Unified LLM Interface: Supports a wide range of providers including OpenAI, Anthropic, Google Gemini, Mistral AI, and Ollama.
  • RAG Support: Integrated support for vector databases like Chroma, Pinecone, Pgvector, and Weaviate, including built-in file parsers for multiple formats (PDF, DOCX, etc.).
  • Prompt Management: Tools for creating, saving, and loading prompt templates and few-shot examples.
  • Structured Output: Parsers that can force LLM responses into specific JSON schemas, with an OutputFixingParser to correct errors.
  • AI Assistants: A high-level class for building chat bots that can execute tools and maintain conversation history.