متقدم
البحث فيالملخصات
طريقة البحث
  • الكلمات تجد عناوين الدروس والنص والكود. صفِّ حسب النوع (أدلة، دورات، برامج، كتب) أو ابقَ في هذا الكتاب.
  • book:rhcsa و ch:8 يضيّقان البحث؛ ‎#code يجد الكلمة داخل أوامر الدروس فقط.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدورة 12الاسم في الدورة: Fundamentals of AI Agents Using RAG and LangChain

Fundamentals of AI Agents Using RAG and LangChain

Course 12 of 13 in the IBM AI Engineering certificate. What AI agents are and when they are a good choice.

Course page: Coursera

  • 7 الدروس
  • 0 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

12.1

What the course covers

What AI agents are and when they are a good choice.

  • How tool calling lets an LLM act on other systems.
  • How RAG retrieves context before the model answers.
  • How DPR and FAISS find similar text fast.
  • Prompt engineering with LangChain documents, chains and agents.
ModuleMain focus
Module 1 · about 2 hoursFundamentals of AI Agents: agent designs, tool calling, build from scratch, when to use agents
Module 2 · about 3 hoursRAG Framework: retrieval pipeline, DPR encoders, FAISS, Hugging Face and PyTorch labs
Module 3 · about 4 hoursPrompt Engineering and LangChain: in-context learning, prompts, documents, chains, agents

12.2

Module 1: Fundamentals of AI Agents

Fundamentals of AI Agents: agent designs, tool calling, build from scratch, when to use agents.

  • An AI agent uses an LLM to decide the next action, calls tools, reads the result and repeats until the task is done.
  • A traditional AI system follows a fixed pipeline. An agent chooses its own steps at run time.
  • Tool calling: the model returns a structured request (tool name plus arguments). The app runs the tool and sends back the result.
  • Agents help with multi-step tasks, fresh data and actions in other systems. They add cost, latency and risk.
  • Do not use an agent for a simple one-shot task. A fixed prompt or a chain is cheaper and easier to test.
  • From scratch gives full control and teaches the mechanics, but you write all the glue code yourself.
  • Frameworks like LangChain give ready tools, memory and chains. They save time but hide details and add dependencies.
  • ReAct is a common pattern: the model writes a thought, an action and an observation in a loop.

12.3

Module 2: RAG Framework

RAG Framework: retrieval pipeline, DPR encoders, FAISS, Hugging Face and PyTorch labs.

  • RAG means retrieval-augmented generation: find useful text first, then let the LLM answer with that text in the prompt.
  • RAG lowers hallucination and lets you update knowledge by changing documents, not weights.
  • Pipeline: load, split, embed, store, retrieve the top-k chunks, build the prompt, generate.
  • An embedding is a dense vector. Texts with similar meaning get vectors that are close.
  • DPR (dense passage retrieval) uses two encoders: a question encoder and a context encoder, each with its own tokenizer.
  • FAISS is a library from Facebook AI Research for fast similarity search over many vectors.
  • Chunk size and overlap matter. Bad chunks give bad context, and bad context gives bad answers.

12.4

Module 3: Prompt Engineering and LangChain

Prompt Engineering and LangChain: in-context learning, prompts, documents, chains, agents.

  • In-context learning puts examples in the prompt. The weights do not change: zero-shot, one-shot, few-shot.
  • Advanced prompts include chain-of-thought, role prompts, prompt chaining and self-consistency.
  • LangChain is an open-source framework that connects LLMs with data, prompts and tools.
  • Core parts: models (LLM and chat), prompts, output parsers, documents, retrievers, chains and agents.
  • Chat models take messages with roles: system, human and AI.
  • PromptTemplate fills variables. FewShotPromptTemplate adds examples, and an example selector picks them.
  • Documents hold page_content and metadata. Loaders create them; splitters cut them into chunks.
  • A chain runs steps in order. An agent chooses which tool to call next.
  • A RAG chain joins the retriever, the prompt, the model and the parser.

12.5

Check yourself

Answer each question first, then open it to check the answer.

1What is an AI agent? a) A fixed SQL query · b) An LLM that plans and calls tools in a loop · c) A vector database · d) A tokenizer

b) An LLM that plans and calls tools in a loop. The agent loops: it plans, calls a tool and uses the result to decide the next step.

2How does tool calling work? a) The model writes a structured call with a tool name and arguments; the app runs it and returns the result · b) The model runs the tool itself on the GPU · c) The user writes every step in code · d) The tool trains the model

a) The model writes a structured call with a tool name and arguments; the app runs it and returns the result. The model only proposes the call; the application executes it and returns the output.

3When should you avoid an AI agent? a) When you need external data · b) When the task needs many steps · c) When you need to call an API · d) When a simple one-step prompt is enough

d) When a simple one-step prompt is enough. For one simple step, a fixed prompt is cheaper, faster and easier to test.

4What is a plus of using an agent framework like LangChain? a) It gives ready-made parts and saves time · b) It removes the need for an LLM · c) It makes the model smaller · d) It guarantees correct answers

a) It gives ready-made parts and saves time. The framework gives ready building blocks, so you write less code.

5What is a minus of building an agent from scratch? a) You cannot call tools · b) You must write and test all the glue code yourself · c) You cannot use an LLM · d) You cannot store data

b) You must write and test all the glue code yourself. With no framework you must write the tool handling, the loop and the error handling yourself.

6What are the main steps of RAG? a) Train a model from zero every time · b) Quantize the model and fine-tune · c) Load and split documents, embed and store them, retrieve on a query, then generate with context · d) Only write a longer prompt

c) Load and split documents, embed and store them, retrieve on a query, then generate with context. RAG always retrieves relevant chunks before the model writes the answer.

7What does an embedding model output? a) A PDF file · b) A dense vector that represents the meaning of the text · c) A tokenizer file · d) A reward score

b) A dense vector that represents the meaning of the text. The embedding is a vector of numbers that stands for the meaning of the text.

8In DPR, how many encoders are used? a) One encoder for questions and one for context passages · b) One encoder for everything · c) Three encoders · d) No encoder

a) One encoder for questions and one for context passages. DPR uses separate question and context encoders with separate tokenizers.

9What is FAISS used for? a) Text splitting · b) Building a UI · c) Training a reward model · d) Fast similarity search in high-dimensional vector spaces

d) Fast similarity search in high-dimensional vector spaces. FAISS indexes vectors and finds nearest neighbours quickly.

10What is in-context learning? a) Fine-tuning all weights · b) Giving examples in the prompt without changing the model weights · c) Quantizing the model · d) Storing documents in Chroma

b) Giving examples in the prompt without changing the model weights. The examples live in the prompt; the model weights stay the same.

11Which LangChain object holds page_content and metadata? a) PromptTemplate · b) OutputParser · c) Document · d) Retriever

c) Document. A Document carries page_content plus metadata such as the source.

12What does a LangChain retriever do? a) It takes a query and returns relevant documents · b) It trains the model · c) It builds the Gradio page · d) It counts tokens

a) It takes a query and returns relevant documents. A retriever wraps a search and returns documents for a query.

13What connects the steps in a LangChain chain? a) A database trigger · b) A cron job · c) The tokenizer · d) The output of one step becomes the input of the next

d) The output of one step becomes the input of the next. LangChain composes steps so each output feeds the next input.

12.6

Study and exam tips

Agent equals a loop: think, call a tool, read the result, repeat.

  • RAG equals retrieve first, generate second.
  • DPR has two encoders; do not mix it up with one shared encoder.
  • FAISS is for search. It is not for training, prompts or UI.
  • In LangChain, know what each object does: Document, PromptTemplate, Retriever and Chain.