Welcome to the LlamaIndex

RAG-a-thon!

2024-10-11 LlamaIndex hackathon

Topics

  • What is LlamaIndex?
  • What can it help me do?
  • Tips for winning this hackathon
  • Example project ideas
  • All the resources you need

What is LlamaIndex?

Python: docs.llamaindex.ai

TypeScript: ts.llamaindex.ai

LlamaHub

llamahub.ai

  • Data loaders
  • Embedding models
  • Vector stores
  • LLMs
  • Agent tools
  • Pre-built strategies
  • More!

LlamaParse

Free for 1000 pages/day!

LlamaCloud

2. Get on the waitlist!

bit.ly/llamacloud-waitlist

1. Sign up:

3. Email info@llamaindex.ai

with the email address you used to sign up

Why LlamaIndex?

  • Build faster
  • Skip the boilerplate
  • Avoid early pitfalls
  • Get best practices for free
  • Go from prototype to production

What can LlamaIndex

do for me?

RAG

What can LlamaIndex do: #1

RAG with LlamaCloud

from llama_index.indices.managed.llama_cloud import LlamaCloudIndex
# pip install llama-index-indices-managed-llama-cloud

index = LlamaCloudIndex(
  name="My Index", 
  project_name="My Project",
  organization_id="e793a802-cb91-4e6a-bd49-61d0ba2ac5f9",
  api_key="llx-..."
)

# retrieve nodes
nodes = index.as_retriever().retrieve(query)
# or use as a query engine
response = index.as_query_engine().query(query)

5 line starter

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

documents = SimpleDirectoryReader("data").load_data()

index = VectorStoreIndex.from_documents(documents)

query_engine = index.as_query_engine()

response = query_engine.query("What did the author do growing up?")

print(response)

RAG is necessary

but not sufficient

Agents

What can LlamaIndex do: #2

Query engine as a tool

# set up list of tools
tools = [
    QueryEngineTool(
        query_engine=vector_query_engine,
        metadata=ToolMetadata(
            # this is how the LLM knows what the tool does
            name="pg_essay",
            description="Paul Graham essay on What I Worked On",
        ),
    ),
    # more query engines or other tools go here
]

Arbitrary code as a tool

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

multiply_tool = FunctionTool.from_defaults(fn=multiply)

# initialize ReAct agent
agent = ReActAgent.from_tools(
  [
    multiply_tool
    # other tools here
  ], 
  verbose=True
)

Tools from LlamaHub

from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec

tool_spec = DuckDuckGoSearchToolSpec()

# initialize ReAct agent
# with a list of tools from the spec
agent = ReActAgent.from_tools(
  DuckDuckGoSearchToolSpec.to_tool_list(),
  verbose=True
)

Agents in LlamaIndex

Agent built-ins

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

# OR structured planner agent
worker = FunctionCallingAgentWorker.from_tools(
    [lyft_tool, uber_tool], verbose=True
)
agent = StructuredPlannerAgent(
    worker, tools=[lyft_tool, uber_tool], verbose=True
)

# OR language agent tree search
worker = LATSAgentWorker.from_tools(
    query_engine_tools,
    llm=llm,
    num_expansions=2,
    max_rollouts=3,
    verbose=True,
)
agent = worker.as_agent()

Workflows

What can LlamaIndex do: #3

Basic workflow

from llama_index.llms.openai import OpenAI

class OpenAIGenerator(Workflow):
    @step()
    async def generate(self, ev: StartEvent) -> StopEvent:
        query = ev.get("query")
        llm = OpenAI()
        response = await llm.acomplete(query)
        return StopEvent(result=str(response))

w = OpenAIGenerator(timeout=10, verbose=False)
result = await w.run(query="What's LlamaIndex?")
print(result)

Visualization

draw_all_possible_flows()

Deploy

What can LlamaIndex do: #4

What LlamaIndex doesn't do

It's not a front-end library!

npx create-llama

More front-end options

What we're

looking for 

Use LlamaIndex

Tips for winning #1

LlamaCloud

not required

Tips for winning #2

Agentic strategies

Tips for winning #3

Workflows will help

Tips for winning #4

More than a chatbot

Tips for winning #5

Use custom models

Tips for winning #6

Go multi-modal

Tips for winning #7

Example projects

Human in the loop demo

Full stack python app

App creator using O1

Multi-agent concierge

PowerPoint generator

Newsletter generator

File organizer

Gmail regex writer

Realtime audio with OpenAI

Resources

  • All of these slides
  • Getting started guide
  • Tutorials
  • Documentation
  • Example projects
  • LlamaIndex Discord

Welcome to the LlamaIndex hackathon

By seldo

Welcome to the LlamaIndex hackathon

  • 190