Build SELF-DISCOVER from Scratch with LlamaIndex
Key Takeaways
Implements the SELF-DISCOVER paper as a LlamaPack with LlamaIndex to demonstrate self-composed reasoning structures for LLMs
Full Transcript
hello everyone this is Raa developer Advocate engineer at Lama index in this video we'll look into implementing a recent paper which is self-discover uh large language model self composed reasoning structures as a Lama pack so let's start with understanding the approach and what this paper is about so basically uh self-discover is a general framework for llms or you can say prom flow strategy to self-discover the reasoning structures to solve a complex problem that are in general difficult with usual proing mechanism so basically it uses llms to select multiple reasoning modules from a large pool of reasoning modules which you can check towards the end of the paper to compose a reasoning structure for the llm to solve the task or the problem that uh is given to it so they showcased that the approach improves the gp4 and pal to performance on challenging Ben benchmarks by margin of 32% compared to CO2 methods so this is designed from a thought that we as humans if given a new problem we think U about what skills we already have from prayer experience and how can use those skills to solve the particular task or problem so the approach is basically divided into two stages um stage one and stage two basically the broader input is a task which we need to solve and the reasoning module um basically I said as I said uh there are uh some reasoning modules from which you select to solve the task right so these are the two inputs U for the whole process and then yeah let's start with the stage one process which has three modules to say which are select adapt and Implement so select chooses the relevant reasoning modules from a large pool of reasoning modules the paper use some 39 reasoning modules and then once you get a selected modules from the first part uh you sent it to adapt and based on this uh module certain modules reasoning modules refres those descriptions to be task specific and then finally um those rephrased ones are sended to the third part which is Implement which creates an execution plan from the adapted module descript ions uh which is something like a reasoning structure similar to a Json format and then in the stage two we basically give the task as well as this reasoning structure for the llm to solve the task and given an answer for the given task or the problem so now uh let's see how you can implement this in the Lama index as a Lama pack we will actually use Query pipeline to implement it um is a probably a simple sign of proms flow so let's uh see how you can do that essentially we have a task and reasoning modules as inputs and give them to a select prompt so basically in the select prompt we ask the llm to select some of these reasoning modules to solve this task and you basically get selected modules uh as an output and then we have an adapt prom uh for the given task and uh for these uh selected modules you send uh them to the llm and then refres the descriptions of these modules for the specific task and then you have an Implement prompt for which there is a task and send it to llm and get a reasoning structure and finally along with the reasoning structure for the specific task you basically generate an answer so these are the different parts of the the whole process and which is part of stage one and stage two so we'll see so the uh we'll implement this whole flow using query P plane um concept which is available in the Lama index take the input send it to the prompt or get a prompt template and send it to llm get the modules and then have an adap prompt uh send uh send the previous step input output as an input to the next one and continue with that process so you can find the uh the Lama pack file here and then uh so it basically contains a self discore pack and uh so that will have certainly some three more uh three functions get modules run and an IT function where you can initialize the llm and then uh the default reasoning modules and the veros so this the Run function has has basically you need to configure the pipeline as I said there are uh two stages and the first stage has three different parts which is Select adapt and Implement and the second stage is uh use the reasoning structure and for the task to generate an answer so the [Music] pipeline has a pipe uh all these parts to it so for the configuring the pipeline you basically set up the templates whatever we have discussed and then add these modules to it and set up the links and uh have the pipeline ready and once the pipeline is ready you basically give the task and the reasoning modules as a input and basically uh get the answer for the task so here if you can see um these are the templates you have uh select uh prompt template which has which takes task as well as reasoning modules as input and then adapt prom template which T takes uh the um task as well as selected modules from the previous step and the third one is the Implement PR template which takes uh um the adapted modules from the previous step and the task um and finally this is given to the final one the stage two one takes the reasoning structure and then task to give a final answer for the given task or the problem right so and then yeah the core the core has the all these modules here so there is an input component which takes the task and the reasoning modules as a high level input and you have llms for each of these parts like select llm adapt LM Implement LM and reasoning llm and all these uh prompt templates right right uh so we have all these modules available now so we just need to set up uh the links between all these modules that I have shown in earlier in the figure right so you start adding the links like what is the input for the promt template and which is Task and then the reasoning module as the input and you send the promt template to the llm okay and once you get whatever the output you get you basically send the selected modules to the adapt right adapt from template so um that's what you do here and then you even have you even send the task as well as the selected modules to the adapt R template and pass the adap prom template to the llm again and similar case with the Implement prom template you have the adapted uh modules and task to the Implement prom template andm get a reasoning structure and send the reasoning structure to the uh the final reasoning prom template to get an answer so that's how you configure the entire Pipeline and then you run it um by taking the task as well as uh reasoning modules so we have a Lama pack ready and then we'll use this llama pack to solve some of the task so we'll go through this notebook on how you can use the Lama pack to solve a task so we need llm for the for it uh we'll use the default one which is gp4 llm for it and then you can actually use the the Lama pack in two ways uh One downloading the Llama pack and then directly use the cell discard pack from the available llama packs so I'll go with the second option for now you can even test the first one so let's get the Lama pack and pass the LM um we can send the gp4 llm or any other llm you want to test it out but if you don't send any llm as an input um it directly uses the default GB 3.5 Taro as an llm and then uh we have some task defined here so one of the task is like U Michael has 15 oranges and he gives four oranges to his brother and trades three oranges for six apple with his neighbor later he disc got two of them and then goes to Market to buy 12 more oranges and five apples and decides to give two apples to his friend Fin and we want to know how many oranges and apples does Michael have at the end during this process so this is the task question and then we'll uh go through it so you can see how each of these things are running you have the input which is Task and reasoning modules and then send it to select prompt about the task and reasoning module to get a selected uh modules and then use that prompt template which takes the task as and selected modules as input and send it to the llm to get the uh rephrasing versions and then the Imp Implement prompt template as well uh and finally get an answer so so basically it has it the answer says like Michael initially has 15 oranges and zero apples and then after giving 4 oranges to his brother it has he has 11 oranges left and then he basically trade some apples and get uh for oranges and so each step um you basically do some operation and get a final answer that he has 18 oranges and N apples so that's how um it break down the whole problem into different steps and uh did some reasoning and got a final answer in the same way there is another task here where Tom buy some ingredients for dinner and um you want the estimate of uh the cost basically the cost for purchasing these items and so basically he pays with a $50 bill and what is the chain one needs to receive purchasing these items so in the similar way um the task reasoning modules and all these stages it goes through all these stages and finally gets an answer um the actually the time taken for Sol to solve the task depends on how complex the problem is because um the number of selected modules might be more based on the task so that's how you can see now this task is taking more time than the previous one um the previous one hardly took 27 seconds and this took uh more time right and so basically yeah it identified the problem and gathered the information broke down on the problem and did some thinking and solved the problem and uh reviewed that solution and got the changes like $31.5 so that's how you can use uh self-discover to solve a complex problem uh please explore this Lama pack and um see how you can use in your workflow uh see you in the next video with a new llama pack or any other new technique available thank you
Original Description
In this video we will look into implementing recent SELF-DISCOVER paper as LlamaPack with LlamaIndex.
OUTLINE:
00:00 - Introduction.
00:17 - SELF-DISCOVER Paper review.
03:06 - Implementation Overview with QueryPipeline.
04:30 - LlamaPack implementation.
08:12 - Notebook walkthrough of using LlamaPack.
Paper: https://arxiv.org/abs/2402.03620
LlamaPack: https://github.com/run-llama/llama_index/tree/main/llama-index-packs/llama-index-packs-self-discover
Notebook: https://github.com/run-llama/llama_index/blob/main/llama-index-packs/llama-index-packs-self-discover/examples/self_discover.ipynb
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from LlamaIndex · LlamaIndex · 55 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
▶
56
57
58
59
60
LlamaIndex Virtual Meetup (May 4th, 2023)
LlamaIndex
LlamaIndex + MongoDB Workshop/Fireside Chat
LlamaIndex
Discover LlamaIndex: Ask Complex Queries over Multiple Documents
LlamaIndex
Discover LlamaIndex: Document Management
LlamaIndex
Discover LlamaIndex: Joint Text to SQL and Semantic Search
LlamaIndex
Discover LlamaIndex: JSON Query Engine
LlamaIndex
LlamaIndex Webinar: Active Retrieval Augmented Generation
LlamaIndex
LlamaIndex Webinar: Demonstrate-Search-Predict (DSP) with Omar Khattab
LlamaIndex
LlamaIndex Sessions: Practical challenges of building a Legal Chatbot over your PDFs
LlamaIndex
LlamaIndex Webinar: Graph Databases, Knowledge Graphs, and RAG with Wey (NebulaGraph)
LlamaIndex
LlamaIndex Webinar: Community Project Showcase (07/07/2023)
LlamaIndex
LlamaIndex Webinar: LLMs for Investment Research (with Didier Lopes, co-founder/CEO at OpenBB)
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 1, LLMs and Prompts)
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 2, Documents and Metadata)
LlamaIndex
Discover LlamaIndex: Key Components to build QA Systems
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 3, Evaluation)
LlamaIndex
LlamaIndex Webinar: From Prompt to Schema Engineering with Pydantic (with @jxnlco)
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 4, Embeddings)
LlamaIndex
Discover LlamaIndex: Custom Retrievers + Hybrid Search
LlamaIndex
LlamaIndex Webinar: Document Metadata and Local Models for Better, Faster Retrieval
LlamaIndex
LlamaIndex Webinar: Build Personalized AI Characters with RealChar
LlamaIndex
LlamaIndex Webinar: Make RAG Production-Ready
LlamaIndex
LlamaIndex Workshop: Building RAG with Knowledge Graphs
LlamaIndex
Discover LlamaIndex: Introduction to Data Agents for Developers
LlamaIndex
LlamaIndex Webinar: Finetuning + RAG
LlamaIndex
Discover LlamaIndex: SEC Insights, End-to-End Guide
LlamaIndex
Discover LlamaIndex: Custom Tools for Data Agents
LlamaIndex
LlamaIndex Sessions: Building a Lending Criteria Chatbot in Production
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 5, Retrievers + Node Postprocessors)
LlamaIndex
LlamaIndex Webinar: How to Win a LLM Hackathon
LlamaIndex
LlamaIndex Webinar: LLM Challenges in Production (w/ Mayo Oshin, AI Jason, Dylan from Starmorph)
LlamaIndex
LlamaIndex Webinar: Agents Showcase!
LlamaIndex
LlamaIndex Webinar: Learn about DSPy
LlamaIndex
LlamaIndex Webinar: Time-based retrieval for RAG (with Timescale)
LlamaIndex
LlamaIndex Webinar: Build/Break/Test LLM Apps Showcase (co-hosted with TrueEra, Pinecone)
LlamaIndex
LlamaIndex Workshop: Evaluation-Driven Development (EDD)
LlamaIndex
LlamaIndex Webinar: Building LLM Apps for Production, Part 1 (co-hosted with Anyscale)
LlamaIndex
LlamaIndex Webinar: Learn about Fine-tuning + RAG (w/ Victoria Lin, author of RA-DIT)
LlamaIndex
LlamaIndex Webinar: What's next for AI after OpenAI Dev Day?
LlamaIndex
Introducing create-llama
LlamaIndex
LlamaIndex Webinar: PrivateGPT - Production RAG with Local Models
LlamaIndex
Multi-modal Retrieval Augmented Generation with LlamaIndex
LlamaIndex
LlamaIndex Webinar: LLaVa Deep Dive
LlamaIndex
A deep dive into Retrieval-Augmented Generation with Llamaindex
LlamaIndex
LlamaIndex Workshop: Multimodal + Advanced RAG Workhop with Gemini
LlamaIndex
LlamaIndex Webinar: Efficient Parallel Function Calling Agents with LLMCompiler
LlamaIndex
Introduction to Query Pipelines (Building Advanced RAG, Part 1)
LlamaIndex
LLMs for Advanced Question-Answering over Tabular/CSV/SQL Data (Building Advanced RAG, Part 2)
LlamaIndex
LlamaIndex Webinar: Advanced Tabular Data Understanding with LLMs
LlamaIndex
Ollama X LlamaIndex Multi-Modal
LlamaIndex
Build Agents from Scratch (Building Advanced RAG, Part 3)
LlamaIndex
LlamaIndex Webinar: Build No-Code RAG with Flowise
LlamaIndex
LlamaIndex Sessions: Practical Tips and Tricks for Productionizing RAG (feat. Sisil @ Jasper)
LlamaIndex
Introduction to LlamaIndex v0.10
LlamaIndex
Build SELF-DISCOVER from Scratch with LlamaIndex
LlamaIndex
Introducing LlamaCloud (and LlamaParse)
LlamaIndex
LlamaIndex Sessions: 12 RAG Pain Points and Solutions
LlamaIndex
LlamaIndex Webinar: RAG Beyond Basic Chatbots
LlamaIndex
A Comprehensive Cookbook for Claude 3
LlamaIndex
LlamaIndex Webinar: RAPTOR - Tree-Structured Indexing and Retrieval
LlamaIndex
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
On July 1, 2026, arXiv will spin out from Cornell University, its home for the past 25 years, to become an independent nonprofit organization. Major funding support from Simons Foundation and Schmidt Sciences. Ditching the red for their website. [N]
Reddit r/MachineLearning
CS-NRRM™ Official Publications: Paper 1 and Paper 2 Are Now Available
Medium · Data Science
Found a potential mistake in an ICLR 2026 blogpost [D]
Reddit r/MachineLearning
Rebuttals Move Peer-Review Scores, but Initial-Review Structure Bounds the Movement
ArXiv cs.AI
Chapters (5)
Introduction.
0:17
SELF-DISCOVER Paper review.
3:06
Implementation Overview with QueryPipeline.
4:30
LlamaPack implementation.
8:12
Notebook walkthrough of using LlamaPack.
🎓
Tutor Explanation
DeepCamp AI