2024-11-26 Memgraph Webinar
Python: docs.llamaindex.ai
TypeScript: ts.llamaindex.ai
cloud.llamaindex.ai
Free for 1000 pages/day!
2. Get on the waitlist!
1. Sign up
Ways to do RAG #1:
Ways to do RAG #2:
Ways to do RAG #3:
Forms of graph RAG retrieval #1:
Forms of graph RAG retrieval #2:
Forms of graph RAG retrieval #3:
Naive RAG failure points #1:
Naive RAG failure points #2:
Naive RAG failure points #3:
⚠️ Single-shot
⚠️ No query understanding/planning
⚠️ No tool use
⚠️ No reflection, error correction
⚠️ No memory (stateless)
✅ Multi-turn
✅ Query / task planning layer
✅ Tool interface for external environment
✅ Reflection
✅ Memory for personalization
and then go further
Agentic strategies
Full agent
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)
class LoopExampleFlow(Workflow):
@step
async def answer_query(self, ev: StartEvent | QueryEvent ) -> FailedEvent | StopEvent:
query = ev.query
# try to answer the query
random_number = random.randint(0, 1)
if (random_number == 0):
return FailedEvent(error="Failed to answer the query.")
else:
return StopEvent(result="The answer to your query")
@step
async def improve_query(self, ev: FailedEvent) -> QueryEvent | StopEvent:
# improve the query or decide it can't be fixed
random_number = random.randint(0, 1)
if (random_number == 0):
return QueryEvent(query="Here's a better query.")
else:
return StopEvent(result="Your query can't be fixed.")
l = LoopExampleFlow(timeout=10, verbose=True)
result = await l.run(query="What's LlamaIndex?")
print(result)
draw_all_possible_flows()
class RAGWorkflow(Workflow):
@step
async def ingest(self, ctx: Context, ev: StartEvent) -> Optional[StopEvent]:
dataset_name = ev.dataset
documents = SimpleDirectoryReader("data").load_data()
ctx.set("INDEX", VectorStoreIndex.from_documents(documents=documents))
return StopEvent(result=f"Indexed {len(documents)} documents.")
...
class MyWorkflow(RAGWorkflow):
@step
def rerank(
self, ctx: Context, ev: Union[RetrieverEvent, StartEvent]
) -> Optional[QueryResult]:
# my custom reranking logic here
w = MyWorkflow(timeout=60, verbose=True)
result = await w.run(query="Who is Paul Graham?")
Follow me on BlueSky:
@seldo.com
Please don't add me on LinkedIn.