All question types and answers for the RAG section in LLM interviews. Source: AIGC Interview Bible, totaling 16 RAG-related PDFs.
I. RAG Fundamentals (Why / What / Three Modules)
Why an external (vector) knowledge base is needed
| Direct methods | Problems |
|---|---|
| Fine-tuning | High cost / requires training time / degradation of general capabilities (catastrophic forgetting) |
| In-Context Learning | Limited context length / difficulty processing multiple documents |
| RAG (external knowledge base) ✅ | Retrieval + generation,Flexible + low cost + easy to update |
Three modules of RAG
| Module | Function |
|---|---|
| R - Retriever | Convert external knowledge sources into vectors, and retrieve relevant documents based on the query |
| A - Augment | Concatenate retrieval results with the user query to form a new prompt |
| G - Generator | The large model generates the final answer based on the augmented prompt |
RAG workflow
1. 知识库构建:文档 → 切分 chunk → embedding → 向量库
2. 用户提问:Query → embedding
3. 检索:向量相似度搜索 Top-K chunk
4. 增强:Query + 检索 chunk → 新 Prompt
5. 生成:LLM 基于新 Prompt 生成答案
LangChain RAG hands-on example
See file_13 for details — using Baidu Baike data on "quinoa" + the LangChain framework to implement a simple RAG Q&A application.
II. Key issues in PDF parsing (file_16)
Why is PDF parsing needed?
When implementing document assistants using LLMs, such as ChatPDF / ChatDoc,PDF text extraction is difficult(especially for complex layouts / multi-column / tables).
Difficulties in PDF parsing
| Difficulty | Example |
|---|---|
| Multi-column layout | Two-column academic papers |
| Embedded figures and tables | Tables and figures in financial reports |
| Character encoding anomalies | Irreversible custom fonts |
| Scanned image PDFs | No text layer, OCR required |
| Loss of document structural information | Heading hierarchy / paragraph affiliation |
PDF parsing solutions
- pdfplumber / pdftotext (poppler) — Plain text
- PaddleOCR / Tesseract — Scanned image OCR
- Layout Parser / Donut — Layout analysis
- GPT-4 Vision — Multimodal direct reading of PDFs
III. Layout analysis (file_17 tables + file_18 text chunking)
Table recognition task
Why is table recognition needed? — Most data in financial reports / papers is in tables, and direct OCR produces out-of-order results.
Table recognition methods:
| Method | Characteristics |
|---|---|
| Rule-based method | Detect horizontal/vertical lines |
| CNN-based | Detect table regions + cells |
| Transformer-based(TableNet) | End-to-end table parsing |
| GPT-4V | Direct visual reading |
Text chunking
Why is chunking needed? — Embedding models have token length limits + LLM context is limited.
Common chunking methods:
| Method | Approach |
|---|---|
| Fixed-length splitting | By token / character |
| Sentence-based splitting | spaCy / NLTK / langchain RecursiveCharacterTextSplitter |
| Paragraph-based splitting | \n\n separation |
| Semantic splitting | Use embedding similarity to determine split points |
| Structural splitting | By document heading hierarchy |
Best practices:
- chunk_size: 256-1024 token
- chunk_overlap: 10–20% of chunk_size
- Chinese chunk_size is slightly smaller than English
IV. Retrieval augmentation (recall optimization)
file_19: HYDE — Hypothetical Document Embeddings
Problem: User queries are short + abstract → retrieval is difficult.
HYDE approach:
- Let the LLM first generate a "hypothetical answer document" for the query
- Use the embedding of this hypothetical document as the retrieval query
- Retrieve real documents as the final context
Advantage: The hypothetical document is semantically closer to the real answer, leading to high recall.
file_20: Hard negative sample mining
Why construct hard negative samples? — After training with simple (random) negative samples, the model has no discriminative power for content that "looks relevant but is actually irrelevant".
Hard negative sample construction methods:
| Strategy | Approach |
|---|---|
| Random Sampling | Simple random sampling |
| Hard Negative Mining | Samples that the current model most easily confuses |
| In-Batch Negatives | In-batch non-self samples |
| Cross-Batch Negatives | Cross-batch |
| Bi-encoder + Cross-encoder Distillation | Distill bi-encoder using cross-encoder |
V. RAG optimization strategies (file_22 + file_23)
Optimization points for each RAG module
| Module | Optimization strategy |
|---|---|
| Data preprocessing | Cleaning / deduplication / metadata enhancement |
| chunk | Chunk granularity / overlap / parent-child chunks |
| embedding | Model selection (Chinese BGE / m3e) / fine-tuning |
| Retrieval | Top-K / multi-path recall / Rerank |
| Augmentation | Prompt templates / context compression |
| Generation | Model selection / temperature / length |
Key pain points of RAG (file_23, 6 major problems and solutions)
| Pain point | Solution |
|---|---|
| Missing content | Improve the knowledge base / add sources |
| Missing top-ranked documents | Multi-path recall + Rerank |
| Content loss after integration | Use LLM for context compression instead of truncation |
| Context limit | Long Context model / Map-Reduce |
| Format errors | Explicit Prompt + output validation |
| Incomplete answers | Step-back Prompting / multi-turn iteration |
VI. RAG evaluation (file_21)
Why evaluate RAG?
- Large models are black boxes; quantitative judgment is needed to assess improvements
- A/B comparison of different RAG solutions
How to synthesize a RAG test set?
| Method | Approach |
|---|---|
| Manual annotation | Manually write questions + standard answers |
| GPT-4 synthesis | Provide documents → let GPT-4 generate questions and answers |
| Public datasets | NaturalQuestions / TriviaQA |
RAG evaluation methods
| Aspect | Metrics |
|---|---|
| Retrieval quality | Recall@K / MRR / NDCG |
| Answer quality | BLEU / ROUGE / BERTScore (automatic) / human scoring |
| Overall | RAGAS framework (faithfulness / answer_relevancy / context_precision / context_recall) |
VII. RAG-Fusion (file_24)
Why RAG-Fusion?
Limitations of ordinary RAG:
- The top-K recalled by a single query may be incomplete
- Recall is biased when user questions are ambiguous
RAG-Fusion approach
1. 用 LLM 把原 query 改写出 N 个不同表达
2. 每个 query 单独召回 top-K
3. 用 RRF (Reciprocal Rank Fusion) 合并结果
4. Rerank + 最终给 LLM
Advantages:
- Improved recall (multi-query covers broader scope)
- Robust to ambiguous user questions
VIII. Graph RAG (file_25)
Why Graph RAG?
Limitations of ordinary RAG:Can only capture local context, and cannot answer questions requiring global reasoning (e.g., "What is the relationship between X and Y?").
Graph RAG approach
1. 用 LLM 从文档中抽取实体 + 关系 → 构建知识图谱
2. 用户问题先做实体识别 / 关系查询
3. 通过图遍历得到相关子图
4. 子图 + 上下文给 LLM 生成
Typical scenarios:
- Multi-hop Q&A (requiring 2–3 steps of reasoning)
- Global summaries (core entity relationships across an entire book)
- Complex queries ("The financial performance after 2023 of all companies that have collaborated with X")
IX. Long-term memory in multi-turn conversations (file_12)
Challenges in multi-turn conversations
- User questions depend on previous context (pronouns / ellipsis)
- Overly long context will exceed the LLM context window
8 long-term memory optimization methods
| Method | Approach |
|---|---|
| 1. Full conversation history | Simple but expensive + limited by context |
| 2. Sliding window | Keep only the most recent N turns |
| 3. Summary condensation | Use LLM to compress old conversations |
| 4. Entity memory | Extract key entities as long-term memory |
| 5. Knowledge graph memory | Build a conversation KG |
| 6. Vector memory (Long-term Memory) | Store conversations in a vector database + retrieve relevant history |
| 7. Cache memory | LRU cache for frequently used context |
| 8. Hybrid memory | Combine short-term (full text) + long-term (vector) |
Practical recommendation: LangChain ConversationSummaryBufferMemory (hybrid of summary + sliding window).
X. LangChain RAG hands-on practice (file_13)
Hands-on steps (using Baidu Baike "quinoa" data as an example)
from langchain.document_loaders import TextLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
# 1. 加载文档
loader = TextLoader("liwheat.txt")
docs = loader.load()
# 2. 分块
splitter = RecursiveCharacterTextSplitter(
chunk_size=500, chunk_overlap=100
)
chunks = splitter.split_documents(docs)
# 3. 向量化 + 存库
embeddings = OpenAIEmbeddings()
db = Chroma.from_documents(chunks, embeddings)
# 4. 构建 RAG Chain
qa = RetrievalQA.from_chain_type(
llm=OpenAI(),
retriever=db.as_retriever(search_kwargs={"k": 3}),
chain_type="stuff"
)
# 5. 问答
answer = qa.run("藜麦有哪些营养价值?")
XI. LangChain basics (file_11)
What is LangChain
- A powerful framework designed to help developers build end-to-end applications using language models
- Provides tools / components / interfaces to simplify the creation of LLM-powered applications
- Can manage interactions with language models,link multiple components + integrate additional resources (APIs / databases)
LangChain core components
| Component | Function |
|---|---|
| Models | Unified interface abstracting different LLMs (OpenAI / Anthropic / local) |
| Prompts | Templated prompt management |
| Chains | Multi-step composition (LLM + tools +...) |
| Agents | Let the LLM decide which tool to call |
| Memory | Maintain conversation history |
| Indexes | Document loading / splitting / vectorization |
| Retrievers | Retrieval interface |
| Output Parsers | Convert LLM outputs into structured data |
See also
- LLM Interviews / Basic Architecture and Components — Basic architecture and components
- LLM Interviews / Complete Special Topic on Fine-tuning and Reinforcement Learning — Fine-tuning / RLHF
- LLM Interviews / 8 Illustrated Special Topics on Distributed Training — Distributed training
- AI Product Manager Interviews and Career Transition / Compilation of 12 Materials — AI product manager interview questions
- newtype · RAG Practice and Knowledge Base Evolution — newtype Lao Huang's RAG practical philosophy (consumer perspective)
- dontbesilent AI Self-media Course / 13 Lessons of Systematic Methodology — The essence of RAG knowledge bases (Emma and Perplexity are both examples)
High-frequency exam point priority
- 🔥🔥🔥 Three RAG modules + workflow — Must-test
- 🔥🔥🔥 6 major categories of RAG key pain points — Practical questions
- 🔥🔥 Text chunking strategies + chunk_size empirical values
- 🔥🔥 HYDE hypothetical documents(Advanced)
- 🔥🔥 RAG-Fusion + RRF
- 🔥 Graph RAG(Differentiation advantage)
- 🔥 RAGAS evaluation framework
- 🔥 8 memory methods for multi-turn conversations