Skip to main content
All integrationsAI Framework

LangChain Integration

Use LangChain RAG chains as an optional layer in the kit.

FastAPI AI Kit includes optional LangChain integration for teams that prefer its abstractions. Use it for complex chains, agents, or document loaders — the core LLM and RAG layers work without it.

Setup in 4 steps

  1. 1LangChain is an optional dependency — install with pip install langchain
  2. 2Use LangChain's document loaders as alternatives to the kit's ingestion pipeline
  3. 3Wire LangChain chains into the kit's existing API endpoints
  4. 4LangChain and native RAG pipelines can co-exist

What's included

  • Optional LangChain import — zero overhead if not used
  • Kit's LLM abstraction wraps LangChain providers for portability
  • LangChain document loaders work with the RAG ingestion API
  • Custom chain results stored in kit's Postgres via standard models
  • LangSmith tracing compatible via standard env vars

Code example

example.py
# Optional LangChain integration
from langchain_openai import ChatOpenAI
from langchain.chains import ConversationalRetrievalChain
from app.rag import get_vector_store  # Kit's vector store

# Wrap kit's pgvector store in LangChain retriever
retriever = get_vector_store().as_retriever(search_kwargs={"k": 5})
chain = ConversationalRetrievalChain.from_llm(
    llm=ChatOpenAI(model="gpt-4o"),
    retriever=retriever,
)

Full documentation: /docs/llm-providers

LangChain integration pre-wired and ready.

FastAPI AI Kit ships with LangChain configured out of the box. No manual setup required.

Ready to ship your AI backend this weekend?

Join developers who skipped weeks of boilerplate and went straight to building.

Read the docs
No subscriptions · One-time payment · Lifetime updates