0Pricing
Vector Databases: Pinecone, Weaviate & pgvector · 课时

RAG 系统架构概览

了解典型 RAG 系统的组件和工作流,重点掌握向量数据库所发挥的作用。

RAG 系统架构概览 是 CoddyKit 上的免费 Vector Databases: Pinecone, Weaviate & pgvector 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Vector Databases: Pinecone, Weaviate & pgvector 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Vector Databases: Pinecone, Weaviate & pgvector 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

What is RAG?

Welcome! In this lesson, we'll explore Retrieval Augmented Generation (RAG) systems. RAG is a powerful technique that combines large language models (LLMs) with external knowledge sources.

It allows LLMs to generate more accurate, up-to-date, and context-rich responses by retrieving relevant information before generating an answer. Think of it as giving an LLM a personal research assistant!

LLM's Knowledge Gap

Large Language Models (LLMs) are amazing, but they have limitations:

  • Knowledge Cutoff: Their training data is static, so they don't know about recent events or information.
  • Hallucinations: They can sometimes generate plausible-sounding but factually incorrect information.
  • Domain Specificity: They lack deep knowledge about private, proprietary, or highly specialized data.

RAG helps address these challenges by providing real-time, relevant facts.

How RAG Bridges the Gap

RAG introduces an information retrieval step before the LLM generates its response. Instead of relying solely on its internal training, the LLM is given specific context from an external knowledge base.

This means the LLM can answer questions about new data, company documents, or specific topics it wasn't originally trained on, significantly reducing hallucinations and improving factual accuracy.

Core RAG Components

A RAG system typically consists of several key components working together:

  • Knowledge Base: Your source documents.
  • Embedding Model: Converts text to numerical vectors.
  • Vector Database: Stores and indexes these vectors.
  • Retriever: Finds relevant information from the vector database.
  • Generator (LLM): Uses the retrieved info to form an answer.

Let's look at each part in more detail.

The Knowledge Base

The knowledge base is the foundation of your RAG system. It's where all the information you want your LLM to access resides.

This can include:

  • Company documents (PDFs, internal wikis)
  • Web articles or blogs
  • Books or research papers
  • Databases or structured data

The quality and relevance of this data directly impact the RAG system's performance.

Embedding & Indexing

Before data can be searched, it needs to be processed. This involves two main steps:

  • Chunking: Breaking down large documents into smaller, manageable pieces (chunks).
  • Embedding: Using an embedding model to convert each text chunk into a numerical vector (an embedding). These vectors capture the semantic meaning of the text.

These embeddings are then stored and indexed for efficient retrieval.

The Vector Database

This is where the 'vector' in RAG comes in! A vector database is specialized to store and efficiently search these high-dimensional vector embeddings.

When a user asks a question, the query is also converted into an embedding. The vector database then quickly finds the most 'similar' (closest in vector space) document chunks to that query.

The Retriever Component

The retriever is the part of the RAG system responsible for fetching relevant context from your knowledge base.

When a user submits a query:

  1. The query is embedded.
  2. The retriever uses this embedding to search the vector database.
  3. It returns the top-K (e.g., top 3 or 5) most similar text chunks.

These retrieved chunks are the 'context' that will be passed to the LLM.

The Generator (LLM)

Finally, the generator, which is your Large Language Model (LLM), takes over. Instead of just the user's query, it receives both the query AND the retrieved context.

It then synthesizes this information to formulate a comprehensive and accurate answer. Try this simple conceptual Python example:

def generate_response(query, context):
    # This function simulates how an LLM uses context.
    # In a real RAG, a complex LLM API call would happen here.
    prompt = f"""Based on the following context, answer the question.
Context: {context}
Question: {query}
Answer:"""
    
    # Simulate LLM processing
    if "capital of France" in query.lower() and "Paris" in context:
        return "The capital of France is Paris, according to the context provided."
    else:
        return f"LLM would process: '{prompt}' and generate a thoughtful response based on the context."

if __name__ == "__main__":
    user_query = "What is the capital of France?"
    retrieved_context = "Paris is the capital and most populous city of France, located on the Seine River."
    
    print("--- RAG Process Simulation ---")
    print(f"User Query: {user_query}")
    print(f"Retrieved Context: {retrieved_context}")
    
    llm_response = generate_response(user_query, retrieved_context)
    print(f"LLM Response: {llm_response}")

RAG System Workflow

Let's put it all together. Here's the typical flow when a user queries a RAG system:

  1. User Query: A user asks a question.
  2. Embed Query: The query is converted into an embedding.
  3. Retrieve Context: The embedding is used to search the vector database for relevant document chunks.
  4. Augment Prompt: The original query is combined with the retrieved context to create an enriched prompt.
  5. Generate Response: This augmented prompt is sent to the LLM, which generates the final answer.

Quick Check: RAG Flow

Which of the following steps happens *before* the Large Language Model (LLM) generates its final response in a RAG system?

RAG: Recap & Next Steps

Great job! You've learned the fundamental architecture of a RAG system. We covered:

  • Why RAG is needed to overcome LLM limitations.
  • The core components: Knowledge Base, Embedding Model, Vector Database, Retriever, and Generator (LLM).
  • The step-by-step workflow from user query to LLM response.

Understanding this architecture is key to building powerful, context-aware AI applications. Next, we'll dive into integrating RAG with popular LLM frameworks!

常见问题解答

「RAG 系统架构概览」课时是免费的吗?

是的 — 「RAG 系统架构概览」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Vector Databases: Pinecone, Weaviate & pgvector 课程的其余内容,请升级到 CoddyKit PRO。 Vector Databases: Pinecone, Weaviate & pgvector 课程共包含 4 节课。

「RAG 系统架构概览」这节课中我会学到什么?

了解典型 RAG 系统的组件和工作流,重点掌握向量数据库所发挥的作用。 你通过在浏览器中直接运行的动手代码来练习 Vector Databases: Pinecone, Weaviate & pgvector,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Vector Databases: Pinecone, Weaviate & pgvector 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Vector Databases: Pinecone, Weaviate & pgvector 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「RAG 系统架构概览」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Vector Databases: Pinecone, Weaviate & pgvector 课中编写并运行代码吗?

能。每节 Vector Databases: Pinecone, Weaviate & pgvector 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. RAG 系统架构概览
  2. 与 LLM 框架集成
  3. 上下文信息检索
  4. RAG 的文本块拆分策略
← 返回 Vector Databases: Pinecone, Weaviate & pgvector