LangChain Deepens Its Cloudflare Integrations

Cloudflare has expanded its collaboration with the LangChain team, adding five new integrations that connect LangChain.js applications to Cloudflare's developer platform. The additions cover chat models, instruct models, text embeddings, vector storage, and persistent chat memory, giving developers more options when building AI-powered applications on Workers.

LangChain is an open-source framework that lets developers compose AI workflows by plugging together models, providers, and other components through a declarative API. The new integrations bring several Cloudflare services into that ecosystem:

  • Workers AI Chat Models — Use workers-ai text generation to power chat models inside LangChain.js applications.
  • Workers AI Instruct Models — Access Workers AI models fine-tuned for instruction-following tasks, such as Mistral and CodeLlama, from LangChain.js.
  • Text Embeddings Models — Generate text embeddings via Workers AI and use them within LangChain.js workflows.
  • Vectorize Vector Store — Use Cloudflare's vector database, Vectorize, as the vector store backing a LangChain.js application.
  • D1-Backed Chat Memory — Replace LangChain's default in-memory chat history with a Cloudflare D1 database, enabling persistent conversations across sessions.

With these primitives, developers can string together embedding models, vector search, LLM generation, and durable storage — all running on Cloudflare's edge infrastructure — to assemble a full AI application with a modest amount of code.

The integrations are documented on the LangChain.js site with dedicated pages for each component. For example, the arrangement allows a chat application to store per-user or per-session conversation state in D1, then retrieve it to maintain context between requests. By passing a unique sessionId, the same codebase can serve independent conversations for different users.

Multi-Source RAG Template

To demonstrate how these pieces fit together, the two teams also published a reference application: LangChain's Cloudflare Chatbot template, available at github.com/langchain-ai/langchain-cloudflare-nuxt-template.

The template extends the idea of retrieval augmented generation (RAG) into a conversational retrieval system. Rather than querying a single database, the bot classifies incoming questions and routes them to the most relevant of two vector stores. This reduces the risk of a similarity search pulling in off-topic documents, a problem that can arise with a single, less selective index.

In its default configuration, the app runs entirely on Cloudflare's AI stack. It uses:

  • A chat-tuned variant of Llama 2-7B served by Workers AI
  • A Workers AI embeddings model
  • Two separate Vectorize databases, though more can be added
  • Cloudflare Pages for hosting
  • LangChain.js for orchestration
  • Nuxt and Vue for the frontend

The two bundled data sources are a Cloudflare security features PDF and a blog post on autonomous agents by Lilian Weng. Questions are classified as relating to Cloudflare, AI, or neither, and the matching data source is used to ground the response. The ingestion content, the models, and all prompts are intended to be swapped out for an application's own needs.

For developers who have access to the LangSmith beta, tracing is already configured in the template. Each step of the orchestration pipeline can be inspected and debugged through the LangSmith interface.

Example implementations and interactive demos have been shared on social media, including a persistent chat application built on Workers, LangChain, and D1 that keeps conversation history per session.