mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-01 22:14:03 -04:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c70d7b9930 | |||
| 1b6f368a3f | |||
| 9d951b288f | |||
| 5fe16697a2 | |||
| 189d8a83ac | |||
| 648cfb5cb5 | |||
| eaf326ee90 | |||
| fc1bedf438 | |||
| 164cf7a6df | |||
| e98033e2cc | |||
| c0ffc7b434 | |||
| 9cf88e9f3f | |||
| 75d6e29187 | |||
| 132517877e | |||
| 299008b34f | |||
| 482ed67690 | |||
| 9aeec9089b | |||
| f1db9b3d48 | |||
| 25093531cf | |||
| f8a86e4eff | |||
| 04f8c96caa | |||
| 43053f9e16 | |||
| 93bc0ffd21 | |||
| 58a9446220 | |||
| da06e4550b | |||
| 3fd4cc383e | |||
| 2b39ceffa6 | |||
| 77e24cec65 | |||
| 2a0a899d66 | |||
| 050cd53450 | |||
| 5189b446f4 | |||
| c7ff3233fe | |||
| 21bebfcaa6 | |||
| 91a18e7057 | |||
| d1c1f99e06 | |||
| 8be84aeb5e | |||
| 5b7b314b25 | |||
| 4a51c9b48e | |||
| bf56fc08ad | |||
| fa40b36516 | |||
| da8068e9e0 |
@@ -1,5 +1,60 @@
|
||||
# @llamaindex/doc
|
||||
|
||||
## 0.2.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 648cfb5: Add support for supabase vector store
|
||||
Added doc for the supbase vector store
|
||||
- Updated dependencies [1b6f368]
|
||||
- Updated dependencies [eaf326e]
|
||||
- Updated dependencies [9d951b2]
|
||||
- @llamaindex/core@0.6.1
|
||||
- llamaindex@0.9.14
|
||||
- @llamaindex/cloud@4.0.1
|
||||
- @llamaindex/node-parser@2.0.1
|
||||
- @llamaindex/openai@0.2.1
|
||||
- @llamaindex/readers@3.0.1
|
||||
- @llamaindex/workflow@1.0.1
|
||||
|
||||
## 0.2.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- e98033e: docs: correct the number of indexes
|
||||
|
||||
## 0.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [75d6e29]
|
||||
- llamaindex@0.9.13
|
||||
|
||||
## 0.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- f1db9b3: Adding an options parameter to vercel tool to tailor responses
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 21bebfc: Expose more content to fix the issue with unavailable documentation links, and adjust the documentation based on the latest code.
|
||||
- 2b39cef: Added documentation for structured output in openai and ollama
|
||||
- Updated dependencies [21bebfc]
|
||||
- Updated dependencies [93bc0ff]
|
||||
- Updated dependencies [91a18e7]
|
||||
- Updated dependencies [bf56fc0]
|
||||
- Updated dependencies [f8a86e4]
|
||||
- Updated dependencies [5189b44]
|
||||
- Updated dependencies [58a9446]
|
||||
- @llamaindex/readers@3.0.0
|
||||
- @llamaindex/core@0.6.0
|
||||
- @llamaindex/openai@0.2.0
|
||||
- @llamaindex/cloud@4.0.0
|
||||
- @llamaindex/workflow@1.0.0
|
||||
- llamaindex@0.9.12
|
||||
- @llamaindex/node-parser@2.0.0
|
||||
|
||||
## 0.1.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -4,6 +4,8 @@ const withMDX = createMDX();
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const config = {
|
||||
// default timeout for static generation is 60s, but we need to increase it to 10 minutes due to the large number of document pages
|
||||
staticPageGenerationTimeout: 600,
|
||||
reactStrictMode: true,
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.1.11",
|
||||
"version": "0.2.3",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "fumadocs-mdx",
|
||||
@@ -8,8 +8,9 @@
|
||||
"build": "next build",
|
||||
"dev": "next dev",
|
||||
"start": "next start",
|
||||
"postbuild": "tsx scripts/post-build.mts",
|
||||
"build:docs": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" typedoc && tsx scripts/generate-docs.mts"
|
||||
"postbuild": "tsx scripts/post-build.mts && tsx scripts/validate-links.mts",
|
||||
"build:docs": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" typedoc && tsx scripts/generate-docs.mts",
|
||||
"validate-links": "tsx scripts/validate-links.mts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@icons-pack/react-simple-icons": "^10.1.0",
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
import glob from "fast-glob";
|
||||
import fs from "fs";
|
||||
import matter from "gray-matter";
|
||||
import path from "path";
|
||||
|
||||
const CONTENT_DIR = path.join(process.cwd(), "src/content/docs");
|
||||
const BUILD_DIR = path.join(process.cwd(), ".next");
|
||||
|
||||
// Regular expression to find internal links
|
||||
// This captures Markdown links [text](/docs/path) and href attributes href="/docs/path"
|
||||
const INTERNAL_LINK_REGEX = /(?:(?:\]\(|\bhref=["'])\/docs\/([^")]+))/g;
|
||||
|
||||
// Regular expression to find relative links
|
||||
// This captures relative links like [text](./path) or 
|
||||
const RELATIVE_LINK_REGEX = /(?:\]\()(?:\s*)(?:\.\.?)\//g;
|
||||
|
||||
interface LinkValidationResult {
|
||||
file: string;
|
||||
invalidLinks: Array<{ link: string; line: number }>;
|
||||
}
|
||||
|
||||
interface RelativeLinkResult {
|
||||
file: string;
|
||||
relativeLinks: Array<{ line: number; lineContent: string }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all valid documentation routes from the content directory
|
||||
*/
|
||||
async function getValidRoutes(): Promise<Set<string>> {
|
||||
const mdxFiles = await glob("**/*.mdx", { cwd: CONTENT_DIR });
|
||||
|
||||
const routes = new Set<string>();
|
||||
|
||||
// Add each MDX file as a valid route
|
||||
for (const file of mdxFiles) {
|
||||
// Remove .mdx extension and normalize to route format
|
||||
let route = file.replace(/\.mdx$/, "");
|
||||
|
||||
// Handle index files
|
||||
if (route.endsWith("/index")) {
|
||||
route = route.replace(/\/index$/, "");
|
||||
} else if (route === "index") {
|
||||
route = "";
|
||||
}
|
||||
|
||||
routes.add(route);
|
||||
}
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract internal links from a MDX file
|
||||
*/
|
||||
function extractLinksFromFile(
|
||||
filePath: string,
|
||||
): Array<{ link: string; line: number }> {
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const { content: mdxContent } = matter(content);
|
||||
|
||||
const lines = mdxContent.split("\n");
|
||||
const links: Array<{ link: string; line: number }> = [];
|
||||
|
||||
lines.forEach((line, lineNumber) => {
|
||||
let match;
|
||||
while ((match = INTERNAL_LINK_REGEX.exec(line)) !== null) {
|
||||
if (match[1]) {
|
||||
links.push({
|
||||
link: match[1],
|
||||
line: lineNumber + 1, // 1-based line numbers
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a link is an image link
|
||||
*/
|
||||
function isImageLink(link: string): boolean {
|
||||
// Check for image extensions
|
||||
const imageExtensions = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"];
|
||||
const hasImageExtension = imageExtensions.some((ext) =>
|
||||
link.toLowerCase().endsWith(ext),
|
||||
);
|
||||
|
||||
// Check for markdown image syntax: 
|
||||
const isMarkdownImage = link.trim().startsWith("!");
|
||||
|
||||
return hasImageExtension || isMarkdownImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract relative links from a MDX file
|
||||
*/
|
||||
function findRelativeLinksInFile(
|
||||
filePath: string,
|
||||
): Array<{ line: number; lineContent: string }> {
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const { content: mdxContent } = matter(content);
|
||||
|
||||
const lines = mdxContent.split("\n");
|
||||
const relativeLinks: Array<{ line: number; lineContent: string }> = [];
|
||||
|
||||
lines.forEach((line, lineNumber) => {
|
||||
// Check for relative links
|
||||
if (RELATIVE_LINK_REGEX.test(line)) {
|
||||
// Reset the regex lastIndex to start from the beginning of the line
|
||||
RELATIVE_LINK_REGEX.lastIndex = 0;
|
||||
|
||||
// Skip image links
|
||||
if (!isImageLink(line)) {
|
||||
relativeLinks.push({
|
||||
line: lineNumber + 1, // 1-based line numbers
|
||||
lineContent: line.trim(),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return relativeLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate internal links in all MDX files
|
||||
*/
|
||||
/**
|
||||
* Find relative links in all MDX files
|
||||
*/
|
||||
async function findRelativeLinks(): Promise<RelativeLinkResult[]> {
|
||||
const mdxFiles = await glob("**/*.mdx", { cwd: CONTENT_DIR });
|
||||
const results: RelativeLinkResult[] = [];
|
||||
|
||||
for (const file of mdxFiles) {
|
||||
const filePath = path.join(CONTENT_DIR, file);
|
||||
const relativeLinks = findRelativeLinksInFile(filePath);
|
||||
|
||||
if (relativeLinks.length > 0) {
|
||||
results.push({
|
||||
file,
|
||||
relativeLinks,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
async function validateLinks(): Promise<LinkValidationResult[]> {
|
||||
const mdxFiles = await glob("**/*.mdx", { cwd: CONTENT_DIR });
|
||||
const validRoutes = await getValidRoutes();
|
||||
|
||||
const results: LinkValidationResult[] = [];
|
||||
|
||||
for (const file of mdxFiles) {
|
||||
const filePath = path.join(CONTENT_DIR, file);
|
||||
const links = extractLinksFromFile(filePath);
|
||||
|
||||
const invalidLinks = links.filter(({ link }) => {
|
||||
// Check if the link exists in valid routes
|
||||
// First normalize the link (remove any query string or hash)
|
||||
const baseLink = link.split("?")[0].split("#")[0];
|
||||
// Remove the trailing slash if present.
|
||||
// This works with links like "api/interfaces/MetadataFilter#operator" and "api/interfaces/MetadataFilter/#operator".
|
||||
const normalizedLink = baseLink.endsWith("/")
|
||||
? baseLink.slice(0, -1)
|
||||
: baseLink;
|
||||
|
||||
// Remove llamaindex/ prefix if it exists as it's the root of the docs
|
||||
let routePath = normalizedLink;
|
||||
if (routePath.startsWith("llamaindex/")) {
|
||||
routePath = routePath.substring("llamaindex/".length);
|
||||
}
|
||||
|
||||
return !validRoutes.has(normalizedLink) && !validRoutes.has(routePath);
|
||||
});
|
||||
|
||||
if (invalidLinks.length > 0) {
|
||||
results.push({
|
||||
file,
|
||||
invalidLinks,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function to validate links and report errors
|
||||
*/
|
||||
async function main() {
|
||||
console.log("🔍 Validating links in documentation...");
|
||||
|
||||
try {
|
||||
// Check for invalid internal links
|
||||
const validationResults: LinkValidationResult[] = await validateLinks();
|
||||
// Check for relative links
|
||||
const relativeLinksResults = await findRelativeLinks();
|
||||
|
||||
let hasErrors = false;
|
||||
|
||||
// Report invalid internal links
|
||||
if (validationResults.length > 0) {
|
||||
console.error("❌ Found invalid internal links:");
|
||||
hasErrors = true;
|
||||
|
||||
for (const result of validationResults) {
|
||||
console.error(`\nFile: ${result.file}`);
|
||||
|
||||
for (const { link, line } of result.invalidLinks) {
|
||||
console.error(` - Line ${line}: /docs/${link}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Report relative links
|
||||
if (relativeLinksResults.length > 0) {
|
||||
console.error("\n❌ Found relative links (use absolute paths instead):");
|
||||
hasErrors = true;
|
||||
|
||||
for (const result of relativeLinksResults) {
|
||||
console.error(`\nFile: ${result.file}`);
|
||||
|
||||
for (const { line, lineContent } of result.relativeLinks) {
|
||||
console.error(` - Line ${line}: ${lineContent}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasErrors) {
|
||||
// Exit with error code to fail the build
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log("✅ All links are valid!");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error validating links:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("Unhandled error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -11,8 +11,6 @@ import {
|
||||
} from "fumadocs-ui/page";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
const { AutoTypeTable } = createTypeTable();
|
||||
|
||||
export const revalidate = false;
|
||||
|
||||
export default async function Page(props: {
|
||||
@@ -22,6 +20,7 @@ export default async function Page(props: {
|
||||
const page = source.getPage(params.slug);
|
||||
if (!page) notFound();
|
||||
|
||||
const { AutoTypeTable } = createTypeTable();
|
||||
const MDX = page.data.body;
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
title: Agents
|
||||
---
|
||||
|
||||
A built-in agent that can take decisions and reasoning based on the tools provided to it.
|
||||
|
||||
## OpenAI Agent
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/agent/openai";
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
title: Gemini Agent
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSourceGemini from "!raw-loader!../../../../../../../examples/gemini/agent.ts";
|
||||
|
||||
## Installation
|
||||
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
<Tabs groupId="install" items={["npm", "yarn", "pnpm"]} persist>
|
||||
```shell tab="npm"
|
||||
npm install llamaindex @llamaindex/google
|
||||
```
|
||||
|
||||
```shell tab="yarn"
|
||||
yarn add llamaindex @llamaindex/google
|
||||
```
|
||||
|
||||
```shell tab="pnpm"
|
||||
pnpm add llamaindex @llamaindex/google
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
## Source
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSourceGemini} />
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: Chat Engine
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/chatEngine";
|
||||
|
||||
Chat Engine is a class that allows you to create a chatbot from a retriever. It is a wrapper around a retriever that allows you to chat with it in a conversational manner.
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
@@ -1,59 +0,0 @@
|
||||
---
|
||||
title: Context-Aware Agent
|
||||
---
|
||||
|
||||
The Context-Aware Agent enhances the capabilities of standard LLM agents by incorporating relevant context from a retriever for each query. This allows the agent to provide more informed and specific responses based on the available information.
|
||||
|
||||
## Usage
|
||||
|
||||
Here's a simple example of how to use the Context-Aware Agent:
|
||||
|
||||
```typescript
|
||||
import {
|
||||
Document,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
import { OpenAI, OpenAIContextAwareAgent } from "@llamaindex/openai";
|
||||
|
||||
async function createContextAwareAgent() {
|
||||
// Create and index some documents
|
||||
const documents = [
|
||||
new Document({
|
||||
text: "LlamaIndex is a data framework for LLM applications.",
|
||||
id_: "doc1",
|
||||
}),
|
||||
new Document({
|
||||
text: "The Eiffel Tower is located in Paris, France.",
|
||||
id_: "doc2",
|
||||
}),
|
||||
];
|
||||
|
||||
const index = await VectorStoreIndex.fromDocuments(documents);
|
||||
const retriever = index.asRetriever({ similarityTopK: 1 });
|
||||
|
||||
// Create the Context-Aware Agent
|
||||
const agent = new OpenAIContextAwareAgent({
|
||||
llm: new OpenAI({ model: "gpt-3.5-turbo" }),
|
||||
contextRetriever: retriever,
|
||||
});
|
||||
|
||||
// Use the agent to answer queries
|
||||
const response = await agent.chat({
|
||||
message: "What is LlamaIndex used for?",
|
||||
});
|
||||
|
||||
console.log("Agent Response:", response.response);
|
||||
}
|
||||
|
||||
createContextAwareAgent().catch(console.error);
|
||||
```
|
||||
|
||||
In this example, the Context-Aware Agent uses the retriever to fetch relevant context for each query, allowing it to provide more accurate and informed responses based on the indexed documents.
|
||||
|
||||
## Key Components
|
||||
|
||||
- `contextRetriever`: A retriever (e.g., from a VectorStoreIndex) that fetches relevant documents or passages for each query.
|
||||
|
||||
## Available Context-Aware Agents
|
||||
|
||||
- `OpenAIContextAwareAgent`: A context-aware agent using OpenAI's models.
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"title": "Examples",
|
||||
"pages": [
|
||||
"more_examples",
|
||||
"chat_engine",
|
||||
"vector_index",
|
||||
"summary_index",
|
||||
"save_load_index",
|
||||
"context_aware_agent",
|
||||
"agent",
|
||||
"agent_gemini",
|
||||
"local_llm",
|
||||
"other_llms"
|
||||
]
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
---
|
||||
title: Using other LLM APIs
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/mistral";
|
||||
|
||||
By default LlamaIndex.TS uses OpenAI's LLMs and embedding models, but we support [lots of other LLMs](../modules/llms) including models from Mistral (Mistral, Mixtral), Anthropic (Claude) and Google (Gemini).
|
||||
|
||||
If you don't want to use an API at all you can [run a local model](./local_llm).
|
||||
|
||||
This example runs you through the process of setting up a Mistral model:
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
<Tabs groupId="install" items={["npm", "yarn", "pnpm"]} persist>
|
||||
```shell tab="npm"
|
||||
npm install llamaindex @llamaindex/mistral
|
||||
```
|
||||
|
||||
```shell tab="yarn"
|
||||
yarn add llamaindex @llamaindex/mistral
|
||||
```
|
||||
|
||||
```shell tab="pnpm"
|
||||
pnpm add llamaindex @llamaindex/mistral
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
## Using another LLM
|
||||
|
||||
You can specify what LLM LlamaIndex.TS will use on the `Settings` object, like this:
|
||||
|
||||
```typescript
|
||||
import { MistralAI } from "@llamaindex/mistral";
|
||||
import { Settings } from "llamaindex";
|
||||
|
||||
Settings.llm = new MistralAI({
|
||||
model: "mistral-tiny",
|
||||
apiKey: "<YOUR_API_KEY>",
|
||||
});
|
||||
```
|
||||
|
||||
You can see examples of other APIs we support by checking out "Available LLMs" in the sidebar of our [LLMs section](../modules/llms).
|
||||
|
||||
## Using another embedding model
|
||||
|
||||
A frequent gotcha when trying to use a different API as your LLM is that LlamaIndex will also by default index and embed your data using OpenAI's embeddings. To completely switch away from OpenAI you will need to set your embedding model as well, for example:
|
||||
|
||||
```typescript
|
||||
import { MistralAIEmbedding } from "@llamaindex/mistral";
|
||||
import { Settings } from "llamaindex";
|
||||
|
||||
Settings.embedModel = new MistralAIEmbedding();
|
||||
```
|
||||
|
||||
We support [many different embeddings](../modules/embeddings).
|
||||
|
||||
## Full example
|
||||
|
||||
This example uses Mistral's `mistral-tiny` model as the LLM and Mistral for embeddings as well.
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
title: Save/Load an Index
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/storageContext";
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
title: Summary Index
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/summaryIndex";
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
title: Vector Index
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/vectorIndex";
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
+1
-5
@@ -1,11 +1,7 @@
|
||||
---
|
||||
title: Chatbot tutorial
|
||||
title: Create-Llama
|
||||
---
|
||||
|
||||
Once you've mastered basic [retrieval-augment generation](retrieval_augmented_generation) you may want to create an interface to chat with your data. You can do this step-by-step, but we recommend getting started quickly using `create-llama`.
|
||||
|
||||
## Using create-llama
|
||||
|
||||
`create-llama` is a powerful but easy to use command-line tool that generates a working, full-stack web application that allows you to chat with your data. You can learn more about it on [the `create-llama` README page](https://www.npmjs.com/package/create-llama).
|
||||
|
||||
Run it once and it will ask you a series of questions about the kind of application you want to generate. Then you can customize your application to suit your use-case. To get started, run:
|
||||
+13
-2
@@ -1,10 +1,10 @@
|
||||
---
|
||||
title: See all examples
|
||||
title: Code examples
|
||||
---
|
||||
|
||||
Our GitHub repository has a wealth of examples to explore and try out. You can check out our [examples folder](https://github.com/run-llama/LlamaIndexTS/tree/main/examples) to see them all at once, or browse the pages in this section for some selected highlights.
|
||||
|
||||
## Check out all examples
|
||||
## Use examples locally
|
||||
|
||||
It may be useful to check out all the examples at once so you can try them out locally. To do this into a folder called `my-new-project`, run these commands:
|
||||
|
||||
@@ -19,3 +19,14 @@ Then you can run any example in the folder with `tsx`, e.g.:
|
||||
```bash npm2yarn
|
||||
npx tsx ./vectorIndex.ts
|
||||
```
|
||||
|
||||
## Try examples online
|
||||
|
||||
You can also try the examples online using StackBlitz:
|
||||
|
||||
<iframe
|
||||
className="w-full h-[440px]"
|
||||
aria-label="LlamaIndex.TS Examples"
|
||||
aria-description="This is a list of examples for LlamaIndex.TS."
|
||||
src="https://stackblitz.com/github/run-llama/LlamaIndexTS/tree/main/examples?file=README.md"
|
||||
/>
|
||||
+1
-1
@@ -14,7 +14,7 @@ Before you start, make sure you have try LlamaIndex.TS in Node.js to make sure y
|
||||
|
||||
<Card
|
||||
title="Getting Started with LlamaIndex.TS in Node.js"
|
||||
href="/docs/llamaindex/getting_started/setup/node"
|
||||
href="/docs/llamaindex/getting_started/frameworks/node"
|
||||
/>
|
||||
|
||||
Also, you need have the basic understanding of <a href='https://developers.cloudflare.com/workers/'><SiCloudflareworkers className="inline mr-2" color="#F38020" />Cloudflare Worker</a>.
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Choose Framework
|
||||
title: Frameworks
|
||||
description: We support multiple JS runtime and frameworks, bundlers.
|
||||
---
|
||||
import {
|
||||
@@ -15,28 +15,28 @@ import {
|
||||
<>
|
||||
<SiNodedotjs className="inline" color="#5FA04E" /> Node.js
|
||||
</>
|
||||
} href="/docs/llamaindex/getting_started/setup/node" />
|
||||
} href="/docs/llamaindex/getting_started/frameworks/node" />
|
||||
<Card title={
|
||||
<>
|
||||
<SiTypescript className="inline" color="#3178C6" /> TypeScript
|
||||
</>
|
||||
} href="/docs/llamaindex/getting_started/setup/typescript" />
|
||||
} href="/docs/llamaindex/getting_started/frameworks/typescript" />
|
||||
<Card title={
|
||||
<>
|
||||
<SiVite className='inline' color='#646CFF' /> Vite
|
||||
</>
|
||||
} href="/docs/llamaindex/getting_started/setup/vite" />
|
||||
} href="/docs/llamaindex/getting_started/frameworks/vite" />
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<SiNextdotjs className='inline' /> Next.js (React Server Component)
|
||||
</>
|
||||
}
|
||||
href="/docs/llamaindex/getting_started/setup/next"
|
||||
href="/docs/llamaindex/getting_started/frameworks/next"
|
||||
/>
|
||||
<Card title={
|
||||
<>
|
||||
<SiCloudflareworkers className='inline' color='#F38020' /> Cloudflare Workers
|
||||
</>
|
||||
} href="/docs/llamaindex/getting_started/setup/cloudflare" />
|
||||
} href="/docs/llamaindex/getting_started/frameworks/cloudflare" />
|
||||
</Cards>
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"title": "Framework",
|
||||
"description": "The setup guide",
|
||||
"defaultOpen": true,
|
||||
"pages": ["node", "typescript", "next", "vite", "cloudflare"]
|
||||
}
|
||||
+2
-2
@@ -7,7 +7,7 @@ Before you start, make sure you have try LlamaIndex.TS in Node.js to make sure y
|
||||
|
||||
<Card
|
||||
title="Getting Started with LlamaIndex.TS in Node.js"
|
||||
href="/docs/llamaindex/getting_started/setup/node"
|
||||
href="/docs/llamaindex/getting_started/frameworks/node"
|
||||
/>
|
||||
|
||||
## Differences between Node.js and Next.js
|
||||
@@ -35,7 +35,7 @@ If you see any dependency issues, you are welcome to open an issue on the GitHub
|
||||
|
||||
## Edge Runtime
|
||||
|
||||
[Vercel Edge Runtime](https://edge-runtime.vercel.app/) is a subset of Node.js APIs. Similar to [Cloudflare Workers](./cloudflare#difference-between-nodejs-and-cloudflare-worker),
|
||||
[Vercel Edge Runtime](https://edge-runtime.vercel.app/) is a subset of Node.js APIs. Similar to [Cloudflare Workers](/docs/llamaindex/getting_started/frameworks/cloudflare#difference-between-nodejs-and-cloudflare-worker),
|
||||
it is a serverless platform that runs your code on the edge.
|
||||
|
||||
Not all features of Node.js are supported in Vercel Edge Runtime, so does LlamaIndex.TS, we are working on more compatibility with all JavaScript runtimes.
|
||||
+2
-2
@@ -42,11 +42,11 @@ By the default, we are using `js-tiktoken` for tokenization. You can install `gp
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
> Note: This only works for Node.js
|
||||
**Note**: This only works for Node.js
|
||||
|
||||
## TypeScript support
|
||||
|
||||
<Card
|
||||
title="Getting Started with LlamaIndex.TS in TypeScript"
|
||||
href="/docs/llamaindex/getting_started/setup/typescript"
|
||||
href="/docs/llamaindex/getting_started/frameworks/typescript"
|
||||
/>
|
||||
+1
-1
@@ -7,7 +7,7 @@ Before you start, make sure you have try LlamaIndex.TS in Node.js to make sure y
|
||||
|
||||
<Card
|
||||
title="Getting Started with LlamaIndex.TS in Node.js"
|
||||
href="/docs/llamaindex/getting_started/setup/node"
|
||||
href="/docs/llamaindex/getting_started/frameworks/node"
|
||||
/>
|
||||
|
||||
Also, make sure you have a basic understanding of [Vite](https://vitejs.dev/).
|
||||
|
Before Width: | Height: | Size: 540 KiB After Width: | Height: | Size: 540 KiB |
@@ -37,20 +37,20 @@ In most cases, you'll also need an LLM package to use LlamaIndex. For example, t
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
Go to [Using other LLM APIs](/docs/llamaindex/examples/other_llms) to find out how to use other LLMs.
|
||||
Go to [LLM APIs](/docs/llamaindex/modules/llms) to find out how to use other LLMs.
|
||||
|
||||
|
||||
## What's next?
|
||||
|
||||
<Cards>
|
||||
<Card
|
||||
title="I want to try LlamaIndex.TS"
|
||||
description="Learn how to use LlamaIndex.TS with different JS runtime and frameworks."
|
||||
href="/docs/llamaindex/getting_started/setup"
|
||||
title="Learn LlamaIndex.TS"
|
||||
description="Learn how to use LlamaIndex.TS by starting with one of our tutorials."
|
||||
href="/docs/llamaindex/tutorials/rag"
|
||||
/>
|
||||
<Card
|
||||
title="Show me code examples"
|
||||
description="Explore code examples using LlamaIndex.TS."
|
||||
href="https://stackblitz.com/github/run-llama/LlamaIndexTS/tree/main/examples?file=README.md"
|
||||
href="/docs/llamaindex/getting_started/examples"
|
||||
/>
|
||||
</Cards>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"title": "Getting Started",
|
||||
"pages": ["index", "setup", "starter_tutorial", "environments", "concepts"]
|
||||
"pages": ["index", "create_llama", "examples", "frameworks"]
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"title": "Setup",
|
||||
"description": "The setup guide",
|
||||
"defaultOpen": true,
|
||||
"pages": ["index", "next", "node", "typescript", "vite", "cloudflare"]
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"title": "Starter Tutorials",
|
||||
"pages": [
|
||||
"retrieval_augmented_generation",
|
||||
"chatbot",
|
||||
"structured_data_extraction",
|
||||
"agent"
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
title: Cost Analysis
|
||||
---
|
||||
|
||||
This page shows how to track LLM cost using APIs.
|
||||
|
||||
## Callback Manager
|
||||
|
||||
The callback manager is a class that manages the callback functions.
|
||||
|
||||
You can register `llm-start`, `llm-end`, and `llm-stream` callbacks to the callback manager for tracking the cost.
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/recipes/cost-analysis";
|
||||
|
||||
<DynamicCodeBlock lang="ts" code={CodeSource} />
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"title": "Guide",
|
||||
"description": "See our guide",
|
||||
"pages": ["loading", "workflow", "chat", "agents", "cost-analysis"]
|
||||
}
|
||||
@@ -16,9 +16,13 @@ The TypeScript implementation is designed for JavaScript server side application
|
||||
|
||||
LlamaIndex.TS provides tools for beginners, advanced users, and everyone in between.
|
||||
|
||||
Try it out with a starter example using StackBlitz:
|
||||
|
||||
<iframe
|
||||
className="w-full h-[440px]"
|
||||
aria-label="LlamaIndex.TS Starter"
|
||||
aria-description="This is a starter example for LlamaIndex.TS, it shows the basic usage of the library."
|
||||
src="https://stackblitz.com/github/run-llama/LlamaIndexTS/tree/main/examples?embed=1&file=starter.ts"
|
||||
/>
|
||||
|
||||
You'll need an OpenAI API key to run this example. You can retrieve it from [OpenAI](https://platform.openai.com/api-keys).
|
||||
@@ -84,6 +84,7 @@ const queryTool = llamaindex({
|
||||
model: openai("gpt-4"),
|
||||
index,
|
||||
description: "Search through the documents",
|
||||
options: { fields: ["sourceNodes", "messages"]}
|
||||
});
|
||||
|
||||
// Use the tool with Vercel's AI SDK
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
"root": true,
|
||||
"pages": [
|
||||
"---Guide---",
|
||||
"what-is-llamaindex",
|
||||
"index",
|
||||
"getting_started",
|
||||
"migration",
|
||||
"guide",
|
||||
"examples",
|
||||
"tutorials",
|
||||
"modules",
|
||||
"integration"
|
||||
"integration",
|
||||
"migration"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ Now:
|
||||
import { SimpleDirectoryReader } from "@llamaindex/readers/directory";
|
||||
```
|
||||
|
||||
For more details about available data loaders and their usage, check the [Loading Data](/docs/llamaindex/guide/loading).
|
||||
For more details about available data loaders and their usage, check the [Loading Data](/docs/llamaindex/modules/loading).
|
||||
|
||||
### 4. Prefer using `llamaindex` instead of `@llamaindex/core`
|
||||
|
||||
|
||||
+2
-5
@@ -2,6 +2,8 @@
|
||||
title: Agents
|
||||
---
|
||||
|
||||
**Note**: Agents are deprecated, use [Agent Workflows](/docs/llamaindex/modules/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:
|
||||
|
||||
- Breaking down a complex question into smaller ones
|
||||
@@ -19,11 +21,6 @@ LlamaIndex.TS comes with a few built-in agents, but you can also create your own
|
||||
- ReACT Agent
|
||||
- Meta3.1 504B via Bedrock (in `@llamaIndex/community`)
|
||||
|
||||
## Examples
|
||||
|
||||
- [OpenAI Agent](/docs/llamaindex/examples/agent)
|
||||
- [Gemini Agent](/docs/llamaindex/examples/agent_gemini)
|
||||
|
||||
## Api References
|
||||
|
||||
- [OpenAIAgent](/docs/api/classes/OpenAIAgent)
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"title": "Migration",
|
||||
"description": "Migration between different versions",
|
||||
"pages": ["0.8-to-0.9"]
|
||||
"pages": ["0.8-to-0.9", "deprecated"]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: Agent Workflow
|
||||
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` 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`](/docs/llamaindex/modules/workflows) system and provides a streamlined interface for agent interactions.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import { ChatDemoRSC } from '../../../../../components/demo/chat/rsc/demo';
|
||||
|
||||
Using [chat-ui](https://github.com/run-llama/chat-ui), it's easy to add a chat interface to your LlamaIndexTS application using [Next.js RSC](https://nextjs.org/docs/app/building-your-application/rendering/server-components) and [Vercel AI RSC](https://sdk.vercel.ai/docs/ai-sdk-rsc/overview).
|
||||
|
||||
With RSC, the chat messages are not returned as JSON from the server (like when using an [API route](./chat)), instead the chat message components are rendered on the server side.
|
||||
With RSC, the chat messages are not returned as JSON from the server (like when using an [API route](/docs/llamaindex/modules/chat/chat)), instead the chat message components are rendered on the server side.
|
||||
This is for example useful for rendering a whole chat history on the server before sending it to the client. [Check here](https://sdk.vercel.ai/docs/getting-started/navigating-the-library#when-to-use-ai-sdk-rsc), for a discussion of when to use use RSC.
|
||||
|
||||
For implementing a chat interface with RSC, you need to create an AI action and then connect the chat interface to use it.
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Index
|
||||
---
|
||||
|
||||
An index is the basic container and organization for your data. LlamaIndex.TS supports two indexes:
|
||||
An index is the basic container and organization for your data. 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.
|
||||
- `SummaryIndex` - will send every `Node` in the index to the LLM in order to generate a response
|
||||
|
||||
@@ -35,7 +35,7 @@ Currently, the following readers are mapped to specific file types:
|
||||
|
||||
- [TextFileReader](/docs/api/classes/TextFileReader): `.txt`
|
||||
- [PDFReader](/docs/api/classes/PDFReader): `.pdf`
|
||||
- [PapaCSVReader](/docs/api/classes/PapaCSVReader): `.csv`
|
||||
- [CSVReader](/docs/api/classes/CSVReader): `.csv`
|
||||
- [MarkdownReader](/docs/api/classes/MarkdownReader): `.md`
|
||||
- [DocxReader](/docs/api/classes/DocxReader): `.docx`
|
||||
- [HTMLReader](/docs/api/classes/HTMLReader): `.htm`, `.html`
|
||||
|
||||
@@ -6,11 +6,11 @@ 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](/docs/llamaindex/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.
|
||||
|
||||
## API Reference
|
||||
|
||||
- [BaseChatStore](/docs/api/interfaces/BaseChatStore)
|
||||
- [BaseChatStore](/docs/api/classes/BaseChatStore)
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
title: Document Stores
|
||||
---
|
||||
|
||||
Document stores contain ingested document chunks, i.e. [Node](/docs/llamaindex/modules/documents_and_nodes/index)s.
|
||||
Document stores contain ingested document chunks, i.e. [Node](/docs/llamaindex/modules/documents_and_nodes)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](/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).
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ Index stores are underlying storage components that contain metadata(i.e. inform
|
||||
|
||||
## 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](/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).
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -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/index) and [Index Stores](/docs/llamaindex/modules/data_stores/index_stores/index)
|
||||
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)
|
||||
|
||||
## 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](/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).
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
|
||||
@@ -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](/docs/llamaindex/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/)
|
||||
@@ -19,6 +19,3 @@ Available Vector Stores are shown on the sidebar to the left. Additionally the f
|
||||
|
||||
Check the [LlamaIndexTS Github](https://github.com/run-llama/LlamaIndexTS) for the most up to date overview of integrations.
|
||||
|
||||
## API Reference
|
||||
|
||||
- [BaseVectorStore](/docs/api/classes/BaseVectorStore)
|
||||
|
||||
@@ -56,10 +56,10 @@ const vectorStore = new QdrantVectorStore({
|
||||
|
||||
```ts
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
vectorStore,
|
||||
});
|
||||
const storageContext = await storageContextFromDefaults({ vectorStore });
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
storageContext,
|
||||
});
|
||||
```
|
||||
|
||||
## Query the index
|
||||
@@ -91,11 +91,11 @@ async function main() {
|
||||
});
|
||||
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
|
||||
const storageContext = await storageContextFromDefaults({ vectorStore });
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
vectorStore,
|
||||
storageContext,
|
||||
});
|
||||
|
||||
|
||||
const queryEngine = index.asQueryEngine();
|
||||
|
||||
const response = await queryEngine.query({
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
---
|
||||
title: Supabase Vector Store
|
||||
---
|
||||
|
||||
[supabase.com](https://supabase.com/)
|
||||
|
||||
To use this vector store, you need a Supabase project. You can create one at [supabase.com](https://supabase.com/).
|
||||
|
||||
## Installation
|
||||
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
<Tabs groupId="install" items={["npm", "yarn", "pnpm"]} persist>
|
||||
```shell tab="npm"
|
||||
npm install llamaindex @llamaindex/supabase
|
||||
```
|
||||
|
||||
```shell tab="yarn"
|
||||
yarn add llamaindex @llamaindex/supabase
|
||||
```
|
||||
|
||||
```shell tab="pnpm"
|
||||
pnpm add llamaindex @llamaindex/supabase
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
## Database Setup
|
||||
|
||||
Before using the vector store, you need to:
|
||||
1. Enable the `pgvector` extension
|
||||
2. Create a table for storing vectors
|
||||
3. Create a vector similarity search function
|
||||
|
||||
```sql
|
||||
create table documents (
|
||||
id uuid primary key,
|
||||
content text,
|
||||
metadata jsonb,
|
||||
embedding vector(1536)
|
||||
);
|
||||
```
|
||||
|
||||
-- Create a function for similarity search
|
||||
```sql
|
||||
create function match_documents (
|
||||
query_embedding vector(1536),
|
||||
match_count int
|
||||
) returns table (
|
||||
id uuid,
|
||||
content text,
|
||||
metadata jsonb,
|
||||
embedding vector(1536),
|
||||
similarity float
|
||||
)
|
||||
language plpgsql
|
||||
as $$
|
||||
begin
|
||||
return query
|
||||
select
|
||||
id,
|
||||
content,
|
||||
metadata,
|
||||
embedding,
|
||||
1 - (embedding <=> query_embedding) as similarity
|
||||
from documents
|
||||
order by embedding <=> query_embedding
|
||||
limit match_count;
|
||||
end;
|
||||
$$;
|
||||
```
|
||||
|
||||
## Importing the modules
|
||||
|
||||
```ts
|
||||
import { Document, VectorStoreIndex } from "llamaindex";
|
||||
import { SupabaseVectorStore } from "@llamaindex/supabase";
|
||||
```
|
||||
|
||||
## Setup Supabase
|
||||
|
||||
```ts
|
||||
const vectorStore = new SupabaseVectorStore({
|
||||
supabaseUrl: process.env.SUPABASE_URL,
|
||||
supabaseKey: process.env.SUPABASE_KEY,
|
||||
table: "documents",
|
||||
});
|
||||
```
|
||||
|
||||
## Setup the index
|
||||
|
||||
```ts
|
||||
const documents = [
|
||||
new Document({
|
||||
text: "Sample document text",
|
||||
metadata: { source: "example" }
|
||||
})
|
||||
];
|
||||
|
||||
const storageContext = await storageContextFromDefaults({ vectorStore });
|
||||
const index = await VectorStoreIndex.fromDocuments(documents, {
|
||||
storageContext,
|
||||
});
|
||||
```
|
||||
|
||||
## Query the index
|
||||
|
||||
```ts
|
||||
const queryEngine = index.asQueryEngine();
|
||||
|
||||
const response = await queryEngine.query({
|
||||
query: "What is in the document?",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
```
|
||||
|
||||
## Full code
|
||||
|
||||
```ts
|
||||
import { Document, VectorStoreIndex, storageContextFromDefaults } from "llamaindex";
|
||||
import { SupabaseVectorStore } from "@llamaindex/supabase";
|
||||
|
||||
async function main() {
|
||||
// Initialize the vector store
|
||||
const vectorStore = new SupabaseVectorStore({
|
||||
supabaseUrl: process.env.SUPABASE_URL,
|
||||
supabaseKey: process.env.SUPABASE_KEY,
|
||||
table: "documents",
|
||||
});
|
||||
|
||||
// Create sample documents
|
||||
const documents = [
|
||||
new Document({
|
||||
text: "Vector search enables semantic similarity search",
|
||||
metadata: {
|
||||
source: "research_paper",
|
||||
author: "Jane Smith",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
// Create storage context
|
||||
const storageContext = await storageContextFromDefaults({ vectorStore });
|
||||
|
||||
// Create and store embeddings
|
||||
const index = await VectorStoreIndex.fromDocuments(documents, {
|
||||
storageContext,
|
||||
});
|
||||
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const response = await queryEngine.query({
|
||||
query: "What is vector search?",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
- [SupabaseVectorStore](/docs/api/classes/SupabaseVectorStore)
|
||||
@@ -4,7 +4,7 @@ title: Embedding
|
||||
|
||||
The embedding model in LlamaIndex is responsible for creating numerical representations of text. By default, LlamaIndex will use the `text-embedding-ada-002` model from OpenAI.
|
||||
|
||||
This can be explicitly updated through `Settings`
|
||||
This can be explicitly updated through `Settings.embedModel`.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -35,7 +35,7 @@ Settings.embedModel = new OpenAIEmbedding({
|
||||
|
||||
## Local Embedding
|
||||
|
||||
For local embeddings, you can use the [HuggingFace](/docs/llamaindex/modules/embeddings/available_embeddings/huggingface) embedding model.
|
||||
For local embeddings, you can use the [HuggingFace](/docs/llamaindex/modules/embeddings/huggingface) embedding model.
|
||||
|
||||
## Local Ollama Embeddings With Remote Host
|
||||
|
||||
|
||||
+1
-1
@@ -74,4 +74,4 @@ the response is not correct with a score of 2.5
|
||||
|
||||
## API Reference
|
||||
|
||||
- [CorrectnessEvaluator](/docs/api/classes/CorrectnessEvaluator)
|
||||
- [CorrectnessEvaluator](/docs/api/classes/CorrectnessEvaluator)
|
||||
+1
-1
@@ -8,7 +8,7 @@ Currently, the following components are Transformation objects:
|
||||
|
||||
- [SentenceSplitter](/docs/api/classes/SentenceSplitter)
|
||||
- [MetadataExtractor](/docs/llamaindex/modules/documents_and_nodes/metadata_extraction)
|
||||
- [Embeddings](/docs/llamaindex/modules/embeddings/index)
|
||||
- [Embeddings](/docs/llamaindex/modules/embeddings)
|
||||
|
||||
## Usage Pattern
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ title: Groq
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../../../examples/groq.ts";
|
||||
import CodeSource from "!raw-loader!../../../../../../../../examples/groq.ts";
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -45,7 +45,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/llms/available_llms/ollama) LLM.
|
||||
For local LLMs, currently we recommend the use of [Ollama](/docs/llamaindex/modules/llms/ollama) LLM.
|
||||
|
||||
## Available LLMs
|
||||
|
||||
|
||||
+29
@@ -55,6 +55,35 @@ const results = await queryEngine.query({
|
||||
});
|
||||
```
|
||||
|
||||
## Using JSON Response Format
|
||||
|
||||
You can configure Ollama to return responses in JSON format:
|
||||
|
||||
```ts
|
||||
import { Ollama } from "@llamaindex/llms/ollama";
|
||||
import { z } from "zod";
|
||||
|
||||
// Simple JSON format
|
||||
const llm = new Ollama({
|
||||
model: "llama2",
|
||||
temperature: 0,
|
||||
responseFormat: { type: "json_object" }
|
||||
});
|
||||
|
||||
// Using Zod schema for validation
|
||||
const responseSchema = z.object({
|
||||
summary: z.string(),
|
||||
topics: z.array(z.string()),
|
||||
sentiment: z.enum(["positive", "negative", "neutral"])
|
||||
});
|
||||
|
||||
const llm = new Ollama({
|
||||
model: "llama2",
|
||||
temperature: 0,
|
||||
responseFormat: responseSchema
|
||||
});
|
||||
```
|
||||
|
||||
## Full Example
|
||||
|
||||
```ts
|
||||
+27
@@ -46,6 +46,33 @@ or
|
||||
Settings.llm = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0, apiKey: <YOUR_API_KEY>, baseURL: "https://api.scaleway.ai/v1" });
|
||||
```
|
||||
|
||||
## Using JSON Response Format
|
||||
|
||||
You can configure OpenAI to return responses in JSON format:
|
||||
|
||||
```ts
|
||||
Settings.llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
temperature: 0,
|
||||
responseFormat: { type: "json_object" }
|
||||
});
|
||||
|
||||
// You can also use a Zod schema to validate the response structure
|
||||
import { z } from "zod";
|
||||
|
||||
const responseSchema = z.object({
|
||||
summary: z.string(),
|
||||
topics: z.array(z.string()),
|
||||
sentiment: z.enum(["positive", "negative", "neutral"])
|
||||
});
|
||||
|
||||
Settings.llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
temperature: 0,
|
||||
responseFormat: responseSchema
|
||||
});
|
||||
```
|
||||
|
||||
## Load and index documents
|
||||
|
||||
For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.
|
||||
+19
-1
@@ -1,8 +1,26 @@
|
||||
---
|
||||
title: Perplexity LLM
|
||||
---
|
||||
## Usage
|
||||
|
||||
## Installation
|
||||
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
<Tabs groupId="install" items={["npm", "yarn", "pnpm"]} persist>
|
||||
```shell tab="npm"
|
||||
npm install @llamaindex/perplexity
|
||||
```
|
||||
|
||||
```shell tab="yarn"
|
||||
yarn add @llamaindex/perplexity
|
||||
```
|
||||
|
||||
```shell tab="pnpm"
|
||||
pnpm add @llamaindex/perplexity
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { Settings } from "llamaindex";
|
||||
+3
-3
@@ -8,15 +8,15 @@ import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
<Tabs groupId="install" items={["npm", "yarn", "pnpm"]} persist>
|
||||
```shell tab="npm"
|
||||
npm install llamaindex
|
||||
npm install @llamaindex/together
|
||||
```
|
||||
|
||||
```shell tab="yarn"
|
||||
yarn add llamaindex
|
||||
yarn add @llamaindex/together
|
||||
```
|
||||
|
||||
```shell tab="pnpm"
|
||||
pnpm add llamaindex
|
||||
pnpm add @llamaindex/together
|
||||
```
|
||||
</Tabs>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ description: Learn how to use Node Parsers and Text Splitters to extract data fr
|
||||
import { CodeNodeParserDemo } from '../../../../../components/demo/code-node-parser.tsx';
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
Node parsers are a simple abstraction that take a list of documents, 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](./).
|
||||
Node parsers are a simple abstraction that take a list of documents, 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/loading).
|
||||
|
||||
## NodeParser
|
||||
|
||||
@@ -28,14 +28,21 @@ Answer:`;
|
||||
|
||||
### 1. Customizing the default prompt on initialization
|
||||
|
||||
The first method is to create a new instance of `ResponseSynthesizer` (or the module you would like to update the prompt) and pass the custom prompt to the `responseBuilder` parameter. Then, pass the instance to the `asQueryEngine` method of the index.
|
||||
The first method is to create a new instance of a Response Synthesizer (or the module you would like to update the prompt) by using the getResponseSynthesizer function. Instead of passing the custom prompt to the deprecated responseBuilder parameter, call getResponseSynthesizer with the mode as the first argument and supply the new prompt via the options parameter.
|
||||
|
||||
```ts
|
||||
// Create an instance of response synthesizer
|
||||
// Create an instance of Response Synthesizer
|
||||
|
||||
// Deprecated usage:
|
||||
const responseSynthesizer = new ResponseSynthesizer({
|
||||
responseBuilder: new CompactAndRefine(undefined, newTextQaPrompt),
|
||||
});
|
||||
|
||||
// Current usage:
|
||||
const responseSynthesizer = getResponseSynthesizer('compact', {
|
||||
textQATemplate: newTextQaPrompt
|
||||
})
|
||||
|
||||
// Create index
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
|
||||
@@ -75,5 +82,5 @@ const response = await queryEngine.query({
|
||||
|
||||
## API Reference
|
||||
|
||||
- [ResponseSynthesizer](/docs/api/classes/ResponseSynthesizer)
|
||||
- [Response Synthesizer](/docs/llamaindex/modules/response_synthesizer)
|
||||
- [CompactAndRefine](/docs/api/classes/CompactAndRefine)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: ResponseSynthesizer
|
||||
title: Response Synthesizer
|
||||
---
|
||||
|
||||
The ResponseSynthesizer is responsible for sending the query, nodes, and prompt templates to the LLM to generate a response. There are a few key modes for generating a response:
|
||||
@@ -12,15 +12,17 @@ The ResponseSynthesizer is responsible for sending the query, nodes, and prompt
|
||||
multiple compact prompts. The same as `refine`, but should result in less LLM calls.
|
||||
- `TreeSummarize`: Given a set of text chunks and the query, recursively construct a tree
|
||||
and return the root node as the response. Good for summarization purposes.
|
||||
- `SimpleResponseBuilder`: Given a set of text chunks and the query, apply the query to each text
|
||||
chunk while accumulating the responses into an array. Returns a concatenated string of all
|
||||
responses. Good for when you need to run the same query separately against each text
|
||||
chunk.
|
||||
- `MultiModal`: Combines textual inputs with additional modality-specific metadata to generate an integrated response.
|
||||
It leverages a text QA template to build a prompt that incorporates various input types and produces either streaming or complete responses.
|
||||
This approach is ideal for use cases where enriching the answer with multi-modal context (such as images, audio, or other data)
|
||||
can enhance the output quality.
|
||||
|
||||
```typescript
|
||||
import { NodeWithScore, TextNode, ResponseSynthesizer } from "llamaindex";
|
||||
import { NodeWithScore, TextNode, getResponseSynthesizer, responseModeSchema } from "llamaindex";
|
||||
|
||||
const responseSynthesizer = new ResponseSynthesizer();
|
||||
// you can also use responseModeSchema.Enum.refine, responseModeSchema.Enum.tree_summarize, responseModeSchema.Enum.multi_modal
|
||||
// or you can use the CompactAndRefine, Refine, TreeSummarize, or MultiModal classes directly
|
||||
const responseSynthesizer = getResponseSynthesizer(responseModeSchema.Enum.compact);
|
||||
|
||||
const nodesWithScore: NodeWithScore[] = [
|
||||
{
|
||||
@@ -55,8 +57,9 @@ for await (const chunk of stream) {
|
||||
|
||||
## API Reference
|
||||
|
||||
- [ResponseSynthesizer](/docs/api/classes/ResponseSynthesizer)
|
||||
- [getResponseSynthesizer](/docs/api/functions/getResponseSynthesizer)
|
||||
- [responseModeSchema](/docs/api/variables/responseModeSchema)
|
||||
- [Refine](/docs/api/classes/Refine)
|
||||
- [CompactAndRefine](/docs/api/classes/CompactAndRefine)
|
||||
- [TreeSummarize](/docs/api/classes/TreeSummarize)
|
||||
- [SimpleResponseBuilder](/docs/api/classes/SimpleResponseBuilder)
|
||||
- [MultiModal](/docs/api/classes/MultiModal)
|
||||
|
||||
@@ -7,9 +7,59 @@ A tool can be called to perform custom actions, or retrieve extra information ba
|
||||
A result from a tool call can be used by subsequent steps in a workflow, or to compute a final answer.
|
||||
For example, a "weather tool" could fetch some live weather information from a geographical location.
|
||||
|
||||
## Tool Function
|
||||
|
||||
The `tool` function is a utility provided to define a tool that can be used by an agent. It takes a function and a configuration object as arguments. The configuration object includes the tool's name, description, and parameters.
|
||||
|
||||
### Parameters with Zod
|
||||
|
||||
The `parameters` field in the tool configuration is defined using `zod`, a TypeScript-first schema declaration and validation library. `zod` allows you to specify the expected structure and types of the input parameters, ensuring that the data passed to the tool is valid.
|
||||
|
||||
Example:
|
||||
```ts
|
||||
import { agent, tool } from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
// first arg is LLM input, second is bound arg
|
||||
const queryKnowledgeBase = async ({ question }, { userToken }) => {
|
||||
const response = await fetch(`https://knowledge-base.com?token=${userToken}&query=${question}`);
|
||||
// ...
|
||||
};
|
||||
|
||||
// define tool with zod validation
|
||||
const kbTool = tool(queryKnowledgeBase, {
|
||||
name: 'queryKnowledgeBase',
|
||||
description: 'Query knowledge base',
|
||||
parameters: z.object({
|
||||
question: z.string({
|
||||
description: 'The user question',
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
```
|
||||
In this example, `z.object` is used to define a schema for the `parameters` where `question` is expected to be a string. This ensures that any input to the tool adheres to the specified structure, providing a layer of type safety and validation.
|
||||
|
||||
|
||||
## Built-in tools
|
||||
|
||||
You can import built-in tools from the `@llamaindex/tools` package.
|
||||
|
||||
```ts
|
||||
import { agent } from "llamaindex";
|
||||
import { wiki } from "@llamaindex/tools";
|
||||
|
||||
const researchAgent = agent({
|
||||
name: "WikiAgent",
|
||||
description: "Gathering information from the internet",
|
||||
systemPrompt: `You are a research agent. Your role is to gather information from the internet using the provided tools.`,
|
||||
tools: [wiki()],
|
||||
});
|
||||
```
|
||||
|
||||
## Function tool
|
||||
|
||||
Function tools are implemented with the `FunctionTool` class.
|
||||
You can still use the `FunctionTool` class to define a tool.
|
||||
A `FunctionTool` is constructed from a function with signature
|
||||
```ts
|
||||
(input: T, additionalArg?: AdditionalToolArgument) => R
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Agent tutorial
|
||||
title: 1. Setup
|
||||
---
|
||||
|
||||
In this guide we'll walk you through the process of building an Agent in JavaScript using the LlamaIndex.TS library, starting from nothing and adding complexity in stages.
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Create a basic agent
|
||||
title: 2. Create a basic agent
|
||||
---
|
||||
|
||||
We want to use `await` so we're going to wrap all of our code in a `main` function, like this:
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Using a local model via Ollama
|
||||
title: 3. Using a local model via Ollama
|
||||
---
|
||||
|
||||
If you're happy using OpenAI, you can skip this section, but many people are interested in using models they run themselves. The easiest way to do this is via the great work of our friends at [Ollama](https://ollama.com/), who provide a simple to use client that will download, install and run a [growing range of models](https://ollama.com/library) for you.
|
||||
+5
-34
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Adding Retrieval-Augmented Generation (RAG)
|
||||
title: 4. Adding Retrieval-Augmented Generation (RAG)
|
||||
---
|
||||
|
||||
While an agent that can perform math is nifty (LLMs are usually not very good at math), LLM-based applications are always more interesting when they work with large amounts of data. In this case, we're going to use a 200-page PDF of the proposed budget of the city of San Francisco for fiscal years 2024-2024 and 2024-2025. It's a great example because it's extremely wordy and full of tables of figures, which present a challenge for humans and LLMs alike.
|
||||
@@ -87,32 +87,9 @@ By default LlamaIndex will retrieve just the 2 most relevant chunks of text. Thi
|
||||
retriever.similarityTopK = 10;
|
||||
```
|
||||
|
||||
### Approach 1: Create a Context-Aware Agent
|
||||
### Use index.queryTool
|
||||
|
||||
With the retriever ready, you can create a **context-aware agent**.
|
||||
|
||||
```javascript
|
||||
const agent = new OpenAIContextAwareAgent({
|
||||
contextRetriever: retriever,
|
||||
});
|
||||
|
||||
// Example query to the context-aware agent
|
||||
let response = await agent.chat({
|
||||
message: `What's the budget of San Francisco in 2023-2024?`,
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
```
|
||||
|
||||
**Expected Output:**
|
||||
|
||||
```md
|
||||
The total budget for the City and County of San Francisco for the fiscal year 2023-2024 is $14.6 billion. This represents a $611.8 million, or 4.4 percent, increase over the previous fiscal year's budget. The budget covers various expenditures across different departments and services, including significant allocations to public works, transportation, commerce, public protection, and health services.
|
||||
```
|
||||
|
||||
### Approach 2: Using QueryEngineTool (Alternative Approach)
|
||||
|
||||
If you prefer more flexibility and don't mind additional complexity, you can create a `QueryEngineTool`. This approach allows you to define the query logic, providing a more tailored way to interact with the data, but note that it introduces a delay due to the extra tool call.
|
||||
`index.queryTool` creates a `QueryEngineTool` that can be used be an agent to query data from the index.
|
||||
|
||||
```javascript
|
||||
const tools = [
|
||||
@@ -125,9 +102,9 @@ const tools = [
|
||||
];
|
||||
|
||||
// Create an agent using the tools array
|
||||
const myAgent = agent({ tools });
|
||||
const ragAgent = agent({ tools });
|
||||
|
||||
let toolResponse = await myAgent.run("What's the budget of San Francisco in 2023-2024?");
|
||||
let toolResponse = await ragAgent.run("What's the budget of San Francisco in 2023-2024?");
|
||||
|
||||
console.log(toolResponse);
|
||||
```
|
||||
@@ -155,10 +132,4 @@ console.log(toolResponse);
|
||||
|
||||
Once again we see a `toolResult`. You can see the query the LLM decided to send to the query engine ("total budget"), and the output the engine returned. In `response.message` you see that the LLM has returned the output from the tool almost verbatim, although it trimmed out the bit about 2024-2025 since we didn't ask about that year.
|
||||
|
||||
### Comparison of Approaches
|
||||
|
||||
The `OpenAIContextAwareAgent` approach simplifies the setup by allowing you to directly link the retriever to the agent, making it straightforward to access relevant context for your queries. This is ideal for situations where you want easy integration with existing data sources, like a context chat engine.
|
||||
|
||||
On the other hand, using the `QueryEngineTool` offers more flexibility and power. This method allows for customization in how queries are constructed and executed, enabling you to query data from various storages and process them in different ways. However, this added flexibility comes with increased complexity and response time due to the separate tool call and queryEngine generating tool output by LLM that is then passed to the agent.
|
||||
|
||||
So now we have an agent that can index complicated documents and answer questions about them. Let's [combine our math agent and our RAG agent](5_rag_and_tools)!
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: A RAG agent that does math
|
||||
title: 5. A RAG agent that does math
|
||||
---
|
||||
|
||||
In [our third iteration of the agent](https://github.com/run-llama/ts-agents/blob/main/3_rag_and_tools/agent.ts) we've combined the two previous agents, so we've defined both `sumNumbers` and a `QueryEngineTool` and created an array of two tools. The tools support both Zod and JSON Schema for parameter definition:
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Adding LlamaParse
|
||||
title: 6. Adding LlamaParse
|
||||
---
|
||||
|
||||
Complicated PDFs can be very tricky for LLMs to understand. To help with this, LlamaIndex provides LlamaParse, a hosted service that parses complex documents including PDFs. To use it, get a `LLAMA_CLOUD_API_KEY` by [signing up for LlamaCloud](https://cloud.llamaindex.ai/) (it's free for up to 1000 pages/day) and adding it to your `.env` file just as you did for your OpenAI key:
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Adding persistent vector storage
|
||||
title: 7. Adding persistent vector storage
|
||||
---
|
||||
|
||||
In the previous examples, we've been loading our data into memory each time we run the agent. This is fine for small datasets, but for larger datasets you'll want to store your embeddings in a database. LlamaIndex.TS provides a `VectorStore` class that can store your embeddings in a variety of databases. We're going to use [Qdrant](https://qdrant.tech/), a popular vector store, for this example.
|
||||
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 236 KiB |
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"title": "Agents",
|
||||
"title": "Agent with RAG",
|
||||
"pages": [
|
||||
"1_setup",
|
||||
"2_create_agent",
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
---
|
||||
title: Agent tutorial
|
||||
title: Basic Agent
|
||||
---
|
||||
|
||||
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
||||
import CodeSource from "!raw-loader!../../../../../../../../examples/agent/openai";
|
||||
import CodeSource from "!raw-loader!../../../../../../../examples/agent/openai";
|
||||
|
||||
We have a comprehensive, step-by-step [guide to building agents in LlamaIndex.TS](../../guides/agents/setup) that we recommend to learn what agents are and how to build them for production. But building a basic agent is simple:
|
||||
We have a comprehensive, step-by-step [guide to building agents in LlamaIndex.TS](/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:
|
||||
|
||||
## Set up
|
||||
|
||||
+5
-2
@@ -4,7 +4,7 @@ title: Local LLMs
|
||||
|
||||
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
||||
|
||||
LlamaIndex.TS supports OpenAI and [other remote LLM APIs](other_llms). You can also run a local LLM on your machine!
|
||||
LlamaIndex.TS supports OpenAI and [other remote LLM APIs](/docs/llamaindex/modules/llms). You can also run a local LLM on your machine!
|
||||
|
||||
## Using a local model via Ollama
|
||||
|
||||
@@ -45,7 +45,10 @@ To switch the LLM in your code, you first need to make sure to install the packa
|
||||
Then, to tell LlamaIndex to use a local LLM, use the `Settings` object:
|
||||
|
||||
```javascript
|
||||
Settings.llm = new Ollama({
|
||||
import { Settings } from "llamaindex";
|
||||
import { ollama } from "@llamaindex/ollama";
|
||||
|
||||
Settings.llm = ollama({
|
||||
model: "mixtral:8x7b",
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"title": "Tutorials",
|
||||
"pages": [
|
||||
"basic_agent",
|
||||
"rag",
|
||||
"agents",
|
||||
"workflow",
|
||||
"local_llm",
|
||||
"chatbot",
|
||||
"structured_data_extraction"
|
||||
]
|
||||
}
|
||||
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user