Skip to content
Snippets Groups Projects
Unverified Commit fa40b365 authored by Marcus Schiesser's avatar Marcus Schiesser Committed by GitHub
Browse files

docs: cleanup (#1745)

parent da8068e9
No related branches found
No related tags found
No related merge requests found
Showing
with 38 additions and 52 deletions
---
title: Agent tutorial
title: 1. Setup
---
In this guide we'll walk you through the process of building an Agent in JavaScript using the LlamaIndex.TS library, starting from nothing and adding complexity in stages.
......
---
title: Create a basic agent
title: 2. Create a basic agent
---
We want to use `await` so we're going to wrap all of our code in a `main` function, like this:
......
---
title: Using a local model via Ollama
title: 3. Using a local model via Ollama
---
If you're happy using OpenAI, you can skip this section, but many people are interested in using models they run themselves. The easiest way to do this is via the great work of our friends at [Ollama](https://ollama.com/), who provide a simple to use client that will download, install and run a [growing range of models](https://ollama.com/library) for you.
......
---
title: Adding Retrieval-Augmented Generation (RAG)
title: 4. Adding Retrieval-Augmented Generation (RAG)
---
While an agent that can perform math is nifty (LLMs are usually not very good at math), LLM-based applications are always more interesting when they work with large amounts of data. In this case, we're going to use a 200-page PDF of the proposed budget of the city of San Francisco for fiscal years 2024-2024 and 2024-2025. It's a great example because it's extremely wordy and full of tables of figures, which present a challenge for humans and LLMs alike.
......@@ -87,32 +87,9 @@ By default LlamaIndex will retrieve just the 2 most relevant chunks of text. Thi
retriever.similarityTopK = 10;
```
### Approach 1: Create a Context-Aware Agent
### Use index.queryTool
With the retriever ready, you can create a **context-aware agent**.
```javascript
const agent = new OpenAIContextAwareAgent({
contextRetriever: retriever,
});
// Example query to the context-aware agent
let response = await agent.chat({
message: `What's the budget of San Francisco in 2023-2024?`,
});
console.log(response);
```
**Expected Output:**
```md
The total budget for the City and County of San Francisco for the fiscal year 2023-2024 is $14.6 billion. This represents a $611.8 million, or 4.4 percent, increase over the previous fiscal year's budget. The budget covers various expenditures across different departments and services, including significant allocations to public works, transportation, commerce, public protection, and health services.
```
### Approach 2: Using QueryEngineTool (Alternative Approach)
If you prefer more flexibility and don't mind additional complexity, you can create a `QueryEngineTool`. This approach allows you to define the query logic, providing a more tailored way to interact with the data, but note that it introduces a delay due to the extra tool call.
`index.queryTool` creates a `QueryEngineTool` that can be used be an agent to query data from the index.
```javascript
const tools = [
......@@ -125,9 +102,9 @@ const tools = [
];
// Create an agent using the tools array
const myAgent = agent({ tools });
const ragAgent = agent({ tools });
let toolResponse = await myAgent.run("What's the budget of San Francisco in 2023-2024?");
let toolResponse = await ragAgent.run("What's the budget of San Francisco in 2023-2024?");
console.log(toolResponse);
```
......@@ -155,10 +132,4 @@ console.log(toolResponse);
Once again we see a `toolResult`. You can see the query the LLM decided to send to the query engine ("total budget"), and the output the engine returned. In `response.message` you see that the LLM has returned the output from the tool almost verbatim, although it trimmed out the bit about 2024-2025 since we didn't ask about that year.
### Comparison of Approaches
The `OpenAIContextAwareAgent` approach simplifies the setup by allowing you to directly link the retriever to the agent, making it straightforward to access relevant context for your queries. This is ideal for situations where you want easy integration with existing data sources, like a context chat engine.
On the other hand, using the `QueryEngineTool` offers more flexibility and power. This method allows for customization in how queries are constructed and executed, enabling you to query data from various storages and process them in different ways. However, this added flexibility comes with increased complexity and response time due to the separate tool call and queryEngine generating tool output by LLM that is then passed to the agent.
So now we have an agent that can index complicated documents and answer questions about them. Let's [combine our math agent and our RAG agent](5_rag_and_tools)!
---
title: A RAG agent that does math
title: 5. A RAG agent that does math
---
In [our third iteration of the agent](https://github.com/run-llama/ts-agents/blob/main/3_rag_and_tools/agent.ts) we've combined the two previous agents, so we've defined both `sumNumbers` and a `QueryEngineTool` and created an array of two tools. The tools support both Zod and JSON Schema for parameter definition:
......
---
title: Adding LlamaParse
title: 6. Adding LlamaParse
---
Complicated PDFs can be very tricky for LLMs to understand. To help with this, LlamaIndex provides LlamaParse, a hosted service that parses complex documents including PDFs. To use it, get a `LLAMA_CLOUD_API_KEY` by [signing up for LlamaCloud](https://cloud.llamaindex.ai/) (it's free for up to 1000 pages/day) and adding it to your `.env` file just as you did for your OpenAI key:
......
---
title: Adding persistent vector storage
title: 7. Adding persistent vector storage
---
In the previous examples, we've been loading our data into memory each time we run the agent. This is fine for small datasets, but for larger datasets you'll want to store your embeddings in a database. LlamaIndex.TS provides a `VectorStore` class that can store your embeddings in a variety of databases. We're going to use [Qdrant](https://qdrant.tech/), a popular vector store, for this example.
......
{
"title": "Agents",
"title": "Agent with RAG",
"pages": [
"1_setup",
"2_create_agent",
......
---
title: Agent tutorial
title: Basic Agent
---
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
import CodeSource from "!raw-loader!../../../../../../../../examples/agent/openai";
import CodeSource from "!raw-loader!../../../../../../../examples/agent/openai";
We have a comprehensive, step-by-step [guide to building agents in LlamaIndex.TS](../../guides/agents/setup) that we recommend to learn what agents are and how to build them for production. But building a basic agent is simple:
We have a comprehensive, step-by-step [guide to building agents in LlamaIndex.TS](./agents/1_setup) that we recommend to learn what agents are and how to build them for production. But building a basic agent is simple:
## Set up
......
......@@ -4,7 +4,7 @@ title: Local LLMs
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
LlamaIndex.TS supports OpenAI and [other remote LLM APIs](other_llms). You can also run a local LLM on your machine!
LlamaIndex.TS supports OpenAI and [other remote LLM APIs](/docs/llamaindex/modules/llms). You can also run a local LLM on your machine!
## Using a local model via Ollama
......@@ -45,7 +45,10 @@ To switch the LLM in your code, you first need to make sure to install the packa
Then, to tell LlamaIndex to use a local LLM, use the `Settings` object:
```javascript
Settings.llm = new Ollama({
import { Settings } from "llamaindex";
import { ollama } from "@llamaindex/ollama";
Settings.llm = ollama({
model: "mixtral:8x7b",
});
```
......
{
"title": "Tutorials",
"pages": [
"rag",
"basic_agent",
"agents",
"workflow",
"local_llm",
"chatbot",
"structured_data_extraction"
]
}
......@@ -16,7 +16,7 @@ LlamaIndex uses a two stage method when using an LLM with your data:
1. **indexing stage**: preparing a knowledge base, and
2. **querying stage**: retrieving relevant context from the knowledge to assist the LLM in responding to a question
![](../_static/concepts/rag.jpg)
![](./_static/concepts/rag.jpg)
This process is also known as Retrieval Augmented Generation (RAG).
......@@ -28,7 +28,7 @@ Let's explore each stage in detail.
LlamaIndex.TS help you prepare the knowledge base with a suite of data connectors and indexes.
![](../_static/concepts/indexing.jpg)
![](./_static/concepts/indexing.jpg)
[**Data Loaders**](/docs/llamaindex/modules/data_loaders/index):
A data connector (i.e. `Reader`) ingest data from different data sources and data formats into a simple `Document` representation (text and simple metadata).
......@@ -54,7 +54,7 @@ LlamaIndex provides composable modules that help you build and integrate RAG pip
These building blocks can be customized to reflect ranking preferences, as well as composed to reason over multiple knowledge bases in a structured way.
![](../_static/concepts/querying.jpg)
![](./_static/concepts/querying.jpg)
#### Building Blocks
......
---
title: Retrieval Augmented Generation (RAG) Tutorial
title: Retrieval Augmented Generation (RAG)
---
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
import CodeSource from "!raw-loader!../../../../../../../../examples/vectorIndex";
import TSConfigSource from "!!raw-loader!../../../../../../../../examples/tsconfig.json";
One of the most common use-cases for LlamaIndex is Retrieval-Augmented Generation or RAG, in which your data is indexed and selectively retrieved to be given to an LLM as source material for responding to a query. You can learn more about the [concepts behind RAG](../concepts).
One of the most common use-cases for LlamaIndex is Retrieval-Augmented Generation or RAG, in which your data is indexed and selectively retrieved to be given to an LLM as source material for responding to a query. You can learn more about the [concepts behind RAG](./rag/concepts).
## Set up the project
......@@ -19,7 +19,7 @@ npm install -D typescript @types/node
Then, check out the [installation](../setup) steps to install LlamaIndex.TS and prepare an OpenAI key.
You can use [other LLMs](../../examples/other_llms) via their APIs; if you would prefer to use local models check out our [local LLM example](../../examples/local_llm).
You can use [other LLMs](/docs/llamaindex/modules/llms) via their APIs; if you would prefer to use local models check out our [local LLM example](./local_llm).
## Run queries
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment