Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNIT] llama-index framework - release 3/3/25 #22

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f5ae4bd
Add general outline llama-index based on TOC
davidberenstein1957 Feb 4, 2025
151f6c3
Add LlamaIndex framework documentation files
davidberenstein1957 Feb 7, 2025
6a1938f
Merge branch 'main' into frameworks/llama-index
davidberenstein1957 Feb 7, 2025
d4ae36c
Update LlamaIndex documentation with comprehensive framework overview
davidberenstein1957 Feb 7, 2025
98373b9
Refine LlamaIndex documentation with clearer language and improved ex…
davidberenstein1957 Feb 7, 2025
f74d175
Restructure LlamaIndex documentation with detailed components and int…
davidberenstein1957 Feb 10, 2025
c454a03
Merge branch 'main' into frameworks/llama-index
davidberenstein1957 Feb 10, 2025
5e1a7e5
Refactor LlamaIndex documentation: Update content structure and remov…
davidberenstein1957 Feb 11, 2025
7cb76e5
Update LlamaIndex components documentation with detailed QueryEngine …
davidberenstein1957 Feb 11, 2025
43e8a2f
Merge branch 'main' into frameworks/llama-index
davidberenstein1957 Feb 11, 2025
7b82baa
Reorganize Unit 2 LlamaIndex content and update README
davidberenstein1957 Feb 11, 2025
0ae5664
Update LlamaIndex documentation with detailed tools and agent creatio…
davidberenstein1957 Feb 11, 2025
cb74d10
Update LlamaIndex agents and tools documentation with comprehensive e…
davidberenstein1957 Feb 12, 2025
fb992bf
Update LlamaIndex unit structure and add new documentation files for …
davidberenstein1957 Feb 12, 2025
0392515
Refactor LlamaIndex documentation with comprehensive workflow and mul…
davidberenstein1957 Feb 12, 2025
19d5c0e
Add workflow creation guide and evaluation techniques in LlamaIndex d…
davidberenstein1957 Feb 12, 2025
42315c8
Add LlamaIndex workflow documentation link and introduction to AgentW…
davidberenstein1957 Feb 12, 2025
21d4078
Enhance LlamaIndex components documentation with detailed storage and…
davidberenstein1957 Feb 13, 2025
10914a2
Enhance LlamaIndex workflow documentation with comprehensive examples…
davidberenstein1957 Feb 13, 2025
dd00899
Remove best practices section from LlamaIndex workflow documentation
davidberenstein1957 Feb 13, 2025
d25186e
Apply suggestions from code review
davidberenstein1957 Feb 13, 2025
209e026
Apply suggestions from code review
davidberenstein1957 Feb 13, 2025
f16e94e
Update LlamaIndex documentation with refined explanations of componen…
davidberenstein1957 Feb 13, 2025
9cc0aef
Merge branch 'frameworks/llama-index' of https://github.com/huggingfa…
davidberenstein1957 Feb 13, 2025
e48c3c7
Refactor LlamaIndex documentation with improved workflow and tool cre…
davidberenstein1957 Feb 13, 2025
acbf8e7
Improve QueryEngine documentation with narrative context and Alfred a…
davidberenstein1957 Feb 13, 2025
37e1fd6
Reorganize LlamaIndex documentation structure and update content flow
davidberenstein1957 Feb 13, 2025
220f67e
Update LlamaIndex documentation file structure and content for unit2
davidberenstein1957 Feb 13, 2025
a5b2b04
Refactor LlamaIndex README with updated file structure and section ti…
davidberenstein1957 Feb 13, 2025
fd8c94f
Remove LlamaIndex introduction file from unit2
davidberenstein1957 Feb 13, 2025
ba29b29
Update introduction and LlamaIndex agents documentation with refined …
davidberenstein1957 Feb 13, 2025
abce3cb
Merge branch 'main' into frameworks/llama-index
davidberenstein1957 Feb 18, 2025
fc4d32f
Add LlamaHub documentation and update LlamaIndex unit2 content
davidberenstein1957 Feb 18, 2025
5260e93
Add LlamaHub documentation and update LlamaIndex unit2 content
davidberenstein1957 Feb 18, 2025
2ce32bb
Update LlamaIndex unit2 toctree with LlamaHub section
davidberenstein1957 Feb 18, 2025
6b212ef
Add visual elements to LlamaIndex tools documentation
davidberenstein1957 Feb 18, 2025
cd820b9
Update LlamaTrace installation instructions in components documentation
davidberenstein1957 Feb 18, 2025
32f45a7
Enhance LlamaIndex components documentation with RAG explanation
davidberenstein1957 Feb 18, 2025
81de803
Update LlamaIndex documentation with visual and formatting improvements
davidberenstein1957 Feb 18, 2025
eec73d8
Refine LlamaIndex documentation with improved text emphasis and forma…
davidberenstein1957 Feb 18, 2025
784d645
Update installation instructions for Google Toolspec and Workflow pac…
davidberenstein1957 Feb 18, 2025
1817bc3
Enhance LlamaIndex workflows documentation with improved explanations…
davidberenstein1957 Feb 18, 2025
bb811b4
Convert external link to HTML anchor tag in workflows documentation
davidberenstein1957 Feb 18, 2025
4931b95
Merge branch 'main' into frameworks/llama-index
davidberenstein1957 Feb 19, 2025
1f95517
Add quizzes for LlamaIndex unit2 documentation
davidberenstein1957 Feb 19, 2025
b9b0d53
Merge branch 'frameworks/llama-index' of https://github.com/huggingfa…
davidberenstein1957 Feb 19, 2025
b6c8074
Reorder LlamaIndex unit2 navigation in _toctree.yml
davidberenstein1957 Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions quiz/data/unit_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"question": "What is the main difference between LlamaIndex and other frameworks?",
"answer_a": "LlamaIndex is a data framework for your LLM application.",
"answer_b": "LlamaIndex is a tool for building agents.",
"answer_c": "LlamaIndex is a framework for building workflows.",
"answer_d": "LlamaIndex is a tool for building prompts.",
"correct_answer": "A"
}
]


