AI / LangGraph LangChain Interview questions II
1. What are the different memory types in LangChain?
LangChain provides several memory classes that differ in how they store and compress conversation history. Choosing the right one involves balancing context quality, token cost, and retrieval precision. Memory Type How It Works Best For ConversationBufferMemory Stores every message verbatim Short...
2. How do you implement conversation memory?
The recommended modern approach for conversation memory uses RunnableWithMessageHistory which wraps an LCEL chain and automatically loads and saves message history per session ID from a configurable store — without any manual history tracking in application code. from langchain_core.chat_history ...
3. How do vector stores work in LangChain?
A vector store in LangChain stores text (documents, chunks) as high-dimensional embedding vectors so you can perform semantic similarity search — finding documents whose meaning is close to a query, even if the exact words don't match. Every vector store integrates an embedding model and a storag...
4. How do you build RAG pipelines with LangChain?
A RAG (Retrieval-Augmented Generation) pipeline enriches LLM responses with external knowledge by retrieving relevant documents at query time and injecting them into the prompt. A complete LangChain RAG pipeline has five stages: Load — ingest source documents with a DocumentLoader Split — chunk d...
5. What are document loaders and splitters?
Document loaders ingest content from various sources and return a list of Document objects (each containing page_content and metadata ). Text splitters then divide those documents into smaller chunks suitable for embedding and retrieval. Common document loaders: PyPDFLoader — extracts text from P...
6. How do retrievers work in LangChain?
A Retriever in LangChain is a Runnable that takes a string query and returns a list of Document objects. It is the standard abstraction that decouples the RAG chain from the specific search mechanism — you can swap a vector store retriever for a keyword search retriever or a hybrid retriever with...
7. What is multi-query retrieval?
Multi-query retrieval addresses a key weakness of single-vector search: a user's question may be phrased in a way that doesn't closely match how the relevant information is worded in the document store. MultiQueryRetriever solves this by using an LLM to automatically generate several alternative ...
8. What are parent document retrieval patterns?
The parent document retrieval pattern addresses a fundamental tension in RAG systems: small chunks improve retrieval precision (the embedding closely matches the query), but large chunks provide richer context for the LLM to answer from. ParentDocumentRetriever resolves this by indexing small chi...
9. What are production deployment patterns for LangChain?
Moving a LangChain application from prototype to production requires addressing reliability, scalability, observability, and cost. The key patterns are: LangServe + Docker — wrap chains as FastAPI endpoints with add_routes() , containerise with Docker, deploy to a managed container service (AWS E...
10. How do you implement caching in LangChain?
LangChain supports LLM response caching at the global level, so any chain that calls an LLM automatically benefits from cache hits without modifying individual chains. The cache key is the serialised prompt plus model parameters — if the same prompt is sent twice, the second call returns the cach...
11. What are cost optimization techniques for LangChain?
LLM API costs are primarily driven by token usage. LangChain applications can apply several techniques at different layers to reduce costs without significantly degrading quality: Response caching — the single highest-impact technique for repetitive queries. InMemoryCache or RedisSemanticCache re...
12. What security best practices should you follow for LangChain applications?
LangChain applications interact with LLMs, external tools, and user-supplied data, creating several attack surfaces that require explicit mitigation: Prompt injection prevention — the most critical LLM-specific risk. Malicious users craft inputs that override system instructions (e.g. 'Ignore all...
13. How do you test LangChain applications?
Testing LangChain applications requires strategies for both unit testing individual components without real LLM calls, and end-to-end evaluation of response quality. Unit testing with fake LLMs — use FakeListLLM or FakeListChatModel to return predetermined responses so tests run fast and determin...
14. How do you monitor LangChain applications?
Monitoring LangChain applications in production means tracking latency, error rates, token usage, and response quality over time. LangSmith is the primary tool, but you can also integrate with standard observability infrastructure. LangSmith tracing — enabled with two env vars, it captures every ...
15. What are common pitfalls in LangChain/LangGraph development?
Developers new to LangChain and LangGraph frequently encounter the same set of issues. Knowing them in advance saves significant debugging time: Context window overflow — injecting the full conversation history into every prompt causes failures on long conversations. Fix: use ConversationBufferWi...