
Section 1: LangChain Fundamentals (Basic) #
- What is LangChain? It is a Python framework designed to simplify building applications powered by Large Language Models (LLMs) by providing modular “Lego-like” blocks.
- Why do we need LangChain if we have LLM APIs? It standardizes interactions across different providers and orchestrates complex tasks like RAG, memory management, and tool usage that a simple API call cannot handle.
- What are the five (or six) core building blocks of LangChain? Models, Prompts, Chains, Agents, Memory, and Indexes (RAG).
- What is the LangChain Expression Language (LCEL)? A declarative syntax using the pipe operator (|) to connect components into a pipeline.
- How does LangChain support “Model Agnostic” development? It provides a standardized interface allowing you to switch between providers (OpenAI, Claude, etc.) by changing just a few lines of code.
- What is the purpose of init_chat_model()? It is the easiest way to start because it automatically detects which provider to use based on the model name.
- What is a Prompt Template? A reusable blueprint for prompts where you use placeholders for variables instead of hardcoding text.
- What are the benefits of using Prompt Templates over Python f-strings? They provide built-in validation, are serializable (savable as JSON), and integrate natively with LCEL.
- What are Output Parsers? Components that convert raw text from an LLM into structured data like JSON, lists, or Python objects.
- Explain the difference between invoke(), stream(), and batch().
invoke()runs once and waits for the full result;stream()returns data token-by-token;batch()processes multiple inputs simultaneously. - What is a Document Loader? A utility to fetch data from various sources (PDF, CSV, URLs) and convert it into a standardized Document Object.
- What does a Document Object contain? Two fields:
page_content(the text) andmetadata(source info, page numbers, etc.). - Why are Text Splitters needed? LLMs have token limits, and splitting large text into smaller chunks ensures the model can process them without losing context or quality.
- What is “Chunk Overlap”? A shared portion of text between consecutive chunks to prevent losing context at the boundaries where the text was cut.
- What are the three main message types in Chat Models? SystemMessage (persona/rules), HumanMessage (user query), and AIMessage (model response).
Section 2: Models & Configuration (Basic/Intermediate) #
- What is the difference between an LLM and a Chat Model in LangChain? LLMs are “text-in, text-out,” while Chat Models take a sequence of labeled messages as input.
- What is an Embedding Model? A model that converts text into numerical vectors representing semantic meaning.
- What does the “Temperature” parameter control? It controls randomness; 0 makes the model deterministic, while 1.5+ makes it highly creative/varied.
- What is the purpose of “Max Completion Tokens”? It restricts the length of the response to manage costs and context window usage.
- Why use Open Source models like TinyLlama or Llama 3? They offer data privacy (run locally), full control over fine-tuning, and no per-token API costs.
- How do you use Open Source models in LangChain? Via the Hugging Face Inference API or by downloading them locally using Hugging Face Pipeline.
- What is the “Knowledge Cut-off” date? The date after which an LLM lacks information about recent events because its training stopped.
- What are “Hallucinations”? When an LLM confidently generates factually incorrect or “made up” information.
- Explain “Few-Shot Prompting.” Providing the LLM with a few examples of input-output pairs inside the prompt to guide its behavior.
- What is a Message Placeholder? A special placeholder in a
ChatPromptTemplateused to dynamically insert conversation history.
Section 3: RAG & Indexing (Intermediate) #
- What is RAG (Retrieval-Augmented Generation)? A technique where relevant information is retrieved from external data and provided to the LLM as context for every query.
- What is the difference between Parametric and External Knowledge? Parametric is learned during training; External is injected via RAG at query time.
- List the four stages of a RAG pipeline. Indexing, Retrieval, Augmentation, and Generation.
- What is a Vector Store? A specialized database that stores text as embeddings to enable semantic search.
- What is “Semantic Search”? Searching based on meaning rather than exact keyword matching by comparing vector distances.
- What is the difference between a Vector Store and a Vector Database? A Vector Store (like FAISS) is a lightweight library; a Vector Database (like Pinecone) is a full-fledged system with enterprise features like backups and scaling.
- Explain “Cosine Similarity” in Vector Stores. A metric used to calculate the similarity between two vectors by measuring the angle between them.
- What is a Retriever? A component that fetches relevant documents from a data source (like a vector store) in response to a query.
- How does RecursiveCharacterTextSplitter work? It tries to keep related text (paragraphs/sentences) together by splitting based on a hierarchy of separators (
\n\n,\n, ,""). - What is “Eager Loading” (load()) vs. “Lazy Loading” (lazy_load())? Eager loads all data into RAM at once; Lazy returns a generator to process one document at a time to save memory.
- What is Chroma DB? A light-weight open-source vector database friendly for local development.
- How do you update a document in a vector store? By using the
update_documentfunction and providing the specific document ID. - How do you delete a document from a vector store? By using the
deletefunction and passing the unique IDs of the documents. - What is the PyPDFLoader unique feature? It loads PDFs page-by-page, creating a separate Document object for each page.
- What is DirectoryLoader? A loader that allows you to batch load multiple files from a folder using a glob pattern.
Section 4: Chains & Runnables (Intermediate/Advanced) #
- What is a Chain? A way to connect multiple components (Prompt -> Model -> Parser) into a single automated pipeline.
- What is a Runnable? The standard interface for all LangChain components, ensuring they have consistent methods like
invoke(). - What is RunnableSequence? A primitive that links multiple Runnables in a series where Step 1’s output is Step 2’s input.
- What is the purpose of RunnableParallel? It allows executing multiple chains simultaneously using the same input.
- What is RunnablePassThrough? It passes the input to the output unchanged, often used in parallel chains to preserve original data.
- What is RunnableLambda? A component that allows you to convert any standard Python function into a Runnable to be used in a chain.
- What is RunnableBranch? It implements “If-Else” logic, allowing the chain to take different paths based on a condition.
- How do you visualize a chain? By using the
.get_graph().print_ascii()method. - What is the difference between a Sequential Chain and a Parallel Chain? Sequential runs steps one after another; Parallel runs them at the same time.
- What is the modern way to define a RunnableSequence? Using the pipe (
|) operator (LCEL).
Section 5: Output Parsing & Structured Data (Intermediate/Advanced) #
- Why is structured output important for machine-to-machine communication? Unstructured text cannot be easily processed by databases or APIs; structured data like JSON is required.
- What is with_structured_output? A native function for models that support function calling or JSON mode to return data in a specific schema.
- What is a PydanticOutputParser? A robust parser that uses Pydantic models to enforce schema validation and type coercion.
- What is the difference between JsonOutputParser and StructuredOutputParser?
JsonOutputParserreturns JSON but doesn’t enforce a schema;StructuredOutputParserallows you to define a specific schema but lacks advanced validation. - When should you use StrOutputParser? When you only need the clean text response and want to strip away model metadata.
- What is a “Typed Dictionary” (TypedDict)? A Python way to specify required keys and value types in a dictionary, though it lacks runtime validation.
- How does Pydantic perform “Type Coercion”? It automatically converts compatible types (e.g., a string “25” to an integer 25) during validation.
- What is ResponseSchema? A component used by the
StructuredOutputParserto define individual fields in a schema. - Why might smaller models like TinyLlama fail at structured output? They are not fine-tuned for “JSON mode” or function calling, necessitating manual output parsers and strict prompting.
- What is the role of get_format_instructions() in a parser? It generates the specific text prompt that tells the LLM how to format its response (e.g., “Return a JSON object…”).
Section 6: Agents & Tools (Advanced) #
- What is an AI Agent? An autonomous system that uses an LLM as a reasoning engine to decide which actions/tools to use to reach a goal.
- What is the fundamental difference between a Chain and an Agent? A chain has predefined steps set by the developer; an agent autonomously chooses its steps at runtime.
- What is a Tool in LangChain? A packaged Python function that an LLM can understand and decide to call.
- How do you create a custom tool? By using the @tool decorator on a function with a detailed docstring.
- Why is a docstring essential for a tool? It provides the description the LLM uses to understand when and how to call the tool.
- What is “Tool Calling”? The process where an LLM generates a structured suggestion (name + arguments) for a tool it wants to use.
- Does the LLM execute the tool’s Python code? No, the LLM only suggests the call; the programmer or framework executes the code.
- What is bind_tools()? The method used to register specific tools with an LLM so the model knows they are available.
- Explain the ReAct pattern. Reasoning + Acting: A loop of Thought → Action → Observation.
- What is an “Agent Scratchpad”? A temporary memory where the agent records its thoughts and tool outputs to decide the next step.
- What is the difference between Agent and AgentExecutor? The Agent is the “thinker” (decides what to do); the
AgentExecutoris the “doer” (runs the loop and tools). - What is “Human-in-the-loop” (HITL)? A safety feature where the AI pauses for human approval before critical actions (e.g., deleting data).
- What are “Injected Tool Arguments”? Arguments like user IDs that are provided by the developer at runtime, which the LLM is told not to fill.
- What is a ToolKit? A collection of related tools (e.g., Gmail tools) packaged together for reusability.
- What is the StructuredTool.from_function method? A more strict way to create tools that uses Pydantic to enforce input schemas.
Section 7: Advanced Retrieval & Memory (Advanced) #
- What is “Maximum Marginal Relevance” (MMR)? A retrieval algorithm that balances relevance with diversity to avoid returning redundant information.
- What is a “Multi-Query Retriever”? It uses an LLM to generate multiple versions of a user’s query to catch different perspectives and improve retrieval quality.
- Explain “Contextual Compression.” Trimming documents after retrieval to keep only the specific sentences that answer the query, saving space in the context window.
- How does “Similarity Search with Score” differ from regular search? It returns the similarity distance/score, where a lower score often indicates higher similarity.
- What is “Hybrid Search”? Combining vector search (semantic) with keyword search (BM25/Exact match) for better accuracy.
- What is “Reranking” in RAG? A post-retrieval step where an LLM re-orders the retrieved chunks to ensure the best answer is at the top.
- What is “ConversationBufferMemory”? It stores the entire raw history of messages in a buffer to pass back to the LLM.
- What is “ConversationSummaryMemory”? It uses an LLM to create a summary of the conversation to save on tokens for long chats.
- What is “ConversationBufferWindowMemory”? It only keeps the last N interactions to focus on the most recent context.
- What are “Memory Keys”? The names (like
chat_history) used to store and inject memory into prompts.
Section 8: Production, Engineering & Future (Advanced) #
- What is LangGraph and when should you use it? LangChain’s framework for stateful workflows involving loops and multi-agent systems; used when standard autonomous agents aren’t scalable enough.
- What is LangSmith? A platform for tracing, debugging, and evaluating LangChain applications.
- What are “Emergent Properties” in LLMs? Abilities (like in-context learning) that appear when a model reaches a certain scale/complexity even if not explicitly programmed.
- What is “LangServe”? A tool to deploy LangChain chains as REST APIs easily.
- Explain “Type Coercion” in Pydantic. The ability to convert data types automatically (e.g., “10” to 10) to match a schema.
- What is “Metadata Filtering”? Filtering search results in a vector store based on non-semantic criteria like “date” or “category”.
- How do you handle “Rate Limiting” in production? By implementing logic to prevent too many API calls, protecting against abuse and high costs.
- What is the “Middleware” concept in agents? It allows intercepting and modifying agent behavior (e.g., logging or safety filters).
- What is “Answer Grounding”? Instructing the LLM to answer only from the provided context to prevent hallucinations.
- What is the “Standard Deviation” method in Semantic Chunking? Identifying a topic change (split point) when the similarity between sentences drops below a certain standard deviation.
- What is a “Multi-Modal RAG”? A system that can retrieve and generate answers from multiple data types like text, images, and videos.
- What is an “Agentic RAG”? A system where an agent uses a retriever as one of its tools to look up information.
- Why is load_memory_variables({}) used? To fetch the current state of stored messages from a memory object.
- How do you implement “Context Window Optimization”? By trimming irrelevant context parts via compression or selection before generation.
- What is the technical definition of an “AI Agent”? An intelligent system that receives a high-level goal and autonomously plans and executes a sequence of actions using tools.