21 changes: 21 additions & 0 deletions units/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,24 @@
sections:
- local: communication/next-units
title: Next Units
- title: Unit 2. Frameworks
local: unit2/introduction
sections:
- title: LlamaIndex
sections:
- local: unit2/llama-index/llama-index
title: What is LLamaIndex?
- local: unit2/llama-index/llama-hub
title: What is the LlamaHub?
- local: unit2/llama-index/components
title: What are Components in LlamaIndex?
- local: unit2/llama-index/tools
title: Using Tools in LlamaIndex
- local: unit2/llama-index/quiz1
title: Quick Quiz 1
- local: unit2/llama-index/agents
title: Using Agents in LlamaIndex
- local: unit2/llama-index/workflows
title: Creating Agentic Workflows in LlamaIndex
- local: unit2/llama-index/quiz2
title: Quick Quiz 2
17 changes: 8 additions & 9 deletions units/en/unit0/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Let's get started!
In this course, you will:

- 📖 Study AI Agents in **theory, design, and practice.**
- 🧑‍💻 Learn to **use established AI Agent libraries** such as [smolagents](https://huggingface.co/docs/smolagents/en/index), [LangChain](https://www.langchain.com/), and [LlamaIndex](https://www.llamaindex.ai/).
- 🧑‍💻 Learn to **use established AI Agent libraries** such as [smolagents](https://huggingface.co/docs/smolagents/en/index), [LlamaIndex](https://www.llamaindex.ai/), and [LangGraph](https://langchain-ai.github.io/langgraph/).
- 💾 **Share your agents** on the Hugging Face Hub and explore agents created by the community.
- 🏆 Participate in challenges where you will **evaluate your agents against other students'.**
- 🎓 **Earn a certificate of completion** by completing assignments.
Expand All @@ -36,7 +36,7 @@ And more!

At the end of this course you'll understand **how Agents work and how to build your own Agents using the latest libraries and tools**.

Don't forget to **<a href="https://bit.ly/hf-learn-agents">sign up to the course!</a>**
Don't forget to **<a href="https://bit.ly/hf-learn-agents">sign up to the course!</a>**

(We are respectful of your privacy. We collect your email address to be able to **send you the links when each Unit is published and give you information about the challenges and updates**).

Expand Down Expand Up @@ -88,13 +88,13 @@ You only need 2 things:

<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit0/three-paths.jpg" alt="Two paths" width="100%"/>

You can choose to follow this course *in audit mode*, or do the activities and *get one of the two certificates we'll issue*.
You can choose to follow this course *in audit mode*, or do the activities and *get one of the two certificates we'll issue*.

If you audit the course, you can participate in all the challenges and do assignments if you want, and **you don't need to notify us**.

The certification process is **completely free**:

- *To get a certification for fundamentals*: you need to complete Unit 1 of the course. This is intended for students that want to get up to date with the latest trends in Agents.
- *To get a certification for fundamentals*: you need to complete Unit 1 of the course. This is intended for students that want to get up to date with the latest trends in Agents.
- *To get a certificate of completion*: you need to complete Unit 1, one of the use case assignments we'll propose during the course, and the final challenge.

There's a deadline for the certification process: all the assignments must be finished before **May 1st 2025**.
Expand Down Expand Up @@ -147,11 +147,11 @@ Thomas is a machine learning engineer at Hugging Face and delivered the successf
- [Follow Thomas on X](https://x.com/ThomasSimonini)
- [Follow Thomas on Linkedin](https://www.linkedin.com/in/simoninithomas/)

## Acknowledgments
## Acknowledgments

We would like to extend our gratitude to the following individuals for their invaluable contributions to this course:
We would like to extend our gratitude to the following individuals for their invaluable contributions to this course:

- **[Pedro Cuenca](https://huggingface.co/pcuenq)** – For his guidance and expertise in reviewing the materials
- **[Pedro Cuenca](https://huggingface.co/pcuenq)** – For his guidance and expertise in reviewing the materials.
- **[Aymeric Roucher](https://huggingface.co/m-ric)** – For his amazing demo spaces ( decoding and final agent ) as well as his help on the smolagents parts.
- **[Joshua Lochner](https://huggingface.co/Xenova)** – For his amazing demo space on tokenization.
- **[Quentin Gallouédec](https://huggingface.co/qgallouedec)** – For his help on the course content.
Expand All @@ -169,8 +169,7 @@ Contributions are **welcome** 🤗

Please ask your question in our <a href="https://discord.gg/UrrTSsSyjb">discord server #ai-agents-discussions.</a>


Now that you have all the information, let's get on board ⛵
Now that you have all the information, let's get on board ⛵

<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit0/time-to-onboard.jpg" alt="Time to Onboard" width="100%"/>

9 changes: 9 additions & 0 deletions units/en/unit2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Table of Contents

This framework outline is part of unit 2 of the course. You can access the unit 2 on hf.co/learn 👉 <a href="https://hf.co/learn/agents-course/unit2/introduction">here</a>

| Title | Description |
| --- | --- |
| [smolagents](smolagents/README.md) | Overview of smolagents |
| [LangChain](langchain/README.md) | Overview of LangChain |
| [LlamaIndex](llama-index/README.md) | Overview of LlamaIndex |
20 changes: 20 additions & 0 deletions units/en/unit2/introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Frameworks

Now, we've mastered our fundamental understanding of agents, we can dive into the most popular frameworks that are used to build them!

In this second unit, **You will learn how to build agents and agentic workflows with various frameworks** including:

**[smolagents](https://github.com/huggingface/smolagents)**: a barebones library for agents. Agents write python code to call tools and orchestrate other agents.

**[LlamaIndex](https://github.com/run-llama/llama_index)**: a data framework for your LLM application. Building with LlamaIndex typically involves working with LlamaIndex core and a chosen set of integrations (or plugins).

**[LangGraph](https://github.com/langchain-ai/langgraph)**: a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows.

Sounds more or less similar, right?

Don't worry. After this unit, you will have a solid understanding of each one of these frameworks and **how and when to use each framework**. You will also have **hands-on experience with building agents** using each framework.

You will create an agent called Alfred, which can help you with tasks like Agentic Retrieval Augmented Generation (Agentic RAG).
Not only focussing on a single vector database, but also offering Alfred the tools to do query rewriting, web search, and everything else you need to build an optimal RAG system.

Ready? Let’s get started! 🚀
11 changes: 11 additions & 0 deletions units/en/unit2/llama-index/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Table of Contents

This LlamaIndex frame outline is part of unit 2 of the course. You can access the unit 2 about LlamaIndex on hf.co/learn 👉 <a href="https://hf.co/learn/agents-course/unit2/llama-index/introduction">here</a>

| Title | Description |
| --- | --- |
| [Introduction](introduction.mdx) | Introduction to LlamaIndex |
| [Components](components.mdx) | Components: the building blocks of workflows |
| [Tools](tools.mdx) | Tools: how to build tools in LlamaIndex |
| [Agents](agents.mdx) | Agents: how to build agents in LlamaIndex |
| [Workflows](workflows.mdx) | Workflows: a sequence of steps, events made of components that are executed in order |
112 changes: 112 additions & 0 deletions units/en/unit2/llama-index/agents.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Using Agents in LlamaIndex

Remember Alfred, our helpful butler agent from earlier? Well, he's about to get an upgrade!
Now that we understand the tools available in LlamaIndex, we can give Alfred new capabilities to better serve us.
But before we continue, let's remind ourselves what makes an agent like Alfred tick.
Back in Unit 1, we learned that:

> An Agent is a system that leverages an AI model to interact with its environment in order to achieve a user-defined objective. It combines reasoning, planning, and the execution of actions (often via external tools) to fulfill tasks.

LlamaIndex supports **three main types of reasoning agents:**

![Agents](https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/agents.png)

1. `Function Calling Agents` - These work with AI models that can call specific functions.
2. `ReAct Agents` - These can work with any AI that does chat or text endpoint and deal with complex reasoning tasks.
3. `Advanced Agents` - These use more complex methods like LLMCompiler or Chain-of-Abstraction.

<Tip>Find more information on advanced agents on <a href="https://github.com/run-llama/llama_index/tree/main/llama-index-packs">LlamaIndex GitHub</a></Tip>

## Initialising Agents

To create an agent, we start by providing it with a set of Tools that define its capabilities.
Let's look at how to create a ReAct agent with some basic tools.
ReAct agents are particularly good at complex reasoning tasks and can work with any LLM that has chat or text completion capabilities.

```python
from llama_index.core.tools import FunctionTool
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPILM
from llama_index.core.agent import ReActAgent

# define sample Tool
def multiply(a: int, b: int) -> int:
"""Multiple two integers and returns the result integer"""
return a * b

multiply_tool = FunctionTool.from_defaults(fn=multiply)

# initialize llm
llm = HuggingFaceInferenceAPILM(model_name="meta-llama/Meta-Llama-3-8B-Instruct")

# initialize ReAct agent
agent = ReActAgent.from_tools([multiply_tool], llm=llm, verbose=True)
```

Similarly, we can use the **`AgentRunner` to automatically pick the best agent reasoning flow** depending on the LLM.
Under the hood, it will thus pick either a Function Calling Agent or a ReAct Agent depending on the LLM.

```python
from llama_index.core.agent import AgentRunner

agent_runner = AgentRunner.from_llm(llm, verbose=True)
```

**Agents support both chat and query methods** with `query()` and `chat()`, where chat interactions keep a history of messages.
This might be useful if you want to use an agent that needs to remember previous interactions, like a chatbot that maintains context across multiple messages or a task manager that needs to track progress over time.

```python
response = agent.query("What is 2 times 2?")
```

Now we've gotten the basics, let's take a look at how we can use tools in our agents.

## Creating RAG Agents with QueryEngineTools

**Agentic RAG is a powerful way to use agents to answer questions about your data.** We can pass various tools to Alfred to help him answer questions.
However, instead of answering the question on top of documents automatically, Alfred can decide to use any other tool or flow to answer the question.

![Agentic RAG](https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/agentic-rag.png)

It is easy to **wrap `QueryEngine` as tools** for an agent.
When doing so, we need to **define a name and description within the `ToolMetadata`**. The LLM will use this information to correctly use the tool.
Let's see how to load in a `QueryEngineTool` using the `QueryEngine` we created in the [component section](02_components.mdx).

```python
from llama_index.core.tools import QueryEngineTool, ToolMetadata

query_engine = index.as_query_engine(similarity_top_k=3) # as shown in the previous section

query_engine_tool = QueryEngineTool(
query_engine=query_engine,
metadata=ToolMetadata(
name="a specific name",
description="a specific description",
),
return_direct=False,
)
query_engine_agent = ReActAgent.from_tools([query_engine_tool], llm=llm, verbose=True)
```

## Creating Multi-agent systems

**Agents in LlamaIndex can directly be used as tools** for other agents by loading them as a `QueryEngineTool`.

```python
from llama_index.core.tools import QueryEngineTool

query_engine_agent = # as defined in the previous section

query_engine_agent_tool = QueryEngineTool(
query_engine=query_engine_agent,
metadata=ToolMetadata(
name="a specific name",
description="a specific description",
),
)

multi_agent = ReActAgent.from_tools([query_engine_agent_tool], llm=llm, verbose=True)
```

<Tip>Haven't learned enough yet? There is a lot more to discover about agents and tools in LlamaIndex within the <a href="https://docs.llamaindex.ai/en/stable/module_guides/deploying/agents/modules/">Agent Component Guide</a> or the <a href="https://docs.llamaindex.ai/en/stable/understanding/agent/">Agent Learning Guide</a>.</Tip>

Now that we understand the basics of agents and tools in LlamaIndex, let's see how we can use LlamaIndex to **create configurable and manageable workflows!**
Loading