mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-02 20:13:52 -04:00
Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 768d99a488 | |||
| b4c55319da | |||
| d3a8b764f0 | |||
| 676e3f8993 | |||
| 7283909755 | |||
| 19e5c318a0 | |||
| d49301555f | |||
| f648bb7b90 | |||
| 06f884a437 | |||
| 9e66861d07 | |||
| ae74f70d7d | |||
| 5b4a53177e | |||
| 5da1cda939 | |||
| 1285e381bd | |||
| 5d5cd44276 | |||
| ed37c645af | |||
| c40adafecc | |||
| 995b465205 | |||
| 8929dcf1dd | |||
| af0b79f1cd | |||
| 1995b38660 | |||
| 001a5159cf | |||
| 9d7d2052e7 | |||
| fd90e25f0e | |||
| 97c00d67c3 | |||
| 6ebd7c2f13 | |||
| 0267bb0e8e | |||
| 7875ee91e6 | |||
| e3405fca44 | |||
| f3bc2b61e7 | |||
| 4c703767b7 | |||
| a27648200d | |||
| c93bb02002 | |||
| e9ded4e65f | |||
| 47a6f5fe5a | |||
| b80f33e264 | |||
| b6409b6823 | |||
| db3f556cb4 | |||
| 4b5179169b | |||
| 971d37ceba | |||
| 3e0ffdc688 | |||
| 049471bade | |||
| 1e296ebe72 | |||
| f9f1de9516 | |||
| f576812e7a | |||
| c3bf3c7178 | |||
| 38487da65d | |||
| f29799e385 | |||
| 9bca30620b | |||
| 7224c06409 | |||
| 29c7cf0989 | |||
| c65a2dc4a7 | |||
| f1c5079290 | |||
| 9ed31958a7 |
@@ -0,0 +1,13 @@
|
||||
name: Trigger Vercel Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Trigger Vercel deployment
|
||||
run: |
|
||||
curl -X POST "${{ secrets.DEVELOPER_HUB_DEPLOY_HOOK }}"
|
||||
@@ -105,6 +105,7 @@ jobs:
|
||||
run: |
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C packages/llamaindex
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C packages/workflow
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C packages/core
|
||||
- name: Install packed packages
|
||||
run: npm add ${{ runner.temp }}/*.tgz
|
||||
working-directory: e2e/npm
|
||||
@@ -121,7 +122,6 @@ jobs:
|
||||
- nextjs-edge-runtime
|
||||
- nextjs-node-runtime
|
||||
- waku-query-engine
|
||||
- llama-parse-browser
|
||||
- vite-import-llamaindex
|
||||
runs-on: ubuntu-latest
|
||||
name: Build LlamaIndex Example (${{ matrix.packages }})
|
||||
@@ -162,7 +162,7 @@ jobs:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
directory: e2e/examples/vite-import-llamaindex
|
||||
skip_step: "install"
|
||||
build_script: build
|
||||
build_script: ci-build
|
||||
package_manager: pnpm
|
||||
|
||||
typecheck-examples:
|
||||
@@ -203,7 +203,7 @@ jobs:
|
||||
fi
|
||||
done
|
||||
- name: Install
|
||||
run: npm add ${{ runner.temp }}/*.tgz
|
||||
run: npm add ${{ runner.temp }}/*.tgz --legacy-peer-deps
|
||||
working-directory: ${{ runner.temp }}/examples
|
||||
- name: Run Type Check
|
||||
run: npx tsc --project ./tsconfig.json
|
||||
|
||||
@@ -1,5 +1,131 @@
|
||||
# @llamaindex/doc
|
||||
|
||||
## 0.2.56
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- b4c5531: Add initial sonnet 4.5 support
|
||||
|
||||
## 0.2.55
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [06f884a]
|
||||
- Updated dependencies [d493015]
|
||||
- @llamaindex/core@0.6.22
|
||||
- @llamaindex/workflow@1.1.24
|
||||
- llamaindex@0.12.0
|
||||
- @llamaindex/node-parser@2.0.22
|
||||
- @llamaindex/openai@0.4.20
|
||||
- @llamaindex/readers@3.1.21
|
||||
|
||||
## 0.2.54
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ed37c64: Addition of APAC_ANTHROPIC_CLAUDE_4_SONNET type/record in @llamaindex/aws for APAC support for claude 4 sonnet per issue 2184.
|
||||
- Updated dependencies [8929dcf]
|
||||
- Updated dependencies [5da1cda]
|
||||
- llamaindex@0.11.29
|
||||
- @llamaindex/core@0.6.21
|
||||
- @llamaindex/workflow@1.1.23
|
||||
- @llamaindex/openai@0.4.19
|
||||
- @llamaindex/cloud@4.1.3
|
||||
- @llamaindex/node-parser@2.0.21
|
||||
- @llamaindex/readers@3.1.20
|
||||
|
||||
## 0.2.53
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1995b38]
|
||||
- Updated dependencies [001a515]
|
||||
- Updated dependencies [9d7d205]
|
||||
- @llamaindex/workflow@1.1.22
|
||||
- @llamaindex/openai@0.4.18
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.2.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0267bb0]
|
||||
- @llamaindex/core@0.6.20
|
||||
- @llamaindex/cloud@4.1.2
|
||||
- llamaindex@0.11.27
|
||||
- @llamaindex/node-parser@2.0.20
|
||||
- @llamaindex/openai@0.4.17
|
||||
- @llamaindex/readers@3.1.19
|
||||
- @llamaindex/workflow@1.1.21
|
||||
|
||||
## 0.2.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4c70376]
|
||||
- @llamaindex/openai@0.4.16
|
||||
|
||||
## 0.2.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b6409b6]
|
||||
- @llamaindex/openai@0.4.15
|
||||
|
||||
## 0.2.49
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [4b51791]
|
||||
- @llamaindex/cloud@4.1.1
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.2.48
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- Updated dependencies [049471b]
|
||||
- @llamaindex/cloud@4.1.0
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.2.47
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [c3bf3c7]
|
||||
- Updated dependencies [f9f1de9]
|
||||
- @llamaindex/cloud@4.0.28
|
||||
- @llamaindex/core@0.6.19
|
||||
- llamaindex@0.11.24
|
||||
- @llamaindex/node-parser@2.0.19
|
||||
- @llamaindex/openai@0.4.14
|
||||
- @llamaindex/readers@3.1.18
|
||||
- @llamaindex/workflow@1.1.20
|
||||
|
||||
## 0.2.46
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [f29799e]
|
||||
- Updated dependencies [7224c06]
|
||||
- @llamaindex/workflow@1.1.19
|
||||
- @llamaindex/core@0.6.18
|
||||
- llamaindex@0.11.23
|
||||
- @llamaindex/cloud@4.0.27
|
||||
- @llamaindex/node-parser@2.0.18
|
||||
- @llamaindex/openai@0.4.13
|
||||
- @llamaindex/readers@3.1.17
|
||||
|
||||
## 0.2.45
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [9ed3195]
|
||||
- @llamaindex/workflow@1.1.18
|
||||
- llamaindex@0.11.22
|
||||
|
||||
## 0.2.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.2.44",
|
||||
"version": "0.2.56",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "fumadocs-mdx",
|
||||
@@ -15,14 +15,14 @@
|
||||
"dependencies": {
|
||||
"@huggingface/transformers": "^3.5.0",
|
||||
"@icons-pack/react-simple-icons": "^10.1.0",
|
||||
"@llamaindex/chat-ui-docs": "^0.0.5",
|
||||
"@llamaindex/cloud": "workspace:*",
|
||||
"@llamaindex/chat-ui-docs": "^0.1.0",
|
||||
"llama-cloud-services": "^0.3.5",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/node-parser": "workspace:*",
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"@llamaindex/readers": "workspace:*",
|
||||
"@llamaindex/workflow": "workspace:*",
|
||||
"@llamaindex/workflow-docs": "0.1.1",
|
||||
"@llamaindex/workflow-docs": "0.1.4",
|
||||
"@mdx-js/mdx": "^3.1.0",
|
||||
"@monaco-editor/react": "^4.7.0",
|
||||
"@next/third-parties": "^15.3.4",
|
||||
@@ -50,7 +50,7 @@
|
||||
"hast-util-to-jsx-runtime": "^2.3.2",
|
||||
"llamaindex": "workspace:*",
|
||||
"lucide-react": "^0.460.0",
|
||||
"next": "^15.3.3",
|
||||
"next": "^15.4.7",
|
||||
"next-themes": "^0.4.3",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
@@ -1,8 +1,8 @@
|
||||
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "@llamaindex/cloud/api";
|
||||
import fg from "fast-glob";
|
||||
import { fileGenerator, remarkDocGen, remarkInstall } from "fumadocs-docgen";
|
||||
import { remarkAutoTypeTable } from "fumadocs-typescript";
|
||||
import matter from "gray-matter";
|
||||
import { upsertBatchPipelineDocumentsApiV1PipelinesPipelineIdDocumentsPut } from "llama-cloud-services/api";
|
||||
import * as fs from "node:fs/promises";
|
||||
import path, { relative } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
import { ClientMDXContent } from "@/components/mdx";
|
||||
import { BotMessage } from "@/components/message";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { LlamaCloudRetriever } from "@/deps/cloud";
|
||||
import { ContextChatEngine } from "@llamaindex/core/chat-engine";
|
||||
import { Settings } from "@llamaindex/core/global";
|
||||
import { ChatMessage } from "@llamaindex/core/llms";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { createAI, createStreamableUI, getMutableAIState } from "ai/rsc";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
Settings.llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
});
|
||||
|
||||
const retriever = new LlamaCloudRetriever({
|
||||
apiKey: process.env.LLAMA_CLOUD_API_KEY!,
|
||||
baseUrl: "https://api.cloud.llamaindex.ai/",
|
||||
|
||||
pipelineId: process.env.LLAMA_CLOUD_PIPELINE_ID!,
|
||||
});
|
||||
|
||||
const initialAIState = {
|
||||
messages: [],
|
||||
} as {
|
||||
messages: ChatMessage[];
|
||||
};
|
||||
|
||||
export type UIMessage = {
|
||||
id: number;
|
||||
display: ReactNode;
|
||||
};
|
||||
|
||||
const initialUIState = {
|
||||
messages: [],
|
||||
} as {
|
||||
messages: UIMessage[];
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const runAsyncFnWithoutBlocking = (fn: (...args: any) => Promise<any>) => {
|
||||
fn().catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
export const AIProvider = createAI({
|
||||
initialAIState,
|
||||
initialUIState,
|
||||
actions: {
|
||||
query: async (message: string): Promise<UIMessage> => {
|
||||
"use server";
|
||||
const chatEngine = new ContextChatEngine({ retriever });
|
||||
|
||||
const id = Date.now();
|
||||
const aiState = getMutableAIState<typeof AIProvider>();
|
||||
aiState.update({
|
||||
...aiState.get(),
|
||||
messages: [
|
||||
...aiState.get().messages,
|
||||
{
|
||||
role: "user",
|
||||
content: message,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const ui = createStreamableUI(
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-full" />
|
||||
</div>,
|
||||
);
|
||||
|
||||
runAsyncFnWithoutBlocking(async () => {
|
||||
const response = await chatEngine.chat({
|
||||
message,
|
||||
chatHistory: aiState.get().messages,
|
||||
stream: true,
|
||||
});
|
||||
|
||||
let content = "";
|
||||
|
||||
for await (const { delta } of response) {
|
||||
content += delta;
|
||||
ui.update(<ClientMDXContent id={id} content={content} />);
|
||||
}
|
||||
|
||||
ui.done();
|
||||
|
||||
aiState.done({
|
||||
...aiState.get(),
|
||||
messages: [
|
||||
...aiState.get().messages,
|
||||
{
|
||||
role: "assistant",
|
||||
content,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
display: <BotMessage>{ui.value}</BotMessage>,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AIProvider } from "@/actions";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { GoogleAnalytics, GoogleTagManager } from "@next/third-parties/google";
|
||||
import { RootProvider } from "fumadocs-ui/provider";
|
||||
@@ -39,9 +38,7 @@ export default function Layout({ children }: { children: ReactNode }) {
|
||||
<GoogleTagManager gtmId="GTM-WWRFB36R" />
|
||||
<body className="flex min-h-screen flex-col">
|
||||
<TooltipProvider>
|
||||
<AIProvider>
|
||||
<RootProvider>{children}</RootProvider>
|
||||
</AIProvider>
|
||||
<RootProvider>{children}</RootProvider>
|
||||
</TooltipProvider>
|
||||
</body>
|
||||
<GoogleAnalytics gaId="G-NB9B8LW9W5" />
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
"use client";
|
||||
import type { AIProvider, UIMessage } from "@/actions";
|
||||
import { UserMessage } from "@/components/message";
|
||||
import { useActions, useUIState } from "ai/rsc";
|
||||
import { Info } from "lucide-react";
|
||||
import { ButtonHTMLAttributes, useState } from "react";
|
||||
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "./ui/dialog";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
||||
|
||||
type AITriggerProps = ButtonHTMLAttributes<HTMLButtonElement>;
|
||||
|
||||
function ChatList({ messages }: { messages: UIMessage[] }) {
|
||||
if (messages.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative mx-auto w-full px-4">
|
||||
{messages.map((message, index) => (
|
||||
<div key={index} className="pb-4">
|
||||
{message.display}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const AITrigger = (props: AITriggerProps) => {
|
||||
const [{ messages }, setUIState] = useUIState<typeof AIProvider>();
|
||||
const { query } = useActions<typeof AIProvider>();
|
||||
const [inputValue, setInputValue] = useState("");
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger {...props} />
|
||||
<DialogPortal>
|
||||
<DialogOverlay className="bg-fd-background/50 data-[state=closed]:animate-fd-fade-out data-[state=open]:animate-fd-fade-in fixed inset-0 z-50 backdrop-blur-sm" />
|
||||
<DialogContent
|
||||
onOpenAutoFocus={(e) => {
|
||||
document.getElementById("nd-ai-input")?.focus();
|
||||
e.preventDefault();
|
||||
}}
|
||||
className="bg-fd-popover text-fd-popover-foreground data-[state=closed]:animate-fd-dialog-out data-[state=open]:animate-fd-dialog-in fixed left-1/2 z-50 my-[5vh] flex max-h-[90dvh] w-[98vw] max-w-[860px] origin-left -translate-x-1/2 flex-col rounded-lg border shadow-lg focus-visible:outline-none"
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="sr-only">Search AI</DialogTitle>
|
||||
<DialogDescription className="sr-only">
|
||||
Ask AI some questions.
|
||||
</DialogDescription>
|
||||
<Alert>
|
||||
<Info className="size-4" />
|
||||
<AlertTitle>Heads up!</AlertTitle>
|
||||
<AlertDescription>
|
||||
Answers from LlamaCloud may be inaccurate, please use with
|
||||
discretion.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</DialogHeader>
|
||||
<div className="mt-4 flex-grow overflow-scroll">
|
||||
<ChatList messages={messages} />
|
||||
</div>
|
||||
<form
|
||||
className="space-y-4 px-4 py-2"
|
||||
action={async () => {
|
||||
const value = inputValue.trim();
|
||||
setInputValue("");
|
||||
if (!value) return;
|
||||
|
||||
// Add user message UI
|
||||
setUIState((state) => ({
|
||||
...state,
|
||||
messages: [
|
||||
...state.messages,
|
||||
{
|
||||
id: Date.now(),
|
||||
display: <UserMessage>{value}</UserMessage>,
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
try {
|
||||
// Submit and get response message
|
||||
const responseMessage = await query(value);
|
||||
setUIState((state) => ({
|
||||
...state,
|
||||
messages: [...state.messages, responseMessage],
|
||||
}));
|
||||
} catch (error) {
|
||||
// You may want to show a toast or trigger an error state.
|
||||
console.error(error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full flex-row items-center gap-2">
|
||||
<Textarea
|
||||
tabIndex={0}
|
||||
placeholder="Ask AI about documentation."
|
||||
className="w-full resize-none bg-transparent px-4 focus-within:outline-none sm:text-sm"
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
event.currentTarget.form?.requestSubmit(null);
|
||||
}
|
||||
}}
|
||||
autoFocus
|
||||
spellCheck={false}
|
||||
autoComplete="off"
|
||||
autoCorrect="off"
|
||||
name="message"
|
||||
rows={1}
|
||||
value={inputValue}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
/>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="submit"
|
||||
size="icon"
|
||||
disabled={inputValue === ""}
|
||||
>
|
||||
<span className="sr-only">Send message</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Send message</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</DialogPortal>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Getting Started
|
||||
collapsed: true
|
||||
@@ -21,7 +21,7 @@ While the definition of an agentic application is broad, there are several key c
|
||||
- **Orchestration**: A hierarchical structure of LLMs is used to orchestrate lower-level actions and LLMs.
|
||||
- **Reflection**: The LLM is used to reflect and validate outputs of previous steps or LLM calls, which can be used to guide the application to the next appropriate step or state.
|
||||
|
||||
In LlamaIndex, you can build agentic applications by using the workflows to orchestrate a sequence of steps and LLMs. You can [learn more about workflows](/docs/llamaindex/tutorials/workflows).
|
||||
In LlamaIndex, you can build agentic applications by using the workflows to orchestrate a sequence of steps and LLMs. You can [learn more about workflows](/typescript/framework/tutorials/workflows).
|
||||
|
||||
## Agents
|
||||
|
||||
@@ -34,27 +34,27 @@ What this means in practice, is something like:
|
||||
- If tools are used, the agent will then interpret the tool outputs and use them to inform the next action
|
||||
- Once the agent stops taking actions, it returns the final output to the user
|
||||
|
||||
You can [learn more about agents](/docs/llamaindex/tutorials/basic_agent).
|
||||
You can [learn more about agents](/typescript/framework/tutorials/basic_agent).
|
||||
|
||||
## Retrieval Augmented Generation (RAG)
|
||||
|
||||
Retrieval-Augmented Generation (RAG) is a core technique for building data-backed LLM applications with LlamaIndex. It allows LLMs to answer questions about your private data by providing it to the LLM at query time, rather than training the LLM on your data. To avoid sending **all** of your data to the LLM every time, RAG indexes your data and selectively sends only the relevant parts along with your query. You can [learn more about RAG](/docs/llamaindex/tutorials/rag).
|
||||
Retrieval-Augmented Generation (RAG) is a core technique for building data-backed LLM applications with LlamaIndex. It allows LLMs to answer questions about your private data by providing it to the LLM at query time, rather than training the LLM on your data. To avoid sending **all** of your data to the LLM every time, RAG indexes your data and selectively sends only the relevant parts along with your query. You can [learn more about RAG](/typescript/framework/tutorials/rag).
|
||||
|
||||
## Use cases
|
||||
|
||||
There are endless use cases for data-backed LLM applications but they can be roughly grouped into four categories:
|
||||
|
||||
[**Agents**](/docs/llamaindex/tutorials/basic_agent):
|
||||
An agent is an automated decision-maker powered by an LLM that interacts with the world via a set of [tools](/docs/llamaindex/modules/agents/tool). Agents can take an arbitrary number of steps to complete a given task, dynamically deciding on the best course of action rather than following pre-determined steps. This gives it additional flexibility to tackle more complex tasks.
|
||||
[**Agents**](/typescript/framework/tutorials/basic_agent):
|
||||
An agent is an automated decision-maker powered by an LLM that interacts with the world via a set of [tools](/typescript/framework/modules/agents/tool). Agents can take an arbitrary number of steps to complete a given task, dynamically deciding on the best course of action rather than following pre-determined steps. This gives it additional flexibility to tackle more complex tasks.
|
||||
|
||||
[**Workflows**](/docs/llamaindex/tutorials/workflows):
|
||||
[**Workflows**](/typescript/framework/tutorials/workflows):
|
||||
A Workflow in LlamaIndex is a specific event-driven abstraction that allows you to orchestrate a sequence of steps and LLMs calls. Workflows can be used to implement any agentic application, and are a core component of LlamaIndex.
|
||||
|
||||
[**Structured Data Extraction**](/docs/llamaindex/tutorials/structured_data_extraction):
|
||||
[**Structured Data Extraction**](/typescript/framework/tutorials/structured_data_extraction):
|
||||
Pydantic extractors allow you to specify a precise data structure to extract from your data and use LLMs to fill in the missing pieces in a type-safe way. This is useful for extracting structured data from unstructured sources like PDFs, websites, and more, and is key to automating workflows.
|
||||
|
||||
[**Query Engines**](/docs/llamaindex/modules/rag/query_engines):
|
||||
[**Query Engines**](/typescript/framework/modules/rag/query_engines):
|
||||
A query engine is an end-to-end flow that allows you to ask questions over your data. It takes in a natural language query, and returns a response, along with reference context retrieved and passed to the LLM.
|
||||
|
||||
[**Chat Engines**](/docs/llamaindex/modules/rag/chat_engine):
|
||||
[**Chat Engines**](/typescript/framework/modules/rag/chat_engine):
|
||||
A chat engine is an end-to-end flow for having a conversation with your data (multiple back-and-forth instead of a single question-and-answer).
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Installation
|
||||
collapsed: true
|
||||
@@ -138,28 +138,28 @@ Choose your deployment target:
|
||||
<Card
|
||||
title="Server APIs & Backends"
|
||||
description="Express, Fastify, Koa, standalone Node.js servers"
|
||||
href="/docs/llamaindex/getting_started/installation/server-apis"
|
||||
href="/typescript/framework/getting_started/installation/server-apis"
|
||||
/>
|
||||
<Card
|
||||
title="Serverless Functions"
|
||||
description="Vercel, Netlify, AWS Lambda, Cloudflare Workers"
|
||||
href="/docs/llamaindex/getting_started/installation/serverless"
|
||||
href="/typescript/framework/getting_started/installation/serverless"
|
||||
/>
|
||||
<Card
|
||||
title="Next.js Applications"
|
||||
description="API routes, server components, edge runtime"
|
||||
href="/docs/llamaindex/getting_started/installation/nextjs"
|
||||
href="/typescript/framework/getting_started/installation/nextjs"
|
||||
/>
|
||||
<Card
|
||||
title="Troubleshooting"
|
||||
description="Common issues, bundle optimization, compatibility"
|
||||
href="/docs/llamaindex/getting_started/installation/troubleshooting"
|
||||
href="/typescript/framework/getting_started/installation/troubleshooting"
|
||||
/>
|
||||
</Cards>
|
||||
|
||||
## LLM/Embedding Providers
|
||||
|
||||
Go to [LLM APIs](/docs/llamaindex/modules/models/llms) and [Embedding APIs](/docs/llamaindex/modules/models/embeddings) to find out how to use different LLM and embedding providers beyond OpenAI.
|
||||
Go to [LLM APIs](/typescript/framework/modules/models/llms) and [Embedding APIs](/typescript/framework/modules/models/embeddings) to find out how to use different LLM and embedding providers beyond OpenAI.
|
||||
|
||||
## What's Next?
|
||||
|
||||
@@ -167,11 +167,11 @@ Go to [LLM APIs](/docs/llamaindex/modules/models/llms) and [Embedding APIs](/doc
|
||||
<Card
|
||||
title="Learn LlamaIndex.TS"
|
||||
description="Learn how to use LlamaIndex.TS by starting with one of our tutorials."
|
||||
href="/docs/llamaindex/tutorials/basic_agent"
|
||||
href="/typescript/framework/tutorials/basic_agent"
|
||||
/>
|
||||
<Card
|
||||
title="Show me code examples"
|
||||
description="Explore code examples using LlamaIndex.TS."
|
||||
href="/docs/llamaindex/getting_started/examples"
|
||||
href="/typescript/framework/getting_started/examples"
|
||||
/>
|
||||
</Cards>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "Installation",
|
||||
"pages": ["server-apis", "serverless", "nextjs", "troubleshooting"]
|
||||
}
|
||||
@@ -400,6 +400,6 @@ export default function ChatInterface() {
|
||||
|
||||
## Next Steps
|
||||
|
||||
- Learn about [serverless deployment](/docs/llamaindex/getting_started/installation/serverless)
|
||||
- Explore [server APIs](/docs/llamaindex/getting_started/installation/server-apis)
|
||||
- Check [troubleshooting guide](/docs/llamaindex/getting_started/installation/troubleshooting) for common issues
|
||||
- Learn about [serverless deployment](/typescript/framework/getting_started/installation/serverless)
|
||||
- Explore [server APIs](/typescript/framework/getting_started/installation/server-apis)
|
||||
- Check [troubleshooting guide](/typescript/framework/getting_started/installation/troubleshooting) for common issues
|
||||
@@ -206,6 +206,6 @@ app.post('/api/chat-stream', async (req, res) => {
|
||||
|
||||
## Next Steps
|
||||
|
||||
- Learn about [serverless deployment](/docs/llamaindex/getting_started/installation/serverless)
|
||||
- Explore [Next.js integration](/docs/llamaindex/getting_started/installation/nextjs)
|
||||
- Check [troubleshooting guide](/docs/llamaindex/getting_started/installation/troubleshooting) for common issues
|
||||
- Learn about [serverless deployment](/typescript/framework/getting_started/installation/serverless)
|
||||
- Explore [Next.js integration](/typescript/framework/getting_started/installation/nextjs)
|
||||
- Check [troubleshooting guide](/typescript/framework/getting_started/installation/troubleshooting) for common issues
|
||||
@@ -235,6 +235,6 @@ export const handler: Handler = async (event, context) => {
|
||||
|
||||
## Next Steps
|
||||
|
||||
- Learn about [Next.js integration](/docs/llamaindex/getting_started/installation/nextjs)
|
||||
- Explore [server deployment](/docs/llamaindex/getting_started/installation/server-apis)
|
||||
- Check [troubleshooting guide](/docs/llamaindex/getting_started/installation/troubleshooting) for common issues
|
||||
- Learn about [Next.js integration](/typescript/framework/getting_started/installation/nextjs)
|
||||
- Explore [server deployment](/typescript/framework/getting_started/installation/server-apis)
|
||||
- Check [troubleshooting guide](/typescript/framework/getting_started/installation/troubleshooting) for common issues
|
||||
+3
-3
@@ -492,9 +492,9 @@ Include:
|
||||
If you're still experiencing issues:
|
||||
|
||||
1. **Check specific deployment guides:**
|
||||
- [Server APIs](/docs/llamaindex/getting_started/installation/server-apis)
|
||||
- [Serverless Functions](/docs/llamaindex/getting_started/installation/serverless)
|
||||
- [Next.js Applications](/docs/llamaindex/getting_started/installation/nextjs)
|
||||
- [Server APIs](/typescript/framework/getting_started/installation/server-apis)
|
||||
- [Serverless Functions](/typescript/framework/getting_started/installation/serverless)
|
||||
- [Next.js Applications](/typescript/framework/getting_started/installation/nextjs)
|
||||
|
||||
2. **Open an issue** on GitHub with a minimal reproduction
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "Getting Started",
|
||||
"pages": ["concepts", "installation", "create_llama", "examples"]
|
||||
}
|
||||
@@ -43,19 +43,19 @@ Built for modern JavaScript runtimes like <SiNodedotjs className="inline" color=
|
||||
|
||||
### What are agents?
|
||||
|
||||
[Agents](/docs/llamaindex/tutorials/agents/1_setup) are LLM-powered assistants that can reason, use external tools, and take actions to accomplish tasks such as research, data extraction, and automation.
|
||||
[Agents](/typescript/framework/tutorials/agents/1_setup) are LLM-powered assistants that can reason, use external tools, and take actions to accomplish tasks such as research, data extraction, and automation.
|
||||
LlamaIndex.TS provides foundational building blocks for creating and orchestrating these agents.
|
||||
|
||||
### What are workflows?
|
||||
|
||||
[Workflows](/docs/llamaindex/tutorials/workflows) are multi-step, event-driven processes that combine agents, data connectors, and other tools to solve complex problems.
|
||||
[Workflows](/typescript/framework/tutorials/workflows) are multi-step, event-driven processes that combine agents, data connectors, and other tools to solve complex problems.
|
||||
With LlamaIndex.TS you can chain together retrieval, generation, and tool-calling steps and then deploy the entire pipeline as a microservice.
|
||||
|
||||
### What is context engineering?
|
||||
|
||||
LLMs come pre-trained on vast public corpora, but not on **your** private or domain-specific data.
|
||||
Context engineering bridges that gap by injecting the right pieces of your data into the LLM prompt at the right time.
|
||||
The most popular example is [Retrieval-Augmented Generation (RAG)](/docs/llamaindex/getting_started/concepts), but the same idea powers agent memory, evaluation, extraction, summarisation, and more.
|
||||
The most popular example is [Retrieval-Augmented Generation (RAG)](/typescript/framework/getting_started/concepts), but the same idea powers agent memory, evaluation, extraction, summarisation, and more.
|
||||
|
||||
LlamaIndex.TS gives you:
|
||||
|
||||
@@ -65,16 +65,16 @@ LlamaIndex.TS gives you:
|
||||
- **Workflows** for fine-grained orchestration of your data and LLM-powered agents.
|
||||
- **Observability** integrations so you can iterate with confidence.
|
||||
|
||||
You can learn more about these concepts in our [concepts guide](/docs/llamaindex/getting_started/concepts).
|
||||
You can learn more about these concepts in our [concepts guide](/typescript/framework/getting_started/concepts).
|
||||
|
||||
## Use cases
|
||||
|
||||
Popular scenarios include:
|
||||
|
||||
- [LLM-Powered Agents](/docs/llamaindex/tutorials/agents/1_setup)
|
||||
- [Indexing and Retrieval](/docs/llamaindex/tutorials/rag)
|
||||
- [Extracting Structured Data](/docs/llamaindex/tutorials/structured_data_extraction)
|
||||
- [Custom Orchestration with Workflows](/docs/llamaindex/tutorials/workflows)
|
||||
- [LLM-Powered Agents](/typescript/framework/tutorials/agents/1_setup)
|
||||
- [Indexing and Retrieval](/typescript/framework/tutorials/rag)
|
||||
- [Extracting Structured Data](/typescript/framework/tutorials/structured_data_extraction)
|
||||
- [Custom Orchestration with Workflows](/typescript/framework/tutorials/workflows)
|
||||
|
||||
## Getting started
|
||||
|
||||
@@ -89,10 +89,10 @@ The fastest way to get started is in StackBlitz below — no local setup require
|
||||
|
||||
Want to learn more? We have several tutorials to get you started:
|
||||
|
||||
- [Installation + Runtime Guide](/docs/llamaindex/getting_started/installation)
|
||||
- [Create your first agent](/docs/llamaindex/tutorials/agents/1_setup)
|
||||
- [Learn how to index data and chat with it](/docs/llamaindex/tutorials/rag)
|
||||
- [Learn how to write your own workflows and agents](/docs/llamaindex/tutorials/workflows)
|
||||
- [Installation + Runtime Guide](/typescript/framework/getting_started/installation)
|
||||
- [Create your first agent](/typescript/framework/tutorials/agents/1_setup)
|
||||
- [Learn how to index data and chat with it](/typescript/framework/tutorials/rag)
|
||||
- [Learn how to write your own workflows and agents](/typescript/framework/tutorials/workflows)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Integration
|
||||
collapsed: true
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
title: MCP Toolbox For Databases
|
||||
description: MCP Toolbox for Databases is an open source MCP server for databases.
|
||||
---
|
||||
|
||||
# MCP Toolbox for Databases
|
||||
|
||||
[MCP Toolbox for Databases](https://github.com/googleapis/genai-toolbox) is an open source MCP server for databases. It was designed with enterprise-grade and production-quality in mind. It enables you to develop tools easier, faster, and more securely by handling the complexities such as connection pooling, authentication, and more.
|
||||
|
||||
Toolbox Tools can be seemlessly integrated with LlamaIndex applications. For more
|
||||
information on [getting
|
||||
started](https://googleapis.github.io/genai-toolbox/getting-started/local_quickstart_js/) or
|
||||
[configuring](https://googleapis.github.io/genai-toolbox/getting-started/configure/)
|
||||
Toolbox, see the
|
||||
[documentation](https://googleapis.github.io/genai-toolbox/getting-started/introduction/).
|
||||
|
||||

|
||||
|
||||
### Configure and deploy
|
||||
|
||||
Toolbox is an open source server that you deploy and manage yourself. For more
|
||||
instructions on deploying and configuring, see the official Toolbox
|
||||
documentation:
|
||||
|
||||
* [Installing the Server](https://googleapis.github.io/genai-toolbox/getting-started/introduction/#installing-the-server)
|
||||
* [Configuring Toolbox](https://googleapis.github.io/genai-toolbox/getting-started/configure/)
|
||||
|
||||
### Install client SDK
|
||||
|
||||
LlamaIndex relies on the `@toolbox-sdk/core` node package to use Toolbox. Install the
|
||||
package before getting started:
|
||||
|
||||
```shell
|
||||
npm install @toolbox-sdk/core
|
||||
```
|
||||
|
||||
### Loading Toolbox Tools
|
||||
|
||||
Once your Toolbox server is configured and up and running, you can load tools
|
||||
from your server using the SDK:
|
||||
|
||||
```javascript
|
||||
import { gemini, GEMINI_MODEL } from "@llamaindex/google";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
import { tool } from "llamaindex";
|
||||
import { ToolboxClient } from "@toolbox-sdk/core";
|
||||
|
||||
// Initialize LLM
|
||||
const llm = gemini({
|
||||
model: GEMINI_MODEL.GEMINI_2_0_FLASH,
|
||||
apiKey: process.env.GOOGLE_API_KEY,
|
||||
});
|
||||
|
||||
// Replace with your Toolbox Server URL
|
||||
const URL = 'https://127.0.0.1:5000';
|
||||
|
||||
const client = new ToolboxClient("http://127.0.0.1:5000");
|
||||
const toolboxTools = await client.loadToolset("my-toolset");
|
||||
|
||||
const getTool = (toolboxTool) => tool({
|
||||
name: toolboxTool.getName(),
|
||||
description: toolboxTool.getDescription(),
|
||||
parameters: toolboxTool.getParamSchema(),
|
||||
execute: toolboxTool
|
||||
});
|
||||
const tools = toolboxTools.map(getTool);
|
||||
|
||||
const myAgent = agent({
|
||||
tools: tools,
|
||||
llm,
|
||||
memory,
|
||||
systemPrompt: prompt,
|
||||
});
|
||||
const result = await myAgent.run(query);
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
### Advanced Toolbox Features
|
||||
|
||||
Toolbox has a variety of features to make developing Gen AI tools for databases seamless.
|
||||
For more information, read more about the following:
|
||||
|
||||
- [Authenticated Parameters](https://googleapis.github.io/genai-toolbox/resources/tools/#authenticated-parameters): bind tool inputs to values from OIDC tokens automatically, making it easy to run sensitive queries without potentially leaking data
|
||||
- [Authorized Invocations](https://googleapis.github.io/genai-toolbox/resources/tools/#authorized-invocations): restrict access to use a tool based on the users Auth token
|
||||
- [OpenTelemetry](https://googleapis.github.io/genai-toolbox/how-to/export_telemetry/): get metrics and tracing from Toolbox with [OpenTelemetry](https://opentelemetry.io/docs/)
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"title": "Integration",
|
||||
"description": "See our integrations",
|
||||
"pages": ["open-llm-metry", "lang-trace", "vercel"]
|
||||
}
|
||||
@@ -38,7 +38,8 @@ Here's how to create a simple vector store index and query it using Vercel's AI
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { llamaindex } from "@llamaindex/vercel";
|
||||
import { streamText } from "ai";
|
||||
import { Document, VectorStoreIndex } from "llamaindex";
|
||||
import { Document } from "llamaindex";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
|
||||
// Create an index from your documents
|
||||
const document = new Document({ text: yourText, id_: "unique-id" });
|
||||
@@ -69,7 +70,7 @@ streamText({
|
||||
For production deployments, you can use LlamaCloud to store and manage your documents:
|
||||
|
||||
```typescript
|
||||
import { LlamaCloudIndex } from "@llamaindex/cloud";
|
||||
import { LlamaCloudIndex } from "llama-cloud-services";
|
||||
|
||||
// Create a LlamaCloud index
|
||||
const index = await LlamaCloudIndex.fromDocuments({
|
||||
|
||||
@@ -35,7 +35,7 @@ import { OpenAI } from "@llamaindex/openai";
|
||||
npm i @llamaindex/openai
|
||||
```
|
||||
|
||||
For more details on available AI model providers and their configuration, see the [LLMs documentation](/docs/llamaindex/modules/models/llms) and the [Embedding Models documentation](/docs/llamaindex/modules/models/embeddings).
|
||||
For more details on available AI model providers and their configuration, see the [LLMs documentation](/typescript/framework/modules/models/llms) and the [Embedding Models documentation](/typescript/framework/modules/models/embeddings).
|
||||
|
||||
### 2. Storage Providers
|
||||
|
||||
@@ -49,7 +49,7 @@ Now:
|
||||
import { PineconeVectorStore } from "@llamaindex/pinecone";
|
||||
```
|
||||
|
||||
For more information about available storage options, refer to the [Data Stores documentation](/docs/llamaindex/modules/data/stores).
|
||||
For more information about available storage options, refer to the [Data Stores documentation](/typescript/framework/modules/data/stores).
|
||||
|
||||
### 3. Data Loaders
|
||||
|
||||
@@ -63,7 +63,7 @@ Now:
|
||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||
```
|
||||
|
||||
For more details about available data loaders and their usage, check the [Loading Data](/docs/llamaindex/modules/data/readers).
|
||||
For more details about available data loaders and their usage, check the [Loading Data](/typescript/framework/modules/data/readers).
|
||||
|
||||
### 4. Prefer using `llamaindex` instead of `@llamaindex/core`
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Migration
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Deprecated
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Agent
|
||||
collapsed: true
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Agents
|
||||
---
|
||||
|
||||
**Note**: Agents are deprecated, use [Agent Workflows](/docs/llamaindex/modules/agents/agent_workflow) instead.
|
||||
**Note**: Agents are deprecated, use [Agent Workflows](/typescript/framework/modules/agents/agent_workflow) instead.
|
||||
|
||||
An “agent” is an automated reasoning and decision engine. It takes in a user input/query and can make internal decisions for executing that query in order to return the correct result. The key agent components can include, but are not limited to:
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"title": "Migration",
|
||||
"description": "Migration between different versions",
|
||||
"pages": ["0.8-to-0.9", "deprecated"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Modules
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Agents
|
||||
collapsed: true
|
||||
@@ -3,7 +3,7 @@ title: Agent Workflows
|
||||
---
|
||||
|
||||
|
||||
Agent Workflows are a powerful system that enables you to create and orchestrate one or multiple agents with tools to perform specific tasks. It's built on top of the base [`Workflow`](/docs/llamaindex/modules/agents/workflows) system and provides a streamlined interface for agent interactions.
|
||||
Agent Workflows are a powerful system that enables you to create and orchestrate one or multiple agents with tools to perform specific tasks. It's built on top of the base [`Workflow`](/typescript/framework/modules/agents/workflows) system and provides a streamlined interface for agent interactions.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -37,6 +37,58 @@ console.log(result.data.result); // Baby Llama is called cria
|
||||
console.log(result.data.message); // { role: 'assistant', content: 'Baby Llama is called cria' }
|
||||
```
|
||||
|
||||
### Structured Output
|
||||
|
||||
You can extract structured data from agent responses by providing a `responseFormat` with a Zod schema. This is useful when you need the agent's response in a specific format for further processing:
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
import { tool } from "llamaindex";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
import { openai } from "@llamaindex/openai";
|
||||
|
||||
// Define a weather tool
|
||||
const weatherTool = tool({
|
||||
name: "weatherTool",
|
||||
description: "Get weather information",
|
||||
parameters: z.object({
|
||||
location: z.string(),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny. The temperature is 72 degrees. The humidity is 50%. The wind speed is 10 mph.`;
|
||||
},
|
||||
});
|
||||
|
||||
// Define the structure you want for the response
|
||||
const responseSchema = z.object({
|
||||
temperature: z.number(),
|
||||
humidity: z.number(),
|
||||
windSpeed: z.number(),
|
||||
});
|
||||
|
||||
// Create the agent
|
||||
const weatherAgent = agent({
|
||||
name: "weatherAgent",
|
||||
tools: [weatherTool],
|
||||
llm: openai({ model: "gpt-4.1-mini" }),
|
||||
});
|
||||
|
||||
// Run with structured output
|
||||
const result = await weatherAgent.run("What's the weather in Tokyo?", {
|
||||
responseFormat: responseSchema,
|
||||
});
|
||||
|
||||
console.log("Natural language result:", result.data.result);
|
||||
console.log("Structured data:", result.data.object);
|
||||
// Output: { temperature: 72, humidity: 50, windSpeed: 10 }
|
||||
```
|
||||
|
||||
The agent will:
|
||||
1. Use the weather tool to get the raw weather information
|
||||
2. Process that information through the LLM
|
||||
3. Extract structured data according to your schema
|
||||
4. Return both the natural language response and the structured object
|
||||
|
||||
### Event Streaming
|
||||
|
||||
Agent Workflows provide a unified interface for event streaming, making it easy to track and respond to different events during execution:
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
---
|
||||
title: Low-Level LLM Execution
|
||||
---
|
||||
|
||||
Sometimes your need more control over LLM interactions than what high-level agents provide. The `llm.exec` method makes it simple for you to make a single LLM call with tools but hides the complexity of executing the tools and generating the tool messages.
|
||||
|
||||
## When to Use `llm.exec`
|
||||
|
||||
Use `llm.exec` when you need to:
|
||||
- Build custom agent logic in [workflow](/typescript/framework/modules/agents/workflows) steps
|
||||
- Have precise control over message handling and tool execution
|
||||
- Extract structured data from LLM responses
|
||||
|
||||
## Basic Usage
|
||||
|
||||
The `llm.exec` method takes messages and tools as parameter and executes one LLM call.
|
||||
The LLM might either request to call one or more of the tools or generate an assistant message as result.
|
||||
For each tool call that is requested, `llm.exec` executes it and generates the two tool call messages (call and result). If no tool call is requested, just the assistant message is returned.
|
||||
|
||||
```ts
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { ChatMessage, tool } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
const llm = openai({ model: "gpt-4.1-mini" });
|
||||
const messages = [
|
||||
{
|
||||
content: "What's the weather like in San Francisco?",
|
||||
role: "user",
|
||||
} as ChatMessage,
|
||||
];
|
||||
|
||||
const { newMessages, toolCalls } = await llm.exec({
|
||||
messages,
|
||||
tools: [
|
||||
tool({
|
||||
name: "get_weather",
|
||||
description: "Get the current weather for a location",
|
||||
parameters: z.object({
|
||||
address: z.string().describe("The address"),
|
||||
}),
|
||||
execute: ({ address }) => {
|
||||
return `It's sunny in ${address}!`;
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
// Add the new messages (including tool calls and responses) to your conversation
|
||||
messages.push(...newMessages);
|
||||
```
|
||||
|
||||
> `newMessages` is an array as each tool call generates two messages: a tool call message and the tool call result message.
|
||||
|
||||
## Structured Output
|
||||
|
||||
You can use `responseFormat` with a Zod schema to get structured data from the LLM response:
|
||||
|
||||
```ts
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { ChatMessage } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
const llm = openai({ model: "gpt-4.1-mini" });
|
||||
|
||||
const schema = z.object({
|
||||
title: z.string(),
|
||||
author: z.string(),
|
||||
year: z.number(),
|
||||
});
|
||||
|
||||
const messages = [
|
||||
{
|
||||
role: "user",
|
||||
content: "I have been reading La Divina Commedia by Dante Alighieri, published in 1321",
|
||||
} as ChatMessage,
|
||||
];
|
||||
|
||||
const { newMessages, toolCalls, object } = await llm.exec({
|
||||
messages,
|
||||
responseFormat: schema,
|
||||
});
|
||||
|
||||
console.log(object); // { title: "La Divina Commedia", author: "Dante Alighieri", year: 1321 }
|
||||
```
|
||||
|
||||
## Agent Loop Pattern
|
||||
|
||||
A common pattern is to use `llm.exec` in a loop until the LLM stops making tool calls:
|
||||
|
||||
```ts
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { ChatMessage, tool } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
async function runAgentLoop() {
|
||||
const llm = openai({ model: "gpt-4.1-mini" });
|
||||
const messages = [
|
||||
{
|
||||
content: "What's the weather like in San Francisco?",
|
||||
role: "user",
|
||||
} as ChatMessage,
|
||||
];
|
||||
|
||||
let exit = false;
|
||||
do {
|
||||
const { newMessages, toolCalls } = await llm.exec({
|
||||
messages,
|
||||
tools: [
|
||||
tool({
|
||||
name: "get_weather",
|
||||
description: "Get the current weather for a location",
|
||||
parameters: z.object({
|
||||
address: z.string().describe("The address"),
|
||||
}),
|
||||
execute: ({ address }) => {
|
||||
return `It's sunny in ${address}!`;
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(newMessages);
|
||||
messages.push(...newMessages);
|
||||
|
||||
// Exit when no more tool calls are made
|
||||
exit = toolCalls.length === 0;
|
||||
} while (!exit);
|
||||
}
|
||||
```
|
||||
|
||||
## Streaming Support
|
||||
|
||||
For real-time responses, use the `stream` option to get the assistant's response as streamed tokens:
|
||||
|
||||
```ts
|
||||
import { openai } from "@llamaindex/openai";
|
||||
import { ChatMessage, tool } from "llamaindex";
|
||||
import z from "zod";
|
||||
|
||||
async function streamingAgentLoop() {
|
||||
const llm = openai({ model: "gpt-4o-mini" });
|
||||
const messages = [
|
||||
{
|
||||
content: "What's the weather like in San Francisco?",
|
||||
role: "user",
|
||||
} as ChatMessage,
|
||||
];
|
||||
|
||||
let exit = false;
|
||||
do {
|
||||
const { stream, newMessages, toolCalls } = await llm.exec({
|
||||
messages,
|
||||
tools: [
|
||||
tool({
|
||||
name: "get_weather",
|
||||
description: "Get the current weather for a location",
|
||||
parameters: z.object({
|
||||
address: z.string().describe("The address"),
|
||||
}),
|
||||
execute: ({ address }) => {
|
||||
return `It's sunny in ${address}!`;
|
||||
},
|
||||
}),
|
||||
],
|
||||
stream: true,
|
||||
});
|
||||
|
||||
// Stream the response token by token
|
||||
for await (const chunk of stream) {
|
||||
process.stdout.write(chunk.delta);
|
||||
}
|
||||
|
||||
messages.push(...newMessages());
|
||||
|
||||
exit = toolCalls.length === 0;
|
||||
} while (!exit);
|
||||
}
|
||||
```
|
||||
|
||||
> `newMessages` is a function when streaming. The reason is that the result only is available after streaming. Calling it before, will throw an error.
|
||||
|
||||
## Return Values
|
||||
|
||||
`llm.exec` returns an object with:
|
||||
|
||||
- **`newMessages`**: Array of new chat messages including the LLM response and any tool call messages (call or result). This is a function return the array when streaming.
|
||||
- **`toolCalls`**: Array of tool calls made by the LLM
|
||||
- **`object`**: The structured object when using `responseFormat` with a Zod schema (undefined if no schema is provided)
|
||||
- **`stream`**: Async iterable for streaming responses (only when `stream: true`)
|
||||
|
||||
## Best Practices
|
||||
|
||||
For using `llm.exec` in an agent loop, take care to:
|
||||
|
||||
1. **Maintain message history**: Always add `newMessages` to your conversation history
|
||||
2. **Set exit conditions**: Implement proper logic to avoid infinite loops
|
||||
3. **Handle structured output**: When using `responseFormat`, the `object` property contains your parsed data
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "Agents",
|
||||
"pages": ["tool", "agent_workflow", "workflows", "natural_language_workflow"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Tool
|
||||
collapsed: true
|
||||
@@ -101,6 +101,9 @@ const agent = agent({
|
||||
});
|
||||
```
|
||||
|
||||
You can also use [MCP Toolbox for
|
||||
Databases](/typescript/framework/integration/mcp-toolbox) to interact with MCP tools.
|
||||
|
||||
|
||||
## Function tool
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Data
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Data Index
|
||||
collapsed: true
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Index
|
||||
---
|
||||
|
||||
An index is the basic container for organizing your data. Besides managed indexes using [LlamaCloud](/docs/llamaindex/modules/data/data_index/managed), LlamaIndex.TS supports three indexes:
|
||||
An index is the basic container for organizing your data. Besides managed indexes using [LlamaCloud](/typescript/framework/modules/data/data_index/managed), LlamaIndex.TS supports three indexes:
|
||||
|
||||
|
||||
- `VectorStoreIndex` - will send the top-k `Node`s to the LLM when generating a response. The default top-k is 2.
|
||||
|
||||
@@ -28,5 +28,4 @@ Here's an example of how to use a managed index together with a chat engine:
|
||||
|
||||
## API Reference
|
||||
|
||||
- [LlamaCloudIndex](/docs/api/classes/LlamaCloudIndex)
|
||||
- [LlamaCloudRetriever](/docs/api/classes/LlamaCloudRetriever)
|
||||
- [LlamaCloud Documentation](https://docs.cloud.llamaindex.ai/)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Ingestion Pipeline
|
||||
collapsed: true
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
label: Transformations
|
||||
collapsed: true
|
||||
+3
-3
@@ -6,9 +6,9 @@ A transformation is something that takes a list of nodes as an input, and return
|
||||
|
||||
Currently, the following components are Transformation objects:
|
||||
|
||||
- [SentenceSplitter](/docs/llamaindex/modules/data/ingestion_pipeline/transformations/node-parser)
|
||||
- [MetadataExtractor](/docs/llamaindex/modules/data/ingestion_pipeline/transformations/metadata_extraction)
|
||||
- [Embeddings](/docs/llamaindex/modules/models/embeddings)
|
||||
- [SentenceSplitter](/typescript/framework/modules/data/ingestion_pipeline/transformations/node-parser)
|
||||
- [MetadataExtractor](/typescript/framework/modules/data/ingestion_pipeline/transformations/metadata_extraction)
|
||||
- [Embeddings](/typescript/framework/modules/models/embeddings)
|
||||
|
||||
## Usage Pattern
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ title: Node Parsers / Text Splitters
|
||||
description: Learn how to use Node Parsers and Text Splitters to extract data from documents.
|
||||
---
|
||||
|
||||
Node parsers are a simple abstraction that take a list of `Document` objects, and chunk them into `Node` objects, such that each node is a specific chunk of the parent document. When a document is broken into nodes, all of it's attributes are inherited to the children nodes (i.e. `metadata`, text and metadata templates, etc.). You can read more about `Node` and `Document` properties [here](/docs/llamaindex/modules/data).
|
||||
Node parsers are a simple abstraction that take a list of `Document` objects, and chunk them into `Node` objects, such that each node is a specific chunk of the parent document. When a document is broken into nodes, all of it's attributes are inherited to the children nodes (i.e. `metadata`, text and metadata templates, etc.). You can read more about `Node` and `Document` properties [here](/typescript/framework/modules/data).
|
||||
|
||||
By default, we will use `Settings.nodeParser` to split the document into nodes. You can also assign a custom `NodeParser` to the `Settings` object.
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Memory
|
||||
collapsed: true
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"title": "Data",
|
||||
"pages": [
|
||||
"index",
|
||||
"memory",
|
||||
"readers",
|
||||
"data_index",
|
||||
"ingestion_pipeline",
|
||||
"stores"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Readers
|
||||
collapsed: true
|
||||
@@ -78,7 +78,7 @@ As the `PDFReader` is not working with the Edge runtime, here's how to use the `
|
||||
|
||||
```typescript
|
||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
|
||||
export const DATA_DIR = "./data";
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Llama Parse
|
||||
collapsed: true
|
||||
@@ -7,7 +7,7 @@ LlamaParse `json` mode supports extracting any images found in a page object by
|
||||
## Installation
|
||||
|
||||
```package-install
|
||||
npm i llamaindex @llamaindex/cloud @llamaindex/openai
|
||||
npm i llamaindex llama-cloud-services @llamaindex/openai
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -26,7 +26,7 @@ You can create an index across both text and image nodes by requesting alternati
|
||||
|
||||
```ts
|
||||
import { Document, ImageNode, VectorStoreIndex } from "llamaindex";
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { createMessageContent } from "llamaindex";
|
||||
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ In JSON mode, LlamaParse will return a data structure representing the parsed ob
|
||||
## Installation
|
||||
|
||||
```package-install
|
||||
npm i llamaindex @llamaindex/cloud
|
||||
npm i llamaindex llama-cloud-services
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -16,7 +16,7 @@ For Json mode, you need to use `loadJson`. The `resultType` is automatically set
|
||||
More information about indexing the results on the next page.
|
||||
|
||||
```ts
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
|
||||
const reader = new LlamaParseReader();
|
||||
async function main() {
|
||||
@@ -68,7 +68,7 @@ However, a simple work around is to create a new reader class that extends `Llam
|
||||
|
||||
```ts
|
||||
import { Document } from "llamaindex";
|
||||
import { LlamaParseReader } from "@llamaindex/cloud";
|
||||
import { LlamaParseReader } from "llama-cloud-services";
|
||||
|
||||
class LlamaParseReaderWithJson extends LlamaParseReader {
|
||||
// Override the loadData method
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Stores
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Chat Stores
|
||||
collapsed: true
|
||||
@@ -6,7 +6,7 @@ Chat stores manage chat history by storing sequences of messages in a structured
|
||||
|
||||
## Available Chat Stores
|
||||
|
||||
- [SimpleChatStore](/docs/api/classes/SimpleChatStore): A simple in-memory chat store with support for [persisting](/docs/llamaindex/modules/data/stores#local-storage) data to disk.
|
||||
- [SimpleChatStore](/docs/api/classes/SimpleChatStore): A simple in-memory chat store with support for [persisting](/typescript/framework/modules/data/stores#local-storage) data to disk.
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Doc Stores
|
||||
collapsed: true
|
||||
@@ -2,12 +2,12 @@
|
||||
title: Document Stores
|
||||
---
|
||||
|
||||
Document stores contain ingested document chunks, i.e. [Node](/docs/llamaindex/modules/data)s.
|
||||
Document stores contain ingested document chunks, i.e. [Node](/typescript/framework/modules/data)s.
|
||||
|
||||
## Available Document Stores
|
||||
|
||||
- [SimpleDocumentStore](/docs/api/classes/SimpleDocumentStore): A simple in-memory document store with support for [persisting](/docs/llamaindex/modules/data/stores#local-storage) data to disk.
|
||||
- [PostgresDocumentStore](/docs/api/classes/PostgresDocumentStore): A PostgreSQL document store, see [PostgreSQL Storage](/docs/llamaindex/modules/data/stores#postgresql-storage).
|
||||
- [SimpleDocumentStore](/docs/api/classes/SimpleDocumentStore): A simple in-memory document store with support for [persisting](/typescript/framework/modules/data/stores#local-storage) data to disk.
|
||||
- [PostgresDocumentStore](/docs/api/classes/PostgresDocumentStore): A PostgreSQL document store, see [PostgreSQL Storage](/typescript/framework/modules/data/stores#postgresql-storage).
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Index Stores
|
||||
collapsed: true
|
||||
@@ -2,12 +2,12 @@
|
||||
title: Index Stores
|
||||
---
|
||||
|
||||
Index stores are underlying storage components that contain metadata(i.e. information created when indexing) about the [index](/docs/llamaindex/modules/data/data_index) itself.
|
||||
Index stores are underlying storage components that contain metadata(i.e. information created when indexing) about the [index](/typescript/framework/modules/data/data_index) itself.
|
||||
|
||||
## Available Index Stores
|
||||
|
||||
- [SimpleIndexStore](/docs/api/classes/SimpleIndexStore): A simple in-memory index store with support for [persisting](/docs/llamaindex/modules/data/stores#local-storage) data to disk.
|
||||
- [PostgresIndexStore](/docs/api/classes/PostgresIndexStore): A PostgreSQL index store, , see [PostgreSQL Storage](/docs/llamaindex/modules/data/stores#postgresql-storage).
|
||||
- [SimpleIndexStore](/docs/api/classes/SimpleIndexStore): A simple in-memory index store with support for [persisting](/typescript/framework/modules/data/stores#local-storage) data to disk.
|
||||
- [PostgresIndexStore](/docs/api/classes/PostgresIndexStore): A PostgreSQL index store, , see [PostgreSQL Storage](/typescript/framework/modules/data/stores#postgresql-storage).
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Kv Stores
|
||||
collapsed: true
|
||||
@@ -2,12 +2,12 @@
|
||||
title: Key-Value Stores
|
||||
---
|
||||
|
||||
Key-Value Stores represent underlying storage components used in [Document Stores](/docs/llamaindex/modules/data/stores/doc_stores) and [Index Stores](/docs/llamaindex/modules/data/stores/index_stores)
|
||||
Key-Value Stores represent underlying storage components used in [Document Stores](/typescript/framework/modules/data/stores/doc_stores) and [Index Stores](/typescript/framework/modules/data/stores/index_stores)
|
||||
|
||||
## Available Key-Value Stores
|
||||
|
||||
- [SimpleKVStore](/docs/api/classes/SimpleKVStore): A simple Key-Value store with support of [persisting](/docs/llamaindex/modules/data/stores#local-storage) data to disk.
|
||||
- [PostgresKVStore](/docs/api/classes/PostgresKVStore): A PostgreSQL Key-Value store, see [PostgreSQL Storage](/docs/llamaindex/modules/data/stores#postgresql-storage).
|
||||
- [SimpleKVStore](/docs/api/classes/SimpleKVStore): A simple Key-Value store with support of [persisting](/typescript/framework/modules/data/stores#local-storage) data to disk.
|
||||
- [PostgresKVStore](/docs/api/classes/PostgresKVStore): A PostgreSQL Key-Value store, see [PostgreSQL Storage](/typescript/framework/modules/data/stores#postgresql-storage).
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Vector Stores
|
||||
collapsed: true
|
||||
@@ -8,7 +8,7 @@ Vector stores save embedding vectors of your ingested document chunks.
|
||||
|
||||
Available Vector Stores are shown on the sidebar to the left. Additionally the following integrations exist without separate documentation:
|
||||
|
||||
- [SimpleVectorStore](/docs/api/classes/SimpleVectorStore): A simple in-memory vector store with optional [persistance](/docs/llamaindex/modules/data/stores#local-storage) to disk.
|
||||
- [SimpleVectorStore](/docs/api/classes/SimpleVectorStore): A simple in-memory vector store with optional [persistance](/typescript/framework/modules/data/stores#local-storage) to disk.
|
||||
- [AstraDBVectorStore](/docs/api/classes/AstraDBVectorStore): A cloud-native, scalable Database-as-a-Service built on Apache Cassandra, see [datastax.com](https://www.datastax.com/products/datastax-astra)
|
||||
- [ChromaVectorStore](/docs/api/classes/ChromaVectorStore): An open-source vector database, focused on ease of use and performance, see [trychroma.com](https://www.trychroma.com/)
|
||||
- [MilvusVectorStore](/docs/api/classes/MilvusVectorStore): An open-source, high-performance, highly scalable vector database, see [milvus.io](https://milvus.io/)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Evaluation
|
||||
collapsed: true
|
||||
@@ -29,6 +29,6 @@ These evaluation modules are in the following forms:
|
||||
|
||||
## Usage
|
||||
|
||||
- [Correctness Evaluator](/docs/llamaindex/modules/evaluation/correctness)
|
||||
- [Faithfulness Evaluator](/docs/llamaindex/modules/evaluation/faithfulness)
|
||||
- [Relevancy Evaluator](/docs/llamaindex/modules/evaluation/relevancy)
|
||||
- [Correctness Evaluator](/typescript/framework/modules/evaluation/correctness)
|
||||
- [Faithfulness Evaluator](/typescript/framework/modules/evaluation/faithfulness)
|
||||
- [Relevancy Evaluator](/typescript/framework/modules/evaluation/relevancy)
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "Modules",
|
||||
"pages": ["models", "agents", "data", "rag", "ui", "evaluation"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Models
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Embeddings
|
||||
collapsed: true
|
||||
@@ -23,7 +23,7 @@ Settings.embedModel = new OpenAIEmbedding({
|
||||
|
||||
## Local Embedding
|
||||
|
||||
For local embeddings, you can use the [HuggingFace](/docs/llamaindex/modules/models/embeddings/huggingface) embedding model.
|
||||
For local embeddings, you can use the [HuggingFace](/typescript/framework/modules/models/embeddings/huggingface) embedding model.
|
||||
|
||||
## Local Ollama Embeddings With Remote Host
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Llms
|
||||
collapsed: true
|
||||
@@ -5,13 +5,13 @@ title: Bedrock
|
||||
## Installation
|
||||
|
||||
```package-install
|
||||
npm i llamaindex @llamaindex/community
|
||||
npm i llamaindex @llamaindex/aws
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/community";
|
||||
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
|
||||
|
||||
Settings.llm = new Bedrock({
|
||||
model: BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
||||
@@ -23,9 +23,19 @@ Settings.llm = new Bedrock({
|
||||
});
|
||||
```
|
||||
|
||||
Currently only supports Anthropic and Meta models:
|
||||
Supported models are listed below (accessible by BEDROCK_MODELS).
|
||||
|
||||
```ts
|
||||
AMAZON_TITAN_TG1_LARGE = "amazon.titan-tg1-large";
|
||||
AMAZON_TITAN_TEXT_EXPRESS_V1 = "amazon.titan-text-express-v1";
|
||||
AI21_J2_GRANDE_INSTRUCT = "ai21.j2-grande-instruct";
|
||||
AI21_J2_JUMBO_INSTRUCT = "ai21.j2-jumbo-instruct";
|
||||
AI21_J2_MID = "ai21.j2-mid";
|
||||
AI21_J2_MID_V1 = "ai21.j2-mid-v1";
|
||||
AI21_J2_ULTRA = "ai21.j2-ultra";
|
||||
AI21_J2_ULTRA_V1 = "ai21.j2-ultra-v1";
|
||||
COHERE_COMMAND_TEXT_V14 = "cohere.command-text-v14";
|
||||
|
||||
ANTHROPIC_CLAUDE_INSTANT_1 = "anthropic.claude-instant-v1";
|
||||
ANTHROPIC_CLAUDE_2 = "anthropic.claude-v2";
|
||||
ANTHROPIC_CLAUDE_2_1 = "anthropic.claude-v2:1";
|
||||
@@ -33,7 +43,15 @@ ANTHROPIC_CLAUDE_3_SONNET = "anthropic.claude-3-sonnet-20240229-v1:0";
|
||||
ANTHROPIC_CLAUDE_3_HAIKU = "anthropic.claude-3-haiku-20240307-v1:0";
|
||||
ANTHROPIC_CLAUDE_3_OPUS = "anthropic.claude-3-opus-20240229-v1:0"; // available on us-west-2
|
||||
ANTHROPIC_CLAUDE_3_5_SONNET = "anthropic.claude-3-5-sonnet-20240620-v1:0";
|
||||
ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "anthropic.claude-3-5-sonnet-20241022-v2:0";
|
||||
ANTHROPIC_CLAUDE_3_5_HAIKU = "anthropic.claude-3-5-haiku-20241022-v1:0";
|
||||
ANTHROPIC_CLAUDE_3_7_SONNET = "anthropic.claude-3-7-sonnet-20250219-v1:0";
|
||||
ANTHROPIC_CLAUDE_4_SONNET = "anthropic.claude-sonnet-4-20250514-v1:0";
|
||||
ANTHROPIC_CLAUDE_4_OPUS = "anthropic.claude-opus-4-20250514-v1:0";
|
||||
ANTHROPIC_CLAUDE_4_1_OPUS = "anthropic.claude-opus-4-1-20250805-v1:0";
|
||||
ANTHROPIC_CLAUDE_4_5_SONNET = "anthropic.claude-sonnet-4-5-20250929-v1:0";
|
||||
|
||||
|
||||
META_LLAMA2_13B_CHAT = "meta.llama2-13b-chat-v1";
|
||||
META_LLAMA2_70B_CHAT = "meta.llama2-70b-chat-v1";
|
||||
META_LLAMA3_8B_INSTRUCT = "meta.llama3-8b-instruct-v1:0";
|
||||
@@ -45,41 +63,71 @@ META_LLAMA3_2_1B_INSTRUCT = "meta.llama3-2-1b-instruct-v1:0"; // only available
|
||||
META_LLAMA3_2_3B_INSTRUCT = "meta.llama3-2-3b-instruct-v1:0"; // only available via inference endpoints (see below)
|
||||
META_LLAMA3_2_11B_INSTRUCT = "meta.llama3-2-11b-instruct-v1:0"; // only available via inference endpoints (see below), multimodal and function call supported
|
||||
META_LLAMA3_2_90B_INSTRUCT = "meta.llama3-2-90b-instruct-v1:0"; // only available via inference endpoints (see below), multimodal and function call supported
|
||||
META_LLAMA3_3_70B_INSTRUCT = "meta.llama3-3-70b-instruct-v1:0";
|
||||
|
||||
MISTRAL_7B_INSTRUCT = "mistral.mistral-7b-instruct-v0:2";
|
||||
MISTRAL_MIXTRAL_7B_INSTRUCT = "mistral.mixtral-8x7b-instruct-v0:1";
|
||||
MISTRAL_MIXTRAL_LARGE_2402 = "mistral.mistral-large-2402-v1:0";
|
||||
|
||||
AMAZON_NOVA_PREMIER_1 = "amazon.nova-premier-v1:0";
|
||||
AMAZON_NOVA_PRO_1 = "amazon.nova-pro-v1:0";
|
||||
AMAZON_NOVA_LITE_1 = "amazon.nova-lite-v1:0";
|
||||
AMAZON_NOVA_MICRO_1 = "amazon.nova-micro-v1:0";
|
||||
```
|
||||
|
||||
You can also use Bedrock's Inference endpoints by using the model names:
|
||||
You can also use Bedrock's Inference endpoints by using the model names (accessible by INFERENCE_BEDROCK_MODELS).
|
||||
Note that the region must be set correctly.
|
||||
|
||||
```ts
|
||||
// US
|
||||
//US
|
||||
US_ANTHROPIC_CLAUDE_3_HAIKU = "us.anthropic.claude-3-haiku-20240307-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_3_5_HAIKU = "us.anthropic.claude-3-5-haiku-20241022-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_3_OPUS = "us.anthropic.claude-3-opus-20240229-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_3_SONNET = "us.anthropic.claude-3-sonnet-20240229-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_3_5_SONNET = "us.anthropic.claude-3-5-sonnet-20240620-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_3_5_SONNET_V2 =
|
||||
"us.anthropic.claude-3-5-sonnet-20241022-v2:0";
|
||||
US_ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "us.anthropic.claude-3-5-sonnet-20241022-v2:0";
|
||||
US_ANTHROPIC_CLAUDE_3_7_SONNET = "us.anthropic.claude-3-7-sonnet-20250219-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_4_SONNET = "us.anthropic.claude-sonnet-4-20250514-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_4_OPUS = "us.anthropic.claude-opus-4-20250514-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_4_1_OPUS = "us.anthropic.claude-opus-4-1-20250805-v1:0";
|
||||
US_ANTHROPIC_CLAUDE_4_5_SONNET = "us.anthropic.claude-sonnet-4-5-20250929-v1:0";
|
||||
US_META_LLAMA_3_2_1B_INSTRUCT = "us.meta.llama3-2-1b-instruct-v1:0";
|
||||
US_META_LLAMA_3_2_3B_INSTRUCT = "us.meta.llama3-2-3b-instruct-v1:0";
|
||||
US_META_LLAMA_3_2_11B_INSTRUCT = "us.meta.llama3-2-11b-instruct-v1:0";
|
||||
US_META_LLAMA_3_2_90B_INSTRUCT = "us.meta.llama3-2-90b-instruct-v1:0";
|
||||
US_AMAZON_NOVA_PRO_1 = "us.amazon.nova-premier-v1:0";
|
||||
US_META_LLAMA_3_3_70B_INSTRUCT = "us.meta.llama3-3-70b-instruct-v1:0";
|
||||
US_AMAZON_NOVA_PREMIER_1 = "us.amazon.nova-premier-v1:0";
|
||||
US_AMAZON_NOVA_PRO_1 = "us.amazon.nova-pro-v1:0";
|
||||
US_AMAZON_NOVA_LITE_1 = "us.amazon.nova-lite-v1:0";
|
||||
US_AMAZON_NOVA_MICRO_1 = "us.amazon.nova-micro-v1:0";
|
||||
|
||||
// EU
|
||||
//EU
|
||||
EU_ANTHROPIC_CLAUDE_3_HAIKU = "eu.anthropic.claude-3-haiku-20240307-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_3_5_HAIKU = "eu.anthropic.claude-3-5-haiku-20240307-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_3_SONNET = "eu.anthropic.claude-3-sonnet-20240229-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_3_5_SONNET = "eu.anthropic.claude-3-5-sonnet-20240620-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_3_7_SONNET = "eu.anthropic.claude-3-7-sonnet-20250219-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_4_SONNET = "eu.anthropic.claude-sonnet-4-20250514-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_4_OPUS = "eu.anthropic.claude-opus-4-20250514-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_4_1_OPUS = "eu.anthropic.claude-opus-4-1-20250805-v1:0";
|
||||
EU_ANTHROPIC_CLAUDE_4_5_SONNET = "eu.anthropic.claude-sonnet-4-5-20250929-v1:0";
|
||||
EU_META_LLAMA_3_2_1B_INSTRUCT = "eu.meta.llama3-2-1b-instruct-v1:0";
|
||||
EU_META_LLAMA_3_2_3B_INSTRUCT = "eu.meta.llama3-2-3b-instruct-v1:0";
|
||||
EU_AMAZON_NOVA_PRO_1 = "eu.amazon.nova-premier-v1:0";
|
||||
EU_AMAZON_NOVA_PREMIER_1 = "eu.amazon.nova-premier-v1:0";
|
||||
EU_AMAZON_NOVA_PRO_1 = "eu.amazon.nova-pro-v1:0";
|
||||
EU_AMAZON_NOVA_LITE_1 = "eu.amazon.nova-lite-v1:0";
|
||||
EU_AMAZON_NOVA_MICRO_1 = "eu.amazon.nova-micro-v1:0";
|
||||
|
||||
//APAC
|
||||
APAC_ANTHROPIC_CLAUDE_3_5_SONNET = "apac.anthropic.claude-3-5-sonnet-20240620-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_5_SONNET_V2 = "apac.anthropic.claude-3-5-sonnet-20241022-v2:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_7_SONNET = "apac.anthropic.claude-3-7-sonnet-20250219-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_4_SONNET = "apac.anthropic.claude-sonnet-4-20250514-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_HAIKU = "apac.anthropic.claude-3-haiku-20240307-v1:0";
|
||||
APAC_ANTHROPIC_CLAUDE_3_SONNET = "apac.anthropic.claude-3-sonnet-20240229-v1:0";
|
||||
APAC_AMAZON_NOVA_PRO_1 = "apac.amazon.nova-pro-v1:0";
|
||||
APAC_AMAZON_NOVA_LITE_1 = "apac.amazon.nova-lite-v1:0";
|
||||
APAC_AMAZON_NOVA_MICRO_1 = "apac.amazon.nova-micro-v1:0";
|
||||
```
|
||||
|
||||
Sonnet, Haiku and Opus are multimodal, image_url only supports base64 data url format, e.g. `data:image/jpeg;base64,SGVsbG8sIFdvcmxkIQ==`
|
||||
@@ -87,10 +135,11 @@ Sonnet, Haiku and Opus are multimodal, image_url only supports base64 data url f
|
||||
## Full Example
|
||||
|
||||
```ts
|
||||
import { BEDROCK_MODELS, Bedrock } from "llamaindex";
|
||||
import { INFERENCE_BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
|
||||
|
||||
Settings.llm = new Bedrock({
|
||||
model: BEDROCK_MODELS.ANTHROPIC_CLAUDE_3_HAIKU,
|
||||
model: INFERENCE_BEDROCK_MODELS.US_ANTHROPIC_CLAUDE_3_SONNET,
|
||||
region: "us-east-1",
|
||||
});
|
||||
|
||||
async function main() {
|
||||
@@ -119,7 +168,7 @@ async function main() {
|
||||
## Agent Example
|
||||
|
||||
```ts
|
||||
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/community";
|
||||
import { BEDROCK_MODELS, Bedrock } from "@llamaindex/aws";
|
||||
import { tool } from "llamaindex";
|
||||
import { agent } from "@llamaindex/workflow";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -33,7 +33,7 @@ export AZURE_OPENAI_DEPLOYMENT="gpt-4" # or some other deployment name
|
||||
|
||||
## Local LLM
|
||||
|
||||
For local LLMs, currently we recommend the use of [Ollama](/docs/llamaindex/modules/models/llms/ollama) LLM.
|
||||
For local LLMs, currently we recommend the use of [Ollama](/typescript/framework/modules/models/llms/ollama) LLM.
|
||||
|
||||
## Available LLMs
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "Models",
|
||||
"pages": ["embeddings", "llms", "prompt"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Prompt
|
||||
collapsed: true
|
||||
@@ -82,5 +82,5 @@ const response = await queryEngine.query({
|
||||
|
||||
## API Reference
|
||||
|
||||
- [Response Synthesizer](/docs/llamaindex/modules/rag/response_synthesizer)
|
||||
- [Response Synthesizer](/typescript/framework/modules/rag/response_synthesizer)
|
||||
- [CompactAndRefine](/docs/api/classes/CompactAndRefine)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: RAG
|
||||
collapsed: true
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"title": "RAG",
|
||||
"pages": [
|
||||
"retriever",
|
||||
"response_synthesizer",
|
||||
"query_engines",
|
||||
"chat_engine",
|
||||
"node_postprocessors",
|
||||
"evaluation"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Node Postprocessors
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Query Engines
|
||||
collapsed: true
|
||||
@@ -4,7 +4,6 @@ title: Retriever
|
||||
|
||||
A retriever in LlamaIndex is what is used to fetch `Node`s from an index using a query string.
|
||||
|
||||
- [LlamaCloudRetriever](/docs/api/classes/LlamaCloudRetriever) to retrieve nodes from a [managed index](/docs/llamaindex/modules/data/data_index/managed)
|
||||
- [VectorIndexRetriever](/docs/api/classes/VectorIndexRetriever) will fetch the top-k most similar nodes. Ideal for dense retrieval to find most relevant nodes.
|
||||
- [SummaryIndexRetriever](/docs/api/classes/SummaryIndexRetriever) will fetch all nodes no matter the query. Ideal when complete context is necessary, e.g. analyzing large datasets.
|
||||
- [SummaryIndexLLMRetriever](/docs/api/classes/SummaryIndexLLMRetriever) utilizes an LLM to score and filter nodes based on relevancy to the query.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Chat UI
|
||||
collapsed: true
|
||||
@@ -5,7 +5,7 @@ description: Running LlamaIndex workflows with both API endpoints and a user int
|
||||
|
||||
# LlamaIndex Server
|
||||
|
||||
LlamaIndexServer is a Next.js-based application that allows you to quickly launch your [LlamaIndex Workflows](https://ts.llamaindex.ai/docs/llamaindex/modules/agents/workflows) and [Agent Workflows](https://ts.llamaindex.ai/docs/llamaindex/modules/agents/agent_workflow) as an API server with an optional chat UI. It provides a complete environment for running LlamaIndex workflows with both API endpoints and a user interface for interaction.
|
||||
LlamaIndexServer is a Next.js-based application that allows you to quickly launch your [LlamaIndex Workflows](https://ts.llamaindex.ai/typescript/framework/modules/agents/workflows) and [Agent Workflows](https://ts.llamaindex.ai/typescript/framework/modules/agents/agent_workflow) as an API server with an optional chat UI. It provides a complete environment for running LlamaIndex workflows with both API endpoints and a user interface for interaction.
|
||||
|
||||
## Features
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"title": "Chat UI",
|
||||
"description": "Use chat-ui to add a chat interface to your LlamaIndexTS application.",
|
||||
"defaultOpen": false,
|
||||
"pages": ["index", "llamaindex-server"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Tutorials
|
||||
collapsed: true
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Agent with RAG
|
||||
collapsed: true
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"title": "Agent with RAG",
|
||||
"pages": [
|
||||
"1_setup",
|
||||
"2_create_agent",
|
||||
"3_local_model",
|
||||
"4_agentic_rag",
|
||||
"5_rag_and_tools",
|
||||
"6_llamaparse",
|
||||
"7_qdrant"
|
||||
]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Basic Agent
|
||||
---
|
||||
|
||||
We have a comprehensive, step-by-step [guide to building agents in LlamaIndex.TS](/docs/llamaindex/tutorials/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:
|
||||
We have a comprehensive, step-by-step [guide to building agents in LlamaIndex.TS](/typescript/framework/tutorials/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
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
title: Custom Model Per Request
|
||||
---
|
||||
|
||||
There are scenarios, such as the case of a multi-tenant backend API, where it may be required to handle each request with a custom model.
|
||||
|
||||
In such a scenario, modifying the `Settings` object directly as follows is not recommended:
|
||||
|
||||
```typescript
|
||||
import { Settings } from 'llamaindex';
|
||||
import { OpenAIEmbedding } from '@llamaindex/embeddings-openai';
|
||||
|
||||
Settings.embedModel = new OpenAIEmbedding({ apiKey: 'CLIENT_API_KEY' });
|
||||
Settings.llm = openai({ apiKey: key, model: 'gpt-4o' })
|
||||
```
|
||||
|
||||
Setting `llm` and `embedModel` directly will lead to unpredictable responses, since `Settings` is global and mutable.
|
||||
This can lead to race conditions, as each request modifies `Settings.embedModel` or `Settings.llm`.
|
||||
|
||||
The recommended approach is to use `Settings.withEmbedModel` or `Settings.withLLM` as follows:
|
||||
|
||||
```typescript
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const llm = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
||||
|
||||
const llmResponse = await Settings.withEmbedModel(embedModel, async () => {
|
||||
return Settings.withLLM(llm, async () => {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const { message, sourceNodes } = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
// Return response with sources
|
||||
return message.content;
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The full example can be found [here](https://github.com/run-llama/LlamaIndexTS/tree/main/examples/local-settings).
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Local LLMs
|
||||
---
|
||||
|
||||
LlamaIndex.TS supports OpenAI and [other remote LLM APIs](/docs/llamaindex/modules/models/llms). You can also run a local LLM on your machine!
|
||||
LlamaIndex.TS supports OpenAI and [other remote LLM APIs](/typescript/framework/modules/models/llms). You can also run a local LLM on your machine!
|
||||
|
||||
## Using a local model via Ollama
|
||||
|
||||
@@ -93,4 +93,4 @@ async function main() {
|
||||
main().catch(console.error);
|
||||
```
|
||||
|
||||
You can see the [full example file](https://github.com/run-llama/LlamaIndexTS/blob/main/examples/vectorIndexLocal.ts).
|
||||
You can see the [full example file](https://github.com/run-llama/LlamaIndexTS/blob/main/examples/index/vectorIndexLocal.ts).
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"title": "Tutorials",
|
||||
"pages": [
|
||||
"basic_agent",
|
||||
"rag",
|
||||
"agents",
|
||||
"workflows",
|
||||
"local_llm",
|
||||
"chatbot",
|
||||
"structured_data_extraction"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Rag
|
||||
collapsed: true
|
||||
@@ -30,12 +30,12 @@ LlamaIndex.TS help you prepare the knowledge base with a suite of data connector
|
||||
|
||||

|
||||
|
||||
[**Data Loaders**](/docs/llamaindex/modules/data/readers):
|
||||
[**Data Loaders**](/typescript/framework/modules/data/readers):
|
||||
A data connector (i.e. `Reader`) ingest data from different data sources and data formats into a simple `Document` representation (text and simple metadata).
|
||||
|
||||
[**Documents / Nodes**](/docs/llamaindex/modules/data): A `Document` is a generic container around any data source - for instance, a PDF, an API output, or retrieved data from a database. A `Node` is the atomic unit of data in LlamaIndex and represents a "chunk" of a source `Document`. It's a rich representation that includes metadata and relationships (to other nodes) to enable accurate and expressive retrieval operations.
|
||||
[**Documents / Nodes**](/typescript/framework/modules/data): A `Document` is a generic container around any data source - for instance, a PDF, an API output, or retrieved data from a database. A `Node` is the atomic unit of data in LlamaIndex and represents a "chunk" of a source `Document`. It's a rich representation that includes metadata and relationships (to other nodes) to enable accurate and expressive retrieval operations.
|
||||
|
||||
[**Data Indexes**](/docs/llamaindex/modules/data/data_index):
|
||||
[**Data Indexes**](/typescript/framework/modules/data/data_index):
|
||||
Once you've ingested your data, LlamaIndex helps you index data into a format that's easy to retrieve.
|
||||
|
||||
Under the hood, LlamaIndex parses the raw documents into intermediate representations, calculates vector embeddings, and stores your data in-memory or to disk.
|
||||
@@ -58,19 +58,19 @@ These building blocks can be customized to reflect ranking preferences, as well
|
||||
|
||||
#### Building Blocks
|
||||
|
||||
[**Retrievers**](/docs/llamaindex/modules/rag/retriever):
|
||||
[**Retrievers**](/typescript/framework/modules/rag/retriever):
|
||||
A retriever defines how to efficiently retrieve relevant context from a knowledge base (i.e. index) when given a query.
|
||||
The specific retrieval logic differs for different indices, the most popular being dense retrieval against a vector index.
|
||||
|
||||
[**Response Synthesizers**](/docs/llamaindex/modules/rag/response_synthesizer):
|
||||
[**Response Synthesizers**](/typescript/framework/modules/rag/response_synthesizer):
|
||||
A response synthesizer generates a response from an LLM, using a user query and a given set of retrieved text chunks.
|
||||
|
||||
#### Pipelines
|
||||
|
||||
[**Query Engines**](/docs/llamaindex/modules/rag/query_engines):
|
||||
[**Query Engines**](/typescript/framework/modules/rag/query_engines):
|
||||
A query engine is an end-to-end pipeline that allow you to ask question over your data.
|
||||
It takes in a natural language query, and returns a response, along with reference context retrieved and passed to the LLM.
|
||||
|
||||
[**Chat Engines**](/docs/llamaindex/modules/rag/chat_engine):
|
||||
[**Chat Engines**](/typescript/framework/modules/rag/chat_engine):
|
||||
A chat engine is an end-to-end pipeline for having a conversation with your data
|
||||
(multiple back-and-forth instead of a single question & answer).
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Retrieval Augmented Generation (RAG)
|
||||
---
|
||||
|
||||
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](/docs/llamaindex/tutorials/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](/typescript/framework/tutorials/rag/concepts).
|
||||
|
||||
## Set up the project
|
||||
|
||||
@@ -14,9 +14,9 @@ npm i -D typescript @types/node
|
||||
npm i llamaindex
|
||||
```
|
||||
|
||||
Then, check out the [installation](/docs/llamaindex/getting_started/installation) steps to install LlamaIndex.TS and prepare an OpenAI key.
|
||||
Then, check out the [installation](/typescript/framework/getting_started/installation) steps to install LlamaIndex.TS and prepare an OpenAI key.
|
||||
|
||||
You can use [other LLMs](/docs/llamaindex/modules/models/llms) via their APIs; if you would prefer to use local models check out our [local LLM example](/docs/llamaindex/tutorials/local_llm).
|
||||
You can use [other LLMs](/typescript/framework/modules/models/llms) via their APIs; if you would prefer to use local models check out our [local LLM example](/typescript/framework/tutorials/local_llm).
|
||||
|
||||
## Run queries
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
title: Structured data extraction
|
||||
---
|
||||
|
||||
Make sure you have installed LlamaIndex.TS and have an OpenAI key. If you haven't, check out the [installation](/docs/llamaindex/getting_started/installation) guide.
|
||||
Make sure you have installed LlamaIndex.TS and have an OpenAI key. If you haven't, check out the [installation](/typescript/framework/getting_started/installation) guide.
|
||||
|
||||
You can use [other LLMs](/docs/llamaindex/modules/models/llms) via their APIs; if you would prefer to use local models check out our [local LLM example](/docs/llamaindex/tutorials/local_llm).
|
||||
You can use [other LLMs](/typescript/framework/modules/models/llms) via their APIs; if you would prefer to use local models check out our [local LLM example](/typescript/framework/tutorials/local_llm).
|
||||
|
||||
## Set up
|
||||
|
||||
@@ -46,3 +46,31 @@ You should expect output something like:
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Using the `exec` method
|
||||
|
||||
Many LLMs do not natively support structured output, and often rely exclusively on prompt or context engineering.
|
||||
|
||||
In this sense, we proved you with an alternative for structured data extraction, using the `exec` method with `responseFormat`.
|
||||
|
||||
For example, you can, in a new folder, install our Anthropic integration and `zod` v3:
|
||||
|
||||
```package-install
|
||||
npm init
|
||||
npm i -D typescript @types/node
|
||||
npm i @llamaindex/anthropic zod@3.25.76
|
||||
```
|
||||
|
||||
And then try extracting data with this code:
|
||||
|
||||
<include cwd>../../examples/agents/tools/response-format-exec.ts</include>
|
||||
|
||||
The output should look like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "La Divina Commedia",
|
||||
"author": "Dante Alighieri",
|
||||
"year": 1321
|
||||
}
|
||||
```
|
||||
@@ -173,4 +173,4 @@ You can combine these utilities with other stream operators like `filter` and `m
|
||||
|
||||
## Next Steps
|
||||
|
||||
To learn more about workflows, check out [the Workflows documentation](/docs/llamaindex/modules/agents/workflows).
|
||||
To learn more about workflows, check out [the Workflows documentation](/typescript/framework/modules/agents/workflows).
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
import {
|
||||
type MetadataFilter,
|
||||
type MetadataFilters,
|
||||
type RetrievalParams,
|
||||
runSearchApiV1PipelinesPipelineIdRetrievePost,
|
||||
type TextNodeWithScore,
|
||||
} from "@llamaindex/cloud/api";
|
||||
import { QueryBundle } from "@llamaindex/core/query-engine";
|
||||
import { BaseRetriever } from "@llamaindex/core/retriever";
|
||||
import { jsonToNode, NodeWithScore, ObjectType } from "@llamaindex/core/schema";
|
||||
import { extractText } from "@llamaindex/core/utils";
|
||||
|
||||
export type CloudRetrieveParams = Omit<
|
||||
RetrievalParams,
|
||||
"query" | "search_filters" | "dense_similarity_top_k"
|
||||
> & { similarityTopK?: number; filters?: MetadataFilters };
|
||||
|
||||
export type LlamaCloudRetrieverParams = {
|
||||
apiKey: string;
|
||||
baseUrl: string;
|
||||
pipelineId: string;
|
||||
} & CloudRetrieveParams;
|
||||
|
||||
export class LlamaCloudRetriever extends BaseRetriever {
|
||||
baseUrl: string;
|
||||
apiKey: string;
|
||||
|
||||
retrieveParams: CloudRetrieveParams;
|
||||
organizationId?: string;
|
||||
pipelineId: string;
|
||||
|
||||
private resultNodesToNodeWithScore(
|
||||
nodes: TextNodeWithScore[],
|
||||
): NodeWithScore[] {
|
||||
return nodes.map((node: TextNodeWithScore) => {
|
||||
const textNode = jsonToNode(node.node, ObjectType.TEXT);
|
||||
textNode.metadata = {
|
||||
...textNode.metadata,
|
||||
...node.node.extra_info,
|
||||
};
|
||||
return {
|
||||
node: textNode,
|
||||
score: node.score ?? undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private convertFilter(filters?: MetadataFilters): MetadataFilters | null {
|
||||
if (!filters) return null;
|
||||
|
||||
const processFilter = (
|
||||
filter: MetadataFilter | MetadataFilters,
|
||||
): MetadataFilter | MetadataFilters => {
|
||||
if ("filters" in filter) {
|
||||
// type MetadataFilters
|
||||
return { ...filter, filters: filter.filters.map(processFilter) };
|
||||
}
|
||||
return { ...filter, value: filter.value ?? null };
|
||||
};
|
||||
|
||||
return { ...filters, filters: filters.filters.map(processFilter) };
|
||||
}
|
||||
|
||||
constructor(params: LlamaCloudRetrieverParams) {
|
||||
super();
|
||||
this.baseUrl = params.baseUrl;
|
||||
this.apiKey = params.apiKey;
|
||||
this.retrieveParams = params;
|
||||
this.pipelineId = params.pipelineId;
|
||||
}
|
||||
|
||||
override async _retrieve(query: QueryBundle): Promise<NodeWithScore[]> {
|
||||
const filters = this.convertFilter(this.retrieveParams.filters);
|
||||
const pipelineId = this.pipelineId;
|
||||
|
||||
const { data: results } =
|
||||
await runSearchApiV1PipelinesPipelineIdRetrievePost({
|
||||
throwOnError: true,
|
||||
path: {
|
||||
pipeline_id: pipelineId,
|
||||
},
|
||||
baseUrl: this.baseUrl,
|
||||
body: {
|
||||
...this.retrieveParams,
|
||||
query: extractText(query),
|
||||
search_filters: filters,
|
||||
dense_similarity_top_k: this.retrieveParams.similarityTopK!,
|
||||
},
|
||||
headers: {
|
||||
authorization: `Bearer ${this.apiKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
return this.resultNodesToNodeWithScore(results.retrieval_nodes);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,6 @@
|
||||
"wrangler": "^3.89.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"hono": "^4.6.11"
|
||||
"hono": "^4.9.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,62 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d493015]
|
||||
- llamaindex@0.12.0
|
||||
|
||||
## 0.0.190
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8929dcf]
|
||||
- llamaindex@0.11.29
|
||||
|
||||
## 0.0.189
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.28
|
||||
|
||||
## 0.0.188
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.27
|
||||
|
||||
## 0.0.187
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.26
|
||||
|
||||
## 0.0.186
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [049471b]
|
||||
- llamaindex@0.11.25
|
||||
|
||||
## 0.0.185
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.24
|
||||
|
||||
## 0.0.184
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.23
|
||||
|
||||
## 0.0.183
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- llamaindex@0.11.22
|
||||
|
||||
## 0.0.182
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.182",
|
||||
"version": "0.0.191",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user