LangChain LCEL and Retrieval Cheat Sheet
This quick reference guide summarizes LCEL operators and RAG components.
1. LCEL Composition Syntax Reference
- Pipe Operator Method:
.pipe(nextComponent)connects steps in sequence. RunnablePassthrough: Passes input values through unmodified to subsequent steps.RunnableMap/ Plain Object: Invokes sub-steps in parallel, returning a unified dictionary object.
2. Document Processing Classes Reference
| Category | Target Class | Usage Example |
| Loader | TextLoader | new TextLoader("./file.txt") |
| Loader | CSVLoader | new CSVLoader("./data.csv", { column: "desc" }) |
| Splitter | RecursiveCharacterTextSplitter | new RecursiveCharacterTextSplitter({ chunkSize: 1000 }) |
| Vector DB | MemoryVectorStore | MemoryVectorStore.fromDocuments(chunks, embeddings) |
| Retriever | VectorStore.asRetriever | store.asRetriever({ k: 2 }) |
3. Basic LCEL Chain Invocation Template
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
const chain = ChatPromptTemplate.fromTemplate("Tell a joke about {topic}")
.pipe(new ChatOpenAI({ modelName: "gpt-4o-mini" }))
.pipe(new StringOutputParser());
const reply = await chain.invoke({ topic: "coding" });Published on Last updated